[GHC] #12124: Ambiguous type variable: it's a red herring!
GHC
ghc-devs at haskell.org
Fri May 27 07:13:46 UTC 2016
#12124: Ambiguous type variable: it's a red herring!
-------------------------------------+-------------------------------------
Reporter: drb226 | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 8.0.1
Keywords: | Operating System: Unknown/Multiple
Architecture: | Type of failure: None/Unknown
Unknown/Multiple |
Test Case: | Blocked By:
Blocking: | Related Tickets:
Differential Rev(s): | Wiki Page:
-------------------------------------+-------------------------------------
{{{
module Ret where
data Whoops = Whoops Int Int
foo :: Maybe Int
foo = return (case Whoops 1 2 of
Whoops a -> a
_ -> 0)
}}}
Note that there is a pattern match error in the case statement, which the
compiler correctly reports. However, it first reports the following red
herring:
{{{
ret.hs:6:7: error:
• Ambiguous type variable ‘m0’ arising from a use of ‘return’
prevents the constraint ‘(Monad m0)’ from being solved.
Probable fix: use a type annotation to specify what ‘m0’ should be.
These potential instances exist:
instance Monad IO -- Defined in ‘GHC.Base’
instance Monad Maybe -- Defined in ‘GHC.Base’
instance Monad ((->) r) -- Defined in ‘GHC.Base’
...plus two others
(use -fprint-potential-instances to see them all)
• In the expression:
return
(case Whoops 1 2 of {
Whoops a -> a
_ -> 0 })
In an equation for ‘foo’:
foo
= return
(case Whoops 1 2 of {
Whoops a -> a
_ -> 0 })
}}}
One would think that the context `foo :: Maybe Int` is sufficient for the
compiler to realize that `return (blah)` implies that m0 = Maybe,
regardless of the errors involved in the expression `(blah)`.
ghc 7.10.3 does not report this red herring. One can get a similar red-
herring type error in ghc 7.10.3 by replacing `return (...)` with `return
$ ...` in the example above.
The red herring also does *not* appear, in ghc 7.10.3 or in ghc 8.0.1, if
you name the broken case expression with a let binding.
{{{
module Ret where
data Whoops = Whoops Int Int
foo :: Maybe Int
foo = return boo where
boo = case Whoops 1 2 of
Whoops a -> a
_ -> 0
}}}
There seems to be something fishy going on here.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12124>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list