3 ms·
Yeah, that's definitely a confusing part of GHCi. If you see an error message like the one in the post Prelude> 1+[2,3] <interactive>:1:1: error:
by cole-k 5y ago
Yeah, that's definitely a confusing part of GHCi. If you see an error message like the one in the post
Prelude> 1+[2,3]
<interactive>:1:1: error:
• Non type-variable argument in the constraint: Num [a]
(Use FlexibleContexts to permit this)
• When checking the inferred type
it :: forall a. (Num a, Num [a]) => [a]
The "line-number" is found on this line
<interactive>:1:1: error:
Since it's in a REPL, it is referring to the first line you entered.
The more confusing part is that the important error is found here
• When checking the inferred type
it :: forall a. (Num a, Num [a]) => [a]
where it is assumed that you know all REPL statements that don't bind to a variable are bound to a variable named "it". So the error is really saying that the whole expression 1+[2,3] has that inferred type, and that type is bad.
If you load your example into a file and run GHC on it, it will produce a still confusing error message, but it will at least show you where the problems are
error-message.hs:3:11: error:
• No instance for (Num [a0]) arising from a use of ‘+’
• In the expression: 1 + [1, 2]
In an equation for ‘badType’: badType = 1 + [1, 2]
|
3 | badType = 1 + [1,2]
| ^^^^^^^^^
(I've omitted another, much longer error message it spewed out which is similarly confusing)