Could anybody explain this output to me? Im completely new at Haskell and do not know why that happens.
import Data.Char
o=ord 'f'
main=do print (o==102)
print (mod (102^2087) 9797)
print (mod (o^2087) 9797)
Output:
xxx:~/Arbeitsfläche$ runhaskell st.hs
True
5253
0
GHC version 7.4.1, Ubuntu
This is because
ohas typeIntwhich has a limited range and thus(mod (o^2087) 9797)is also anInt. However, the constant102is of a generic numeric type (Num a => a) and(mod (102^2087) 9797)is of generic integral type (Integral a => a). When this generic integral type must be resolved to a concrete type, which happens when applyingprint, the default resolution is to chooseInteger, an unbounded integral type. The details of this resolution are described in section 4.3.4 Ambiguous Types, and Defaults for Overloaded Numeric Operations of the Haskell 2010 Report.