该程序不会进行类型检查:
$ runghc a.hs
a.hs:12:25:
Couldn't match expected type `Word32' with actual type `Integer'
In the second argument of `div', namely `ix'
In the expression: len "ABCDEF" `div` ix
In an equation for `iy': iy = len "ABCDEF" `div` ix
但如果我删除wy
or iy
,它确实如此。为什么?
import Data.Word
import Data.List
len = genericLength
wx :: Word32
wx = 3
wy = len "ABCDEF" `div` wx
ix :: Integer
ix = 3
iy = len "ABCDEF" `div` ix
main = print 1