Created
March 20, 2018 18:44
-
-
Save JoelQ/a742b80c81bf55c3dd4f18707fc90412 to your computer and use it in GitHub Desktop.
Folding a list is like replacing the cons and empty constructors
This file contains 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
-- GIVEN | |
type MyList a | |
= Cons a (MyList a) | |
| Empty | |
add : Int -> Int -> Int | |
add a b = | |
a + b | |
-- WHEN FOLDING | |
foldl add 0 | |
-- NOTE THE SYMMETRY | |
Cons 3 (Cons 2 (Cons 1 Empty)) | |
add 3 (add 2 (add 1 0 )) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment