Fakultas Ilmu Komputer UI

Skip to content
Snippets Groups Projects
Commit 5db1bb33 authored by Sean Gillespie's avatar Sean Gillespie Committed by GitHub
Browse files

Begin an examples section

parent ad85c8c2
No related branches found
No related tags found
No related merge requests found
......@@ -52,6 +52,24 @@ An abstraction is applied by using the form `f x y z`, where `f` is a lambda abs
(λx. x) x
(λx y. x) (λx. x)
# Examples
λ is surprisingly expressive for a language so small. We will now look at representing simple data types using pure λ, including natural numbers, booleans, and records.
# Natural Numbers
Natural numbers can be achieved by using what we call Church Numerals.
0: λ f x. x
1: λ f x. f x
2: λ f x. f (f x)
3: λ f x. f (f (f x))
The pattern here is any number `n` is achieved by applying it's first argument, `f`, `n` times, to its second argument, `x`. We can generalize this to two functions
zero: λ f x. x
succ: λ n f x. f (n f x)
We have defined natural numbers inductively, using two cases.
# References
1. [Lambda Calculus](https://en.wikipedia.org/wiki/Lambda_calculus). Wikipedia: The Free Encyclopedia
2. Types and Programming Languages, Benjamin C. Pierce
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment