[Haskell-cafe] Class Synonyms

Stefan Holdermans sholderm at students.cs.uu.nl
Sat Dec 11 03:55:51 EST 2004


Jorge,

> I'd like to achieve something better than this. I was looking for 
> something
> like "class synonyms". So if I declared an instance Foo A A, I 
> automagicaly
> had Bar A, because they'd be the same.

Using -fallow-undecidable-instances (in GHC) you could do:

\begin{code}
class Foo a b | a -> b where
   foo_method1 :: ...
   foo_method2 :: ...
   ...

class (Foo a a) => Bar a where

instance (Foo a a) => Bar a where   -- replaces all your other Bar 
instances

instance Foo Integer Integer where
   foo_method1 = ...
   foo_method2 = ...
\end{code}

HTH,

Stefan



More information about the Haskell-Cafe mailing list