let abs x = if x abs 5 5 Prelude> -6ren">
gpt4 book ai didi

haskell - "No instance for"错误

转载 作者:行者123 更新时间:2023-12-03 14:56:19 24 4
gpt4 key购买 nike

http://en.wikibooks.org/wiki/Haskell/Beginning 中的示例为例

Prelude> let abs x = if x < 0 then -x else x
Prelude> abs 5
5
Prelude> abs -3

<interactive>:1:6:
No instance for (Num (a0 -> a0))
arising from the literal `3'
Possible fix: add an instance declaration for (Num (a0 -> a0))
In the second argument of `(-)', namely `3'
In the expression: abs - 3
In an equation for `it': it = abs - 3

怎么了?

最佳答案

Haskell 认为您正在尝试减去 3来自 abs ,并提示 abs不是一个数字。使用一元否定运算符时需要添加括号:

abs (-3)

关于haskell - "No instance for"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6224212/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com