[Haskell-cafe] Intersection types for Haskell?

Brian Hulley brianh at metamilk.com
Tue Jan 10 13:00:35 EST 2006

Hi -
I'm wondering if there is any possiblility of getting intersection types 
into Haskell. For example, at the moment there is no (proper) typing for:

    f g x y = (g x, g y)

Ideally, I'd like to be able to write:

    f:: (a -> b & c -> d) -> a -> c -> (b,d)


    f :: (a -> b a) -> c -> d -> (b c, b d)

which is perhaps clearer and prevents bad types such as (Int -> String & 
Int -> Char) by construction.

While it may be impossible (?) to infer such a type for f, would it be 
possible to make use of such an annotation (esp since Haskell with GHC 
extensions already has arbitary rank polymorphism)?

Also, as a second point, could functional dependencies in type classes be 
written using a similar syntax eg instead of

    class Insert t c a | c a -> t where
        insert :: t -> c a -> c a

we could write:

    class Insert (h (c a)) c a where
        insert :: h (c a) -> c a -> c a

    class Insert t@(h (c a)) c a where   -- re-using as-pattern syntax
        insert :: t -> c a -> c a

to avoid having to have a special syntax just for functional dependencies 
and/or to be able to write more complicated fundeps more succinctly?

Brian Hulley 

More information about the Haskell-Cafe mailing list