考虑这个例子:
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
Run Code Online (Sandbox Code Playgroud)
该3在applyThrice通过GHC默认为一个Integer与编译时如图所示-Wall:
Warning: Defaulting the following constraint(s) to type 'Integer'
'Integral t'
arising from a use of 'applyKTimes'
Run Code Online (Sandbox Code Playgroud)
所以我猜这Integer是默认的Integral a => a.
-Wall …