[GHC] #1090: Bad monomorphism-restriction-related type error message
GHC
trac at galois.com
Sun Jan 7 23:04:52 EST 2007
#1090: Bad monomorphism-restriction-related type error message
----------------------------------------+-----------------------------------
Reporter: kirsten | Owner:
Type: bug | Status: new
Priority: lowest | Milestone:
Component: Compiler (Type checker) | Version: 6.6
Severity: trivial | Keywords:
Difficulty: Unknown | Testcase:
Architecture: Multiple | Os: Multiple
----------------------------------------+-----------------------------------
Consider the following program:
{{{
module Small2 where
printFormatted :: IO ()
printFormatted =
let myPrint :: (a -> String) -> a -> IO ()
myPrint f s = putStr (f s)
-- myShow :: Show a => a -> IO ()
myShow = myPrint show in
myShow 1 >> myShow "foo"
}}}
If I compile this I get:
{{{
> ghc --make -no-recomp -c small2.hs
[1 of 1] Compiling Small2 ( small2.hs, small2.o )
small2.hs:9:19:
No instance for (Num [Char])
arising from the literal `1' at small2.hs:9:19
Possible fix: add an instance declaration for (Num [Char])
In the first argument of `myShow', namely `1'
In the first argument of `(>>)', namely `myShow 1'
In the expression:
let
myPrint :: (a -> String) -> a -> IO ()
myPrint f s = putStr (f s)
myShow = myPrint show
in (myShow 1) >> (myShow "foo")
}}}
The fix, of course, is to either add -fno-monomorphism-restriction or to
uncomment the type signature for {{{myShow}}}, but it took me a while to
figure that out. It would be much better if the error message would
suggest adding a type signature for {{{myShow}}}. As it is, the suggestion
to add an instance for {{{Num [Char]}}} is none too helpful.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/1090>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the Glasgow-haskell-bugs
mailing list