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@haskell.org
[mailto:glasgow-haskell-users-bounces@haskell.org] On Behalf Of Conal
Elliott
Sent: 15 July 2008 15:59
To: glasgow-haskell-users@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