# Foldl

(define foldl (lambda (f a xs) (if (null? xs) a (foldl f (f a (car xs)) (cdr xs)))))

foldl f a [] = a foldl f a (x:xs) = foldl f (f a x) xs

for *Normal Order* left fold lets evaluate accumulator *before* making a recursive call

foldl' f a [] = a foldl' f a (x:xs) = let a' = a `f` x in seq a' $ foldl' f a' xs

foldl(F, A, [H|T]) -> foldl(F, F(H, A), T); foldl(F, A, []) when is_function(F, 2) -> A.

Last modified
4 years ago
Last modified on Nov 1, 2016, 8:40:59 PM

**Note:**See TracWiki for help on using the wiki.