小编Ala*_*ius的帖子

如何在Haskell中进行类型转换?

我在文件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)

haskell type-conversion

5
推荐指数
1
解决办法
69
查看次数

标签 统计

haskell ×1

type-conversion ×1