我试图理解 haskell 错误消息,因为它们让新手程序员感到困惑。我能找到的最简单的例子是:
Prelude> 1 + True
<interactive>:2:3:
No instance for (Num Bool)
arising from a use of `+'
Possible fix: add an instance declaration for (Num Bool)
In the expression: 1 + True
In an equation for `it': it = 1 + True
为什么编译器不考虑参数顺序而寻找(Num Bool) ?为什么在我定义以下内容后它会起作用?
instance Num Bool where (+) a b = True;
[...]
Prelude> 1 + True
True
仅当第二个参数也是(Num Bool) 时,如何确保(+)可以应用于( Num Bool)?