3 ms·
Here was about my first experience of Haskell. I don't mind admitting I bounced fairly hard at first. I've since done a bit more, but find it too limiting rathe
by CJefferson 12y ago
Here was about my first experience of Haskell. I don't mind admitting I bounced fairly hard at first. I've since done a bit more, but find it too limiting rather than freeing.
Prelude> foldr + [1,2,3]
<interactive>:14:9:
Couldn't match expected type ‘(a -> b -> b) -> b -> [a] -> b’
with actual type ‘[t0]’
Relevant bindings include
it :: (a -> b -> b) -> b -> [a] -> b (bound at <interactive>:14:1)
In the second argument of ‘(+)’, namely ‘[1, 2, 3]’
In the expression: foldr + [1, 2, 3]
In an equation for ‘it’: it = foldr + [1, 2, 3]
- Viktoras25 12y agoFinally I found out the correct version: foldr (+) 0 [1,2,3] 1. + contains only special characters and must be used either as infix function (1 + 2) or be enclosed in brackets 2. You need an initial value for the accumulator. You are reducing a list to a single value, you need to start somewhere Please, gurus of Haskell, correct me if I'm wrong, I've just recently started to learn the language