考虑这个例子:
applyKTimes :: Integral i => i -> (a -> a) -> a -> a
applyKTimes 0 _ x = x
applyKTimes k f x = applyKTimes (k-1) f (f x)
applyThrice :: (a -> a) -> a -> a
applyThrice = applyKTimes 3
applyThrice
中的3
由GHC缺省为Integer
,如使用-Wall
编译时所示
Warning: Defaulting the following constraint(s) to type 'Integer'
'Integral t'
arising from a use of 'applyKTimes'
所以我猜Integer
是默认的Integral a => a
。
-Wall
..)时,它确实会抱怨
https://stackoverflow.com/questions/2861988
复制相似问题