Skip to content

Instantly share code, notes, and snippets.

@WillNess
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WillNess/90e1698cd49dcfea0146 to your computer and use it in GitHub Desktop.
Save WillNess/90e1698cd49dcfea0146 to your computer and use it in GitHub Desktop.
Prelude> foldr (\x k-> k . (:) x) id [1..4] []
[4,3,2,1]
Prelude> foldl (\k x-> k . (:) x) id [1..4] []
[1,2,3,4]
Prelude>
Prelude> foldr (\x r-> (:) x r) [] [1..4]
[1,2,3,4]
Prelude> foldl (\r x-> (:) x r) [] [1..4]
[4,3,2,1]
Prelude>
foldr f z xs == foldl (\k x-> k . f x) id xs z
foldl f z xs == foldr (\x k-> k . flip f x) id xs z
foldr f z xs == foldl (\k x r-> k (f x r)) id xs z
foldl f z xs == foldr (\x k r-> k (f r x)) id xs z
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment