This has nothing to do with ghci. This restriction of monomorphism is annoying. If you try to compile the following file:
add = uncurry (+) main = do print $ add (1,2 :: Int) print $ add (1,2 :: Double)
You will receive an error message. If you expand:
main = do print $ uncurry (+) (1,2 :: Int) print $ uncurry (+) (1,2 :: Double)
Everything is fine, as expected. The restriction of monomorphism refuses to do something that βlooks like a valueβ (that is, Defined with no arguments on the left side of the equality) typeclass is polymorphic because it defeats the caching that usually happens. For example.
foo :: Integer foo = expensive computation bar :: (Num a) => a bar = expensive computation
foo guaranteed that it will be evaluated only once (well, at least in the GHC), while bar will be evaluated every time it is mentioned. Limiting monomorphism tries to save you from the latter case, by default, if it looks like what you wanted.
If you use the function only once (or always in the same type), enter the output that will take care of inferring the correct type for you. In this case, ghci does something a little different, guessing earlier. But using it on two different types shows what is happening.
If in doubt, use a type signature (or disable the wretched thing with {-# LANGUAGE NoMonomorphismRestriction #-} ).
luqui
source share