GHC shows wrong line number in error?

Hello, I have some code like this (the contents don't really matter): 42 data TestChain next = ChainEntry (forall b . TestG b) next 43 | ChainDescribe String (Free TestChain... 44 deriving (Functor) 45 46 -- deriving instance Show a => Show (TestChain a) 47 48 it :: (SomeT typ, Partition t typ) => String -> t -> ... 49 it desc test = liftF (ChainEntry (mkTestG test) ()) And get the error: Clean.hs:49:43: Could not deduce (t ~ b) from the context (SomeT typ, Partition t typ) bound by the type signature for it :: (SomeT typ, Partition t typ) => String -> t -> Free TestChain () at Clean.hs:49:1-51 `t' is a rigid type variable bound by the type signature for it :: (SomeT typ, Partition t typ) => String -> t -> Free TestChain () at Clean.hs:49:1 `b' is a rigid type variable bound by a type expected by the context: TestG b at Clean.hs:49:23 [...] In that last error line, should that not be "Clean.hs:42:..." (as it references the 'b', which I only really have there), or is that intended, and if yes, why? I'm using GHC 7.4.2. Thanks Niklas

* Niklas Hambüchen
Hello,
I have some code like this (the contents don't really matter):
42 data TestChain next = ChainEntry (forall b . TestG b) next 43 | ChainDescribe String (Free TestChain... 44 deriving (Functor) 45 46 -- deriving instance Show a => Show (TestChain a) 47 48 it :: (SomeT typ, Partition t typ) => String -> t -> ... 49 it desc test = liftF (ChainEntry (mkTestG test) ())
And get the error:
Clean.hs:49:43: Could not deduce (t ~ b) from the context (SomeT typ, Partition t typ) bound by the type signature for it :: (SomeT typ, Partition t typ) => String -> t -> Free TestChain () at Clean.hs:49:1-51 `t' is a rigid type variable bound by the type signature for it :: (SomeT typ, Partition t typ) => String -> t -> Free TestChain () at Clean.hs:49:1 `b' is a rigid type variable bound by a type expected by the context: TestG b at Clean.hs:49:23 [...]
In that last error line, should that not be "Clean.hs:42:..." (as it references the 'b', which I only really have there), or is that intended, and if yes, why?
I'm using GHC 7.4.2.
Because there's no error on line 42. It's a fine type declaration, and saying it contains an error would be utterly confusing. But *given* that type declaration, your code on line 49 is incorrect, and that's what GHC is saying. To consider a simpler example, writing "foo" :: Int is incorrect because "foo" is not an Int. But the problem is in the assertion that "foo" has type Int, and not in the type declaration itself, although the error message would presumably reference Int. Roman

On Thu, Dec 20, 2012 at 3:47 AM, Niklas Hambüchen
`b' is a rigid type variable bound by a type expected by the context: TestG b at Clean.hs:49:23
It might be worth rephrasing this error message somehow, although I suspect it's written to fit into existing error reporting machinery that's not easy to adapt to fit the situation: the location is not referring to "TestG b", but to "a type" on line 49, which is expected/"generated" by the context TestG b established previously. You have to read pretty closely to figure that out, though. -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net
participants (3)
-
Brandon Allbery
-
Niklas Hambüchen
-
Roman Cheplyaka