Perplexing GHC7.0.3 behavior with hairy typelevel code (regression from 6.12.3??)
Simon PeytonJones
simonpj at microsoft.com
Tue Apr 26 10:53:49 CEST 2011
It's hard to say much without a particular program to look at. But when type families or functional dependencies are involved you can certainly get situations where
f :: <ty>
but if you write
g ::<ty>
g = f
the program is rejected. Sounds similar to what you are seeing. Look here:
http://www.haskell.org/haskellwiki/GHC/Type_families#Injectivity.2C_type_inference.2C_and_ambiguity
If you are still puzzled, by all means try to boil out a test case, the smaller the better. A bug is far from impossible.
Simon
 Original Message
 From: glasgowhaskellusersbounces at haskell.org [mailto:glasgowhaskellusers
 bounces at haskell.org] On Behalf Of Bjorn Buckwalter
 Sent: 22 April 2011 16:19
 To: GHC Users
 Subject: Perplexing GHC7.0.3 behavior with hairy typelevel code (regression from
 6.12.3??)

 Hello all,

 I am doing some fairly hairy typelevel stuff with
 FunctionalDependencies, UndecidableInstances, and other. Without going
 into details I have the following function which compiles fine:

 vecMat :: (Transpose m m', MatrixVector m' v v', Num a)
 => Vec v a > Mat m a > Vec v' a
 vecMat v m = transpose m `matVec` v


 However, I am perplexed by the following:

 1. This does NOT compile despite the type signature being identical to
 that of 'vecMat':

 vecMat2 :: (Transpose m m', MatrixVector m' v v', Num a)
 => Vec v a > Mat m a > Vec v' a
 vecMat2 v m = vecMat v m

 The error message is along the lines of the below where 'HMap ...' is
 the context for the MatrixVector instance... I'll provide more details
 as needed.

 Could not deduce (HMap (DotProd, v) m' v')
 arising from a use of `vecMat'
 from the context (Transpose m m', MatrixVector m' v v', Num a)
 bound by the type signature for
 vecMat2 :: (Transpose m m', MatrixVector m' v v', Num a) =>
 Vec v a > Mat m a > Vec v' a


 2. If I omit the type signature the definition of 'vecMat2' does compile:

 vecMat2 v m = vecMat v m

 3. If I omit the second argument it also compiles:

 vecMat2 v = vecMat v

 4. However, if I omit both arguments it does NOT compile:

 vecMat2 = vecMat


 So I guess I have two questions. First: why would 1 not compile?
 Second: why are 2, 3, and 4 not equivalent? Pointers to relevant
 documentation welcome.

 I broke my GHC6.12.3 installation when upgrading to the latest HP
 with GHC7.0.3 so I cannot test 2, 3, and 4 but I know that 1 DID
 compile on GHC6.12.3. Is the change of behavior in GHC7.0.3 a bug or
 a bug fix?

 I'll be happy to elaborate on the code if it would be useful, and try
 to find a minimal example. But I wanted to check if the behavior I am
 seeing makes any sense at all first. In case you cannot wait the
 'matVec' definition is from:

 https://github.com/bjornbm/dimensional
 vectors/blob/master/Numeric/Units/Dimensional/LinearAlgebra/Matrix.hs


 Thanks,
 Bjorn

 _______________________________________________
 Glasgowhaskellusers mailing list
 Glasgowhaskellusers at haskell.org
 http://www.haskell.org/mailman/listinfo/glasgowhaskellusers
More information about the Glasgowhaskellusers
mailing list