Created
December 29, 2014 14:59
-
-
Save amonshiz/6ee585dd4360d47baabd to your computer and use it in GitHub Desktop.
foldl blog example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
foldl (\acc x -> acc + x) 0 [1,2,3,4] | |
-- acc starts at 0, x starts as the first element of the list, so 1 | |
-- 0 + 1 = 1 -> acc = 1, list = [2,3,4] | |
-- 1 + 2 = 3 -> acc = 3, list = [3,4] | |
-- 3 + 3 = 6 -> acc = 6, list = [4] | |
-- 6 + 4 = 10 -> acc = 10 | |
-- therefore, this foldl results in a value of 10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment