[prev in list] [next in list] [prev in thread] [next in thread] 

List:       haskell-cafe
Subject:    [Haskell-cafe] Class Synonyms - example 2
From:       Jorge Adriano Aires <jadrian () mat ! uc ! pt>
Date:       2004-12-11 2:05:25
Message-ID: 200412110205.26276.jadrian () mat ! uc ! pt
[Download RAW message or body]

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 

right?

J.A.


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic