I'm trying to create a "hierarchy" of algebraic type classes, as follows:
class Semigroup a where
(.*) :: a -> a -> a
foldr1 (.*) = foldl1 (.*) -- GHCi error: "`foldr1' is not a (visible) method of class `Semigroup'"
class (Semigroup a) => Monoid a where
identity :: a
(.*) identity = id :: a -> a -- GHCi error: "`.*' is not a (visible) method of class `Monoid'"
class (Monoid a) => Group a where
inverse :: a -> a
Thus, groups are monoids and monoids are semigroups. However, I get errors that the classes can't see the functions of their parent class.
These errors bug me because I assumed that by writing (for example) class (Semigroup a) => Monoid a
the class Monoid a
would be able to see the function (.*)
. And furthermore, the type of foldr1
in the Prelude has no constraints, so I assumed that foldr1
would work in this context.