[Haskell-cafe] Inheritance and Wrappers
Henning Thielemann
lemming at henning-thielemann.de
Mon Jan 31 21:36:31 CET 2011
On Mon, 31 Jan 2011, MattMan wrote:
> I'm new to Haskell, and am trying to implement some simple typeclasses for
> doing algebra. For example I have type class (simplified for the sake of
> argument)
>
> class AbGroup a where
> add :: a -> a -> a
>
> I would like any type instantiating Num to also be an abelian group:
>
> instance (Num a) => AbGroup a where
> add i j = i+j,
If all methods of AbGroup can be defined for all Num types - why do you
want an AbGroup at all? You could simply write functions with Num
constraint.
You may be also interested in existing approaches to algebra in Haskell:
http://www.haskell.org/haskellwiki/Mathematical_prelude_discussion
More information about the Haskell-Cafe
mailing list