[GHC] #13292: Type checker rejects ambiguous top level declaration. (was: panic! (the 'impossible' happened): corePrepPgm)
GHC
ghc-devs at haskell.org
Sat Feb 18 10:11:50 UTC 2017
#13292: Type checker rejects ambiguous top level declaration.
-------------------------------------+-------------------------------------
Reporter: jeiea | Owner: (none)
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler (Type | Version: 8.0.2
checker) |
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture: x86_64
| (amd64)
Type of failure: Other | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Changes (by Phyx-):
* cc: bgamari (added)
* failure: None/Unknown => Other
* component: Compiler => Compiler (Type checker)
* os: Windows => Unknown/Multiple
Comment:
Hi,
Thanks for the report. I am not sure that this is a bug or at least not a
new one.
It seems more like a limitation of the type inferencing.
The confusing error message comes from the handling of packages in the
`cabal` file.
The error simplified is:
{{{
$ ~/ghc/inplace/bin/ghc-stage2.exe Main.hs
[1 of 2] Compiling Lib ( Lib.hs, Lib.o )
Lib.hs:6:12: error:
* Ambiguous type variable `m0' arising from a use of `return'
prevents the constraint `(Monad m0)' from being solved.
Relevant bindings include someFunc :: m0 () (bound at Lib.hs:6:1)
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 ()
In an equation for `someFunc': someFunc = return ()
|
6 | someFunc = return ()
| ^^^^^^^^^
}}}
Essentially (I think) because there's so little context for the type
inference it can't disambiguate between the possible types `someFunc` can
have.
So it can't chose which type is the most general type for `someFunc`
simply because
they're all valid and can be the most general type.
So it needs to be told, either by adding a type signature, or using
`someFunc` in a way that allows it to determine what the most general type
should be.
e.g.
{{{
module Lib
( someFunc
) where
-- someFunc :: Monad m => m ()
someFunc = moreFunc
moreFunc :: IO ()
moreFunc = someFunc
}}}
But I'm not that familiar with GHC's typechecker so I'll reclassify and
leave it for someone more knowledgeable in this area. I also don't know
why `stack repl` would have worked.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13292#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list