[Haskell-cafe] Class Synonyms - example 2

Jorge Adriano Aires jadrian at mat.uc.pt
Fri Dec 10 21:05:25 EST 2004

Maybe I should have included a more interesting example in the previous mail. 
So I had this class:

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

Besides the case where 'a' is the same as 'b', there is also another 
interesting case. That is when you have both, Foo A B and Foo B A. This is a 
known property (named DoubleFoo), so I'd like to type contexts as,

> DoubleFoo a b =>

instead of,

> (Foo a b, Foo b a) =>

so I tried:
> class (Foo a b, Foo b a) => DoubleFoo a b where

This works fine if I'm going to define functions which need both instances of 
Foo. Something like:

> testDouble :: DoubleFoo a b => a -> b -> c 
> testDouble a b = foo_method1 a b  ... foo_method1 b a 

but it doesn't help me with:

> testDouble2 :: DoubleFoo a b => a -> b -> c 
> testDouble2 a b = foo_method1 a b  ... testDouble2 b a 

now I need DoubleFoo b a as well. Seems to me like there is no way of saying:
> Foo a b , Foo b a <=> DoubleFoo a b 



More information about the Haskell-Cafe mailing list