) where

import AlgebraicStructures.Base
import Data.List
import GHC.Integer

identity :: Eq a => (a -> a -> a) -> [a] -> Maybe a
identity (+) d = find (\e -> all (\a -> e + a == a && a + e == a) d) d

multIdentity :: Eq a => (a -> a -> a) -> (a -> a -> a) -> [a] -> Maybe a
multIdentity (+) (*) d = (\d' -> identity (*) d') =<< (fmap (\e -> filter (/= e) d) (identity (+) d))

generate :: Eq a => (a -> a -> a) -> a -> [a]