Question 1
Hi, if in WinGHCi I intentionally do the following wrong piece of code :
3 4
Then the error message I get is
<interactive>:1:1:
No instance for (Num (a0 -> t0))
arising from the literal `3'
Possible fix: add an instance declaration for (Num (a0 -> t0))
In the expression: 3
In the expression: 3 4
In an equation for `it': it = 3 4
What exactly does No instance for (Num (a0 -> t0))
mean?
Question 2
Why does the following piece of code :
(+) 2 3 4
<interactive>:1:7:
No instance for (Num (a0 -> t0))
arising from the literal `3'
Possible fix: add an instance declaration for (Num (a0 -> t0))
In the second argument of `(+)', namely `3'
In the expression: (+) 2 3 4
In an equation for `it': it = (+) 2 3 4
yield a slightly different error from the second piece of code :
2+3 4
<interactive>:1:3:
No instance for (Num (a1 -> a0))
arising from the literal `3'
Possible fix: add an instance declaration for (Num (a1 -> a0))
In the expression: 3
In the second argument of `(+)', namely `3 4'
In the expression: 2 + 3 4
Namely in the first piece of code we have No instance for (Num (a0 -> t0))
where as in the second piece of code we have No instance for (Num (a1 -> a0))
.
[Response to ehird]
(Questions moved from answer comments) :
1) I appreciate the latter two expressions are different, but are you saying that I should not try to understand why the interpreter chooses (Num (a0 -> t0))
for the former and (Num(a1 -> a0))
for the latter, besides the fact that they are different?
2)Hi, and with the former when you say "But there's no Num instance for functions" what do you mean? Sorry I am not clear on what the concept of an instance is. Furthermore, just out of curiosity, could you use your instance Num (a -> b)
method to somehow tell the interpreter to interpret 3 4
as 4 modulo 3
?