Name: Anonymous 2011-07-12 15:24
Hi /prog/,
why bellow function doesn't produce an array of natural numbers from n to 0?
Instead I got rather cryptic message:
How to fix this? Why this failsand bellow code works?
why bellow function doesn't produce an array of natural numbers from n to 0?
Prelude> let foo n = if n > 0 then n : (foo n-1) else []Instead I got rather cryptic message:
Prelude> foo 5
<interactive>:1:0:
No instance for (Num [t])
arising from a use of `foo' at <interactive>:1:0-4
Possible fix: add an instance declaration for (Num [t])
In the expression: foo 5
In the definition of `it': it = foo 5How to fix this? Why this failsand bellow code works?
Prelude> 1 : 2 : []
[1,2]