2008/12/12 George Pollard :
>
> However, when it comes to defining (e.g.) a Field class you have two
> Abelian groups over the same type, which won't work straight off:
Especially since you generally can't take the multiplicative inverse
of the additive identity.
> I'm beginning to think that the
What about something like
data AddMult a b = AddMult a b
class Monoid a where
operation :: a -> a -> a
identity :: a
instance (Monoid a, Monoid b) => Monoid (AddMult a b) where
operation (AddMult a1 m1)
(AddMult a2 m2)
= AddMult (operation a1 a2)
Is there a good way of doing this? My running example is Monoid:
> class Monoid a where
> operation :: a -> a -> a
> identity :: a
With the obvious examples on Num:
> instance (Num a) => Monoid a where
> operation = (+)
> identity = 1
>
> instance (Num a) => Monoid a whe