Skip to content

Commit 5696942

Browse files
authored
Merge pull request #142 from ydewit/master
added subsections to make it easier to eyeball content
2 parents c407b65 + 75f8967 commit 5696942

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

lean/main/03_expressions.lean

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ we must be careful to apply each universe-polymorphic constant to the right univ
191191
192192
## Constructing Expressions
193193
194+
### Constants
195+
194196
The simplest expressions we can construct are constants.
195197
We use the `const` constructor and give it a name and a list of universe levels.
196198
Most of our examples only involve non-universe-polymorphic constants,
@@ -228,6 +230,8 @@ def z₂ := Expr.const ``zero []
228230
#eval z₂ -- Lean.Expr.const `Nat.zero []
229231

230232
/-
233+
### Function Applications
234+
231235
The next class of expressions we consider are function applications.
232236
These can be built using the `app` constructor,
233237
with the first argument being an expression for the function
@@ -242,29 +246,31 @@ def one := Expr.app (.const ``Nat.succ []) z
242246
#eval one
243247
-- Lean.Expr.app (Lean.Expr.const `Nat.succ []) (Lean.Expr.const `Nat.zero [])
244248

245-
def natExpr: Nat → Expr
249+
def natExpr: Nat → Expr
246250
| 0 => z
247251
| n + 1 => .app (.const ``Nat.succ []) (natExpr n)
248252

249253
/-
250254
Next we use the variant `mkAppN` which allows application with multiple arguments.
251255
-/
252256

253-
def sumExpr : Nat → Nat → Expr
257+
def sumExpr : Nat → Nat → Expr
254258
| n, m => mkAppN (.const ``Nat.add []) #[natExpr n, natExpr m]
255259

256260
/-
257261
As you may have noticed, we didn't show `#eval` outputs for the two last functions.
258262
That's because the resulting expressions can grow so large
259263
that it's hard to make sense of them.
260264
265+
### Lambda Abstractions
266+
261267
We next use the constructor `lam`
262268
to construct a simple function which takes any natural number `x` and returns `Nat.zero`.
263269
The argument `BinderInfo.default` says that `x` is an explicit argument
264270
(rather than an implicit or typeclass argument).
265271
-/
266272

267-
def constZero : Expr :=
273+
def constZero : Expr :=
268274
.lam `x (.const ``Nat []) (.const ``Nat.zero []) BinderInfo.default
269275

270276
#eval constZero

0 commit comments

Comments
 (0)