How overload operator in Haskell?

Ganesh Sittampalam ganesh@comlab.ox.ac.uk
Thu, 10 Jul 2003 11:41:46 +0100


On Thu, 10 Jul 2003 10:58:51 +1000, Andrew J Bromage <ajb@spamcop.net>
wrote:

>This suggests that wrapping each "standard" mathemtaical
>function/operator in its own typeclass would have literally
>no run-time performance penalty:
>
>	class Plus a b c | a b -> c where
>	    (+) :: a -> b -> c
>
>	class Mult a b c | a b -> c where
>	    (*) :: a -> b -> c
>
>	{- etc -}
>
>	class (Eq a, Show a,
>	       Plus a a a, Mult a a a, {- etc -}
>	      ) => Num a
>
>Apart from the possibility of naming these typeclasses better, this
>reorganisation gets my vote for Haskell 2.

Given the current way the system works, this imposes a syntactic penalty on
people wishing to declare an instance of Num. If some nice change can be
made to avoid this, e.g. by allowing people to declare instances of several
classes in the same instance declaration and automatically inferring the
names of the relevant base classes, then this would be a very good thing.

Ganesh