Trying to understand the foldl type?

The type is: foldl :: (a -> b -> a) -> a -> [b] -> a Eg I might do something like this: foldl (+) 0 [1..10] so taking (a -> b -> a) leftmost a is (+) b is 0 right a is what? The first value in the list? Then -> ? [b] ? Is this like the temporary recursion calculation? final -> a is the result?

Given foldl (+) 0 [1..10] (+) is (a -> b -> a) 0 is a [1..10] is [b] and the final a is the result of the expression. On Tuesday, December 24, 2013, Angus Comber wrote:
The type is:
foldl :: (a -> b -> a) -> a -> [b] -> a
Eg I might do something like this:
foldl (+) 0 [1..10]
so taking (a -> b -> a)
leftmost a is (+) b is 0 right a is what? The first value in the list?
Then -> ?
[b] ? Is this like the temporary recursion calculation?
final -> a is the result?

On Tue, Dec 24, 2013 at 8:19 PM, Angus Comber
foldl :: (a -> b -> a) -> a -> [b] -> a
Eg I might do something like this:
foldl (+) 0 [1..10]
Try the following in ghci to see if you get an idea of what's going on: :t foldl :t foldl (+) :t foldl (+) 0 :t foldl (+) 0 [1..10] -- Kim-Ee
participants (3)
-
Angus Comber
-
Bob Ippolito
-
Kim-Ee Yeoh