[Haskell-cafe] Functional dependencies *not* part of the next
Haskell standard?
peterv
bf3 at telenet.be
Thu Jul 12 09:03:29 EDT 2007
> instance Vector Vector2 where
> dot (V2 x1 y1) (V2 x2 y2) = x1 * x2 + y1 * y2
Amazing, so simple it is, Yoda would say ;)
I did not realize one could perform "partial application" on types when
declaring instances (I mean not specifying the type of Vector2 in <instance
Vector Vector2>).
Now regarding these funcdeps, are they "ill" as the "rumor" goes?
Thanks,
Peter
-----Original Message-----
From: Henning Thielemann [mailto:lemming at henning-thielemann.de]
Sent: Thursday, July 12, 2007 11:44 AM
To: peterv
Cc: Haskell-Cafe at haskell.org
Subject: Re: [Haskell-cafe] Functional dependencies *not* part of the next
Haskell standard?
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