Ich habe die folgende Verwendung von foldl welche erroring:foldl Ausdruck nicht durch die Erstellung von wörtlichen verwenden
elementAt :: [a] -> Int -> a
elementAt [] x = error "No empty lists for element-at"
elementAt xs x = foldl(\acc (a, b) -> if(b == x) then a else acc) 0 $ zip xs [0..]
Wenn ich versuche, und kompilieren ich diesen Fehler:
exercises.hs:8:67: error: * No instance for (Num a) arising from the literal
0' Possible fix: add (Num a) to the context of the type signature for: elementAt :: [a] -> Int -> a * In the second argument of
foldl', namely `0' In the expression: foldl (\ acc (a, b) -> if (b == x) then a else acc) 0 In the expression: foldl (\ acc (a, b) -> if (b == x) then a else acc) 0 $ zip xs [0 .. ] Failed, modules loaded: none.