“无实例”错误 [英] "No instance for" error

查看:118
本文介绍了“无实例”错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

遵循 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

有什么问题? / p>

What's wrong?

推荐答案

Haskell认为你正试图从<$ c中减去 3 $ c> abs ,并且抱怨 abs 不是数字。您需要在使用一元否定运算符时添加括号:

Haskell thinks you're trying to subtract 3 from abs, and is complaining that abs is not a number. You need to add parenthesis when using the unary negation operator:

abs (-3)

这篇关于“无实例”错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆