[Haskell-cafe] Functional dependencies *not* part of the next Haskell standard?

Henning Thielemann lemming at henning-thielemann.de
Thu Jul 12 05:43:57 EDT 2007


On Thu, 12 Jul 2007, peterv wrote:

> I tried to do something in CAL that I could not solve without functional
> dependencies. In their support forum, it got mentioned that func.deps
> propably won't make into the next Haskell standard... Any comments on that?
>
> Now, the thing I tried to solve was:
>
>        data Vector2 a = Num a => V2 a a
>
>        class Vector a n | a -> n where
>          dot :: a -> a -> n
>
>        instance Num a => Vector (Vector2 a) a where
>          dot (V2 x1 y1) (V2 x2 y2) = x1 * x2 + y1 * y2
>
>        test1 = dot (V2 1.0 2.0) (V2 3.0 4.0)


class Vector v where
   dot :: Num a => v a -> v a -> a

instance Vector Vector2 where
   dot (V2 x1 y1) (V2 x2 y2) = x1 * x2 + y1 * y2


This will work satisfyingly if you don't plan a larger type class
hierarchy.


More information about the Haskell-Cafe mailing list