[Haskell-cafe] Type Classes in Haskell - how can I make GHC make a choice of types, when the type chosen doesn't matter?
Chris Dew
cmsdew at gmail.com
Thu Apr 14 21:24:06 CEST 2011
@Neil Brown - That did it. It's not the ideal solution, as all ->>
are 'coerced' into being 'IO x' (if the rightmost term is an 'IO x'.
But it'll do for the time being.
Many thanks,
Chris.
On 14 April 2011 13:50, Neil Brown <nccb2 at kent.ac.uk> wrote:
> On 14/04/11 13:00, Chris Dew wrote:
>>
>> class Stream a b c d where
>> (->>) :: a -> (b -> c) -> d
>>
>> instance Stream (IO d) d (IO c) (IO c) where
>> f ->> g = f>>= g
>>
>> instance Stream d d (IO c) (IO c) where
>> f ->> g = g f
>>
>> instance Stream d d c c where
>> x ->> y = y $ x
>>
>
> I notice that in all your instances, the last two types are the same. So do
> you need the final type parameter? Could you not make it:
>
> class Stream a b c where
> (->>) :: a -> (b -> c) -> c
>
> I quickly tried this, and it fixes the errors you were getting. If that
> doesn't hold for all instances you have in mind, then you may want to use
> functional dependencies or type families to specify a relationship between
> the types.
>
> Thanks,
>
> Neil.
>
>
More information about the Haskell-Cafe
mailing list