Works in ghci but not in the file

后端 未结 1 845
庸人自扰
庸人自扰 2020-12-20 20:58

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

相关标签:
1条回答
  • 2020-12-20 21:46

    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.

    0 讨论(0)
提交回复
热议问题