Today I bumped into Haskell's "Monomorphism Restriction", which essentially requires that you provide explicit type information on parameters that are overloaded. It appears that GHC/i aggressively tries to avoid producing this error, which can lead to some strange behavior. For instance, f is a function to show and then print something:
f = putStrLn . show
Loaded into GHCi in a file by itself will produce the MR error. However:
f = putStrLn . show
f [1, 2]
Does not. If you query the type of f, it reports f :: [Integer] -> IO (). It's inferred that f takes a list of Integers from our function call, which is understandable but not quite as general as we'd intented f to be. If we add an another call to display a string:
f = putStrLn . show
f [1, 2]
f "ab"
We receive a unhelpful type error about the value of "1". I was scratching my head for awhile until I checked the type of my helper function.
The solution? Explicitly add the type signature:
f :: Show a => a -> IO ()
f = putStrLn . show