[Haskell-cafe] GHC shows wrong line number in error?

Roman Cheplyaka roma at ro-che.info
Thu Dec 20 10:20:42 CET 2012


* Niklas Hambüchen <mail at nh2.me> [2012-12-20 08:47:17+0000]
> 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



More information about the Haskell-Cafe mailing list