You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Manual/BuildTools/Lake.lean
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -479,7 +479,7 @@ Because they are Lean definitions, Lake scripts can only be defined in the Lean
479
479
480
480
Restore the following once we can import enough of Lake to elaborate it
481
481
482
-
`````
482
+
````
483
483
```lean (show := false)
484
484
section
485
485
open Lake DSL
@@ -507,7 +507,7 @@ script "list-deps" := do
507
507
```lean (show := false)
508
508
end
509
509
```
510
-
`````
510
+
````
511
511
512
512
:::::
513
513
@@ -525,7 +525,7 @@ Lint drivers may be executables or scripts, which are run by {lake}`lint`.
525
525
A test or lint driver can be configured by either setting the {tomlField Lake.PackageConfig}`testDriver` or {tomlField Lake.PackageConfig}`lintDriver` package configuration options or by tagging a script, executable, or library with the `test_driver` or `lint_driver` attribute in a Lean-format configuration file.
526
526
A definition in a dependency can be used as a test or lint driver by using the `<pkg>/<name>`syntaxfor the appropriate configuration option.
527
527
:::TODO
528
-
Restore the ``{attr}`` role for`test_driver` and `lint_driver` above. Right now, importing the attributes crashes the compiler.
528
+
Restore the `{attr}` role for`test_driver` and `lint_driver` above. Right now, importing the attributes crashes the compiler.
Copy file name to clipboardExpand all lines: Manual/Classes.lean
+7-5Lines changed: 7 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -158,7 +158,7 @@ use the command `set_option checkBinderAnnotations false` to disable the check
158
158
159
159
::::example"Class vs Structure Constructors"
160
160
A very small algebraic hierarchy can be represented either as structures ({name}`S.Magma`, {name}`S.Semigroup`, and {name}`S.Monoid` below), a mix of structures and classes ({name}`C1.Monoid`), or only using classes ({name}`C2.Magma`, {name}`C2.Semigroup`, and {name}`C2.Monoid`):
161
-
````lean
161
+
```lean
162
162
namespace S
163
163
structureMagma (α : Type u) where
164
164
op : α → α → α
@@ -191,7 +191,7 @@ class Monoid (α : Type u) extends Semigroup α where
191
191
ident_left : ∀ x, op ident x = x
192
192
ident_right : ∀ x, op x ident = x
193
193
end C2
194
-
````
194
+
```
195
195
196
196
197
197
{name}`S.Monoid.mk` and {name}`C1.Monoid.mk`have identical signatures, because the parent of the class {name}`C1.Monoid`isnotitselfaclass:
@@ -257,7 +257,7 @@ Two instances of the same class with the same parameters are not necessarily ide
257
257
::::example"Instances are Not Unique"
258
258
259
259
This implementation of binary heap insertion is buggy:
Copy file name to clipboardExpand all lines: Manual/Coercions.lean
+23-12Lines changed: 23 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -354,7 +354,7 @@ def tomorrow : Later String :=
354
354
section
355
355
variable {α : Type u}
356
356
```
357
-
:::example"Duplicate Evaluation in Coercions"
357
+
::::example"Duplicate Evaluation in Coercions"
358
358
Because the contents of {lean}`Coe` instances are unfolded during coercion insertion, coercions that use their argument more than once should be careful to ensure that evaluation occurs just once.
359
359
This can be done by using a helper function that is not part of the instance, or by using {keywordOf Lean.Parser.Term.let}`let` to evaluate the coerced term and then re-use its resulting value.
When the {name}`Coe`instanceisunfolded,thecallto {name}`twice` remains, which causes its argument to be evaluated before the body of the function is executed.
381
-
As a result, the {keywordOf Lean.Parser.Term.dbgTrace}`dbg_trace`executes just once:
381
+
As a result, the {keywordOf Lean.Parser.Term.dbgTrace}`dbg_trace`is included in the resulting term just once:
382
382
```lean (name := eval1)
383
-
#eval ((dbg_trace "hello"; 5 : Nat) : Twice Nat)
383
+
#check ((dbg_trace "hello"; 5 : Nat) : Twice Nat)
384
384
```
385
+
:::comment
386
+
This used to demonstrate the effect:
385
387
```leanOutput eval1
386
388
hello
387
389
```
390
+
:::
388
391
```leanOutput eval1
389
-
{ first := 5, second := 5, first_eq_second := _ }
392
+
↑(dbgTrace (toString "hello") fun x => 5) : Twice Nat
390
393
```
391
394
392
395
Inlining the helper into the {name}`Coe`instanceresultsinatermthatduplicatesthe {keywordOf Lean.Parser.Term.dbgTrace}`dbg_trace`:
393
396
```lean (name := eval2)
394
397
instance : Coe α (Twice α) where
395
398
coe x := ⟨x, x, rfl⟩
396
399
397
-
#eval ((dbg_trace "hello"; 5 : Nat) : Twice Nat)
400
+
#check ((dbg_trace "hello"; 5 : Nat) : Twice Nat)
398
401
```
402
+
:::comment
403
+
This used to check the effects, but can't in the new codegen
399
404
```leanOutput eval2
400
405
hello
401
406
hello
402
407
```
408
+
:::
403
409
```leanOutput eval2
404
-
{ first := 5, second := 5, first_eq_second := _ }
410
+
{ first := dbgTrace (toString "hello") fun x => 5, second := dbgTrace (toString "hello") fun x => 5,
411
+
first_eq_second := ⋯ } : Twice Nat
405
412
```
406
413
407
-
Introducing an intermediate name for the result of the evaluation prevents the duplicated work:
414
+
Introducing an intermediate name for the result of the evaluation prevents the duplication of {keywordOf Lean.Parser.Term.dbgTrace}`dbg_trace`:
408
415
```lean (name := eval3)
409
416
instance : Coe α (Twice α) where
410
417
coe x := let y := x; ⟨y, y, rfl⟩
411
418
412
-
#eval ((dbg_trace "hello"; 5 : Nat) : Twice Nat)
419
+
#check ((dbg_trace "hello"; 5 : Nat) : Twice Nat)
413
420
```
421
+
:::comment
422
+
This also checked the effects
414
423
```leanOutput eval3
415
424
hello
416
425
```
426
+
:::
417
427
```leanOutput eval3
418
-
{ first := 5, second := 5, first_eq_second := _ }
428
+
let y := dbgTrace (toString "hello") fun x => 5;
429
+
{ first := y, second := y, first_eq_second := ⋯ } : Twice Nat
419
430
```
420
431
421
-
:::
432
+
::::
422
433
```lean (show := false)
423
434
end
424
435
```
@@ -485,12 +496,12 @@ Non-dependent coercions are used whenever all values of the inferred type can be
485
496
486
497
:::example"Defining Dependent Coercions"
487
498
The string "four" can be coerced into the natural number {lean type:="Nat"}`4`with this instancedeclaration:
0 commit comments