[Haskell-beginners] strange take result--explanation?
7stud
bbxx789_05ss at yahoo.com
Thu Mar 12 04:11:46 EDT 2009
*Main> let x = []
*Main> take (length x - 1) [1, 2, 3]
[]
*Main> length x
0
*Main> take (0 - 1) [1, 2, 3]
[]
*Main> take -1 [1, 2, 3]
<interactive>:1:0:
No instance for (Num (Int -> [a] -> [a]))
arising from a use of `-' at <interactive>:1:0-16
Possible fix:
add an instance declaration for (Num (Int -> [a] -> [a]))
In the expression: take - 1 [1, 2, 3]
In the definition of `it': it = take - 1 [1, 2, 3]
<interactive>:1:6:
No instance for (Num ([t] -> Int -> [a] -> [a]))
arising from the literal `1' at <interactive>:1:6-16
Possible fix:
add an instance declaration for (Num ([t] -> Int -> [a] -> [a]))
In the second argument of `(-)', namely `1 [1, 2, 3]'
In the expression: take - 1 [1, 2, 3]
In the definition of `it': it = take - 1 [1, 2, 3]
*Main> take - 1 [1, 2, 3]
-----
Why does
take (0 - 1) [1, 2, 3]
produce a result but not
take -1 [1, 2, 3]
? Thanks
More information about the Beginners
mailing list