@@ -191,6 +191,8 @@ we must be careful to apply each universe-polymorphic constant to the right univ
191
191
192
192
## Constructing Expressions
193
193
194
+ ### Constants
195
+
194
196
The simplest expressions we can construct are constants.
195
197
We use the `const` constructor and give it a name and a list of universe levels.
196
198
Most of our examples only involve non-universe-polymorphic constants,
@@ -228,6 +230,8 @@ def z₂ := Expr.const ``zero []
228
230
#eval z₂ -- Lean.Expr.const `Nat.zero []
229
231
230
232
/-
233
+ ### Function Applications
234
+
231
235
The next class of expressions we consider are function applications.
232
236
These can be built using the `app` constructor,
233
237
with the first argument being an expression for the function
@@ -242,29 +246,31 @@ def one := Expr.app (.const ``Nat.succ []) z
242
246
#eval one
243
247
-- Lean.Expr.app (Lean.Expr.const `Nat.succ []) (Lean.Expr.const `Nat.zero [])
244
248
245
- def natExpr : Nat → Expr
249
+ def natExpr : Nat → Expr
246
250
| 0 => z
247
251
| n + 1 => .app (.const ``Nat.succ []) (natExpr n)
248
252
249
253
/-
250
254
Next we use the variant `mkAppN` which allows application with multiple arguments.
251
255
-/
252
256
253
- def sumExpr : Nat → Nat → Expr
257
+ def sumExpr : Nat → Nat → Expr
254
258
| n, m => mkAppN (.const ``Nat.add []) #[natExpr n, natExpr m]
255
259
256
260
/-
257
261
As you may have noticed, we didn't show `#eval` outputs for the two last functions.
258
262
That's because the resulting expressions can grow so large
259
263
that it's hard to make sense of them.
260
264
265
+ ### Lambda Abstractions
266
+
261
267
We next use the constructor `lam`
262
268
to construct a simple function which takes any natural number `x` and returns `Nat.zero`.
263
269
The argument `BinderInfo.default` says that `x` is an explicit argument
264
270
(rather than an implicit or typeclass argument).
265
271
-/
266
272
267
- def constZero : Expr :=
273
+ def constZero : Expr :=
268
274
.lam `x (.const ``Nat []) (.const ``Nat.zero []) BinderInfo.default
269
275
270
276
#eval constZero
0 commit comments