Lean 4 fork for HoTT-compatible kernel extensions (Path types, transport, HITs). Maintained against upstream leanprover/lean4.
Find a file
Leonardo de Moura 261dc999d0 refactor(frontends/lean/elaborator): mark thunk as opaque, and thunk A to A is now a coercion
@kha I was working in the new declaration type and using tasks there.
Since we don't have tasks yet in Lean, I decided to start refactoring
the `thunk` type. I defined it as:

```
-- TODO(Leo): mark as opaque, it is implemented by the new runtime
structure thunk (α : Type u) : Type u :=
(fn : unit → α)

def thunk.pure {α : Type u} (a : α) : thunk α :=
⟨λ _, a⟩

def thunk.get {α : Type u} (t : thunk α) : α :=
t.fn ()
```

The idea is to use the runtime primitives to implement them.
Then, I realized the support for `thunk`s in the elaborator are quite
hacky. Given `f x`, if `f`'s domain has type `thunk A`, we elaborate
`f x` as `f (fun _, x)` even if `x` has type `thunk A`.
This is quite bad, for example, suppose we have
```
def f (x : thunk A) := ...
```
Then, the following definition is type incorrect.
```
def g (x : thunk A) := f x
```
and we are forced to write
```
def g (x : thunk A) := f (x ())
```
The term `f (x ())` will be elaborated as `f (fun _, x ())` and an
unnecessary closure is created at runtime.

This mechanism inherited from Lean 3 is also incompatible with the
new thunk definition. Given `x : thunk A`, I want to write `x.get`
to retrieve the value instead of `x ()` as in Lean 3.
However, `x.get` expands into the nonsensical `(fun _, x).get`.

So, I decided to view the mapping `A` to `thunk A` as a "coercion".
I used double quotes, because it is a macro instead of a function.
If it were a coercion, then we would be using `thunk.pure` to coerce
values but this is not we want most of the time.
For example, given `f : thunk A -> B` and a term `t : A`, when we write
`f t`, we want it to be converted into `f (fun _, t)` instead of
`f (thunk.pure t)` which would eagerly compute `t`. The transformation
`t` into `fun _, t` is syntactic.
We cannot implement it using type classes. I implemented it as
a hard-coded extra case like the one from `Prop` to `bool`.
We can also add a coercion from `thunk A` to `A` to avoid the `.get`.

That being said, I had a few breakages in the code base since we only
use coercions when the given and expected type do not contain
metavariables.
2018-08-21 15:27:51 -07:00
.github chore(.github/CONTRIBUTING): fix typos and URLs 2017-10-30 16:23:22 +01:00
bin chore(bin/lean-gdb.py): fix lean::name pretty printer and add lean::obj_list pretty printer 2018-06-06 15:36:28 +02:00
doc doc(doc/coding_style,doc/commit_convention): fix git hook commands 2018-07-05 10:20:25 +02:00
extras/latex chore(extras/depgraph): remove leandeps 2017-07-15 02:27:17 -07:00
gen chore(*): fix style 2018-08-21 09:32:01 -07:00
images chore(CMakeLists.txt): move Lean logo to make sure we can test leanemacs without installing Lean 2015-01-31 17:38:49 -08:00
leanpkg chore(leanpkg): delete 2018-04-10 12:43:17 -07:00
library refactor(frontends/lean/elaborator): mark thunk as opaque, and thunk A to A is now a coercion 2018-08-21 15:27:51 -07:00
old_tests/tests chore(library/init/io): rename io.print_ln to io.println 2018-08-21 08:43:10 -07:00
packages chore(script/test_registry): Replace with leanpkg. Execute in every artifact-producing build configuration. 2017-12-20 14:01:45 -08:00
script refactor(library/system/io): move into init 2018-08-21 08:43:09 -07:00
src refactor(frontends/lean/elaborator): mark thunk as opaque, and thunk A to A is now a coercion 2018-08-21 15:27:51 -07:00
tests chore(library/init/io): rename io.print_ln to io.println 2018-08-21 08:43:10 -07:00
tmp chore(tmp/lean4.md): moved to google docs 2018-03-20 17:26:43 -07:00
.appveyor.yml chore(.appveyor,.travis): disable leanpkg registry tests 2018-04-12 18:32:20 +02:00
.clang-format feat(library/vm/process): add basic process support 2017-03-28 18:08:06 -07:00
.codecov.yml fix(.codecov.yml): do not fail github ci if coverage drops by 0.01% 2017-06-25 10:35:02 +02:00
.gitattributes chore(.gitattributes): use union merge strategy for doc/changes.md 2017-12-11 12:49:10 +01:00
.gitignore chore(.gitignore): ignore *.produced.out files 2018-05-01 08:43:46 -07:00
.travis.yml chore(.travis.yml): trigger AppVeyor nightly build from Travis 2018-04-13 16:44:27 +02:00
LICENSE Add LICENSE file 2013-07-15 18:55:48 -07:00
README.md chore(README): point CI links to lean4 branch 2018-04-12 13:50:42 +02:00

logo

LicenseWindowsLinux / macOSTest CoverageChat
Codecov Join the Zulip chat

About

Installation

Stable and nightly binary releases of Lean are available on the homepage. For building Lean from source, see the build instructions.

Miscellaneous

Roadmap