when I try something in ghci after loading the file like putStrLn $ showManyP \"%d\" 10
it works but why this don\'t work when I write it in the file
main
In ghc, When you enter a numeric constant like 10
, it can be any type that is an instance of Num
. If there are no additional type constraints, it is an undecided instance, and you must provide a specific type; i.e. (10 :: Int)
. Ghci is interactive, and it would be a pain to have to add types to numbers, so it helps you out by assuming that, in the absence of additional type constraints, that things that look like integers are of type Integer
. This is explained in the GHC User Guide 2.4.5. Type defaulting in GHCi
According to the "2010 Haskell Report", in 4.3.4 Ambiguous Types, and Defaults for Overloaded Numeric Operations, there is a default
keyword that allows you to take advantage of this behavior in compiled modules.