[Haskell-cafe] Class Synonyms

Jorge Adriano Aires jadrian at mat.uc.pt
Fri Dec 10 20:40:03 EST 2004


I got a multi-parameter type class:

> class Foo a b | a -> b where
>    foo_method1 :: ...
>    foo_method2 :: ...
>    ...

And some particular cases are important on their own, like the one where 'a' 
and 'b' are the same, I call elements with this property, Bar. So I defined:

class Foo a a => Bar a where

This is nice, now I can replace (F a a) for (Bar a) in the context of many 
functions. Less typing and it's more readable. Still, I have to define 
instances as:
> instance Foo A A where
>    foo_method1 = bla1
>    foo_method2 = bla2
> instance Bar A where

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. Or even better, I could declare

> instance Bar A where
>    foo_method1 = bla1
>    foo_method2 = bla2

Is anything like this possible at all?


More information about the Haskell-Cafe mailing list