我在文件main.hs中有以下代码:
teste :: Integral a => a -> a
teste n = truncate (sqrt n) + mod n 2
Run Code Online (Sandbox Code Playgroud)
当我尝试加载它时,我从ghci中收到以下错误:
Prelude> :l main.hs
[1 of 1] Compiling Main ( main.hs, interpreted )
main.hs:12:11:
Could not deduce (RealFrac a) arising from a use of ‘truncate’
from the context (Integral a)
bound by the type signature for teste :: Integral a => a -> a
at main.hs:11:10-29
Possible fix:
add (RealFrac a) to the context of
the type signature for teste :: …Run Code Online (Sandbox Code Playgroud)