Bug in type equality constraints?
Simon Peyton-Jones
simonpj at microsoft.com
Wed Jul 16 15:51:57 EDT 2008
Conal
That looks like a bug, at least on the surface. You've clearly said that the instance for InnerSpace (u,v) can assume (Scalar u ~ Scalar v).
Can you spare a moment submit a Trac report, with a reproducible test case (as small as possible, please!)?
Manuel is actively working on associated types etc at the moment. Our goal is a pretty-much-fully-working implementation for release in 6.10 just before ICFP.
thanks
Simon
From: glasgow-haskell-users-bounces at haskell.org [mailto:glasgow-haskell-users-bounces at haskell.org] On Behalf Of Conal Elliott
Sent: 15 July 2008 15:59
To: glasgow-haskell-users at haskell.org
Subject: Bug in type equality constraints?
I'm converting some code from functionally dependencies to associated types, and I've run into a problem with equality constraints and subclasses. The classes:
class AdditiveGroup v => VectorSpace v where
type Scalar v :: *
(*^) :: Scalar v -> v -> v
class VectorSpace v => InnerSpace v where
(<.>) :: v -> v -> Scalar v
Products of vector spaces are vector spaces *if* over the same scalar field. Hence:
instance ( VectorSpace u,VectorSpace v
, Scalar u ~ Scalar v ) => VectorSpace (u,v) where
type Scalar (u,v) = Scalar u
s *^ (u,v) = (s*^u,s*^v)
Similarly for inner product spaces:
instance ( InnerSpace u,InnerSpace v, Scalar u ~ Scalar v
, AdditiveGroup (Scalar v) ) => InnerSpace (u,v) where
(u,v) <.> (u',v') = (u <.> u') ^+^ (v <.> v')
But here's where ghc-6.9.20080622 balks:
Data\VectorSpace.hs:106:0:
Couldn't match expected type `Scalar v'
against inferred type `Scalar u'
When checking the super-classes of an instance declaration
In the instance declaration for `InnerSpace (u, v)'
Any ideas?
- Conal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/glasgow-haskell-users/attachments/20080716/477c521d/attachment.htm
More information about the Glasgow-haskell-users
mailing list