GHC: Ticket #409: confusing error
http://ghc.haskell.org/trac/ghc/ticket/409
<pre class="wiki">I got a perplexing error message. Here is a concise
example:
t = ((\Just x -> x) :: Maybe a -> a) (Just 1)
Try.hs:1:6:
Couldn't match the rigid variable `a' against
`t -> t1'
`a' is bound by the polymorphic type `forall
a. Maybe a -> a' at Try.hs:1:5-34
Expected type: a
Inferred type: t -> t1
In the expression: (\ Just x -> x) :: Maybe a -> a
In the definition of `t': t = ((\ Just x -> x)
:: Maybe a -> a) (Just 1)
Failed, modules loaded: none.
It seems to be telling me that the whole expression "(\
Just x -> x) ::
Maybe a -> a" was expected to have type a, in
contradiction to the explicit
type annotation it prints out! In the context of a
larger program, this
threw me for a loop. I would have expected
Expected type: Maybe -> a
Inferred type: Maybe -> t -> t1
Even better, if I change the code, I get a helpful
diagnostic:
t = (\Just x -> x) (Just 1)
Try.hs:1:6:
Constructor `Just' should have 1 argument, but
has been given 0
When checking the pattern: Just
In a lambda abstraction: \ Just x -> x
In the definition of `t': t = (\ Just x -> x)
(Just 1)
Failed, modules loaded: none.
Could I get that error in the first example? You could
probably go even further: "(did you forget parentheses
around the pattern?)".
</pre>en-usGHChttp://ghc.haskell.org/trac/ghc/chrome/site/ghc_logo.png
http://ghc.haskell.org/trac/ghc/ticket/409
Trac 1.2.2.dev0simonpjMon, 11 Jul 2005 10:52:17 GMTstatus changed
http://ghc.haskell.org/trac/ghc/ticket/409#comment:1
http://ghc.haskell.org/trac/ghc/ticket/409#comment:1
<ul>
<li><strong>status</strong>
changed from <em>assigned</em> to <em>closed</em>
</li>
</ul>
<pre class="wiki">Logged In: YES
user_id=50165
Good bug report. I've improved the message a lot:
tcfail140.hs:16:6:
The lambda expression `\ Just x -> ...' has two argumentss,
but its type `Maybe a -> a' has only one
In the expression: (\ Just x -> x) :: Maybe a -> a
In the definition of `t': t = ((\ Just x -> x) :: Maybe a -> a)
(Just 1)
test is tcfail140
Simon
</pre>
TicketpimlottThu, 14 Jul 2005 21:45:42 GMT
http://ghc.haskell.org/trac/ghc/ticket/409#comment:2
http://ghc.haskell.org/trac/ghc/ticket/409#comment:2
<pre class="wiki">Logged In: YES
user_id=498741
That's excellent. In fact, I look forward to making this
mistake in the future.
</pre>
Ticket