Skip to content

Instantly share code, notes, and snippets.

@JoelQ
Created March 20, 2018 18:44
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 JoelQ/a742b80c81bf55c3dd4f18707fc90412 to your computer and use it in GitHub Desktop.
Save JoelQ/a742b80c81bf55c3dd4f18707fc90412 to your computer and use it in GitHub Desktop.
Folding a list is like replacing the cons and empty constructors
-- 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