[Haskell-cafe] Intersection types for Haskell?

Brian Hulley brianh at metamilk.com
Tue Jan 10 14:06:50 EST 2006


José Miguel Vilaça wrote:
> Hi
>
> If I understand your problem than the following is a solution:
>
> --------------------------------------------------
>
> {-# OPTIONS -fglasgow-exts #-}
>
> class Foo a b where
>    g :: a -> b
>
> type A = {- change the following -} Int
> type B = {- change the following -} Char
>
> instance Foo A B where
>    g a = {- change the following -} ' '
>
> type C = {- change the following -} Float
> type D = {- change the following -} String
>
> instance Foo C D where
>    g c = {- change the following -} ""
>
>
> f :: (Foo a b, Foo c d) => a -> c -> (b, d)
> f x y = (g x, g y)

Thanks for the workaround. However this does not seem to be quite so general 
as intersection types, because it would only allow me to define f for some 
specific g ie the g of Foo, rather than for any general function...

Regards,
Brian Hulley 



More information about the Haskell-Cafe mailing list