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

peterv bf3 at telenet.be
Thu Jul 12 05:36:43 EDT 2007


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)

Please note this is just some testing code (the math people in here might be
horrified by it ;), although any hints of how to do this in a clearer way
are welcome. As side-note, does Haskell have some easy to use good linear
algebra package for doing 2D, 3D and 4D math? Then I would not be writing
any of this code, although I did find it useful for learning.
 
Now without the funcdep a -> n in the type class declaration I get

    No instance for (Vector (Vector2 t) n)
      arising from use of `dot' at l:/Haskell/test/vector.hs:9:8-36
    Possible fix:
      add an instance declaration for (Vector (Vector2 t) n)
    In the expression: dot (V2 1.0 2.0) (V2 3.0 4.0)
    In the definition of `test1': test1 = dot (V2 1.0 2.0) (V2 3.0 4.0)

CAL seems to have the same problem, and without funcdeps I seem to be stuck
in that language.

PS(1): In the above I was using GHCI with extensions enabled.
PS(2): IMHO CAL is in some aspects easier to get started than Haskell
because of their nice Eclipse plugin and GEM Cutter environment for doing
learning experiments.

Thanks,
Peter




More information about the Haskell-Cafe mailing list