lean4-htt/tests/lean/run/proj_unify.lean
Leonardo de Moura d3eca9fa35 feat(library/type_context): improve unifier support for projections
We need this improvement to be able to finish Section "Other goodies" described at
https://github.com/leanprover/lean/wiki/Refactoring-structures

Before this commit, Lean would not be able to solve constraints such as

```lean
@has_add.add nat nat.has_add a b =?= @had_add.add ?A ?inst a b
```

The problem is that projections were being reduced eagerly, and the
constraint would be reduced to

```lean
nat.add a b =?= @had_add.add ?A ?inst a b
```

The new test proj_uniy.lean contains similar unification problems.
2017-04-27 15:55:09 -07:00

66 lines
1.7 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

open tactic
-- Unify (prod.fst ?m) with (prod.fst (1,2))
example : true :=
by do
type ← to_expr ``(nat × nat),
m₁ ← mk_meta_var type,
t₁ ← mk_app ``prod.fst [m₁],
t₂ ← to_expr ``(prod.fst (1, 2)),
unify t₁ t₂,
constructor
-- Unify (prod.fst (?m, 2)) with (prod.fst (3, 1))
example : true :=
by do
type ← to_expr ``(nat),
m₁ ← mk_meta_var type,
two ← to_expr ``(2),
mk ← mk_app ``prod.mk [m₁, two],
t₁ ← mk_app ``prod.fst [mk],
t₂ ← to_expr ``(prod.fst (3, 1)),
trace t₁, trace t₂,
unify t₁ t₂,
four ← to_expr ``(4),
fail_if_success (unify m₁ four),
three ← to_expr ``(3),
unify m₁ three,
constructor
-- Unify (prod.fst ?m) with (id (prod.fst (1,2)))
example : true :=
by do
type ← to_expr ``(nat × nat),
m₁ ← mk_meta_var type,
t₁ ← mk_app ``prod.fst [m₁],
t₂ ← to_expr ``(id (prod.fst (1, 2))),
unify t₁ t₂,
constructor
-- Unify (id (prod.fst ?m)) with (prod.fst (1,2))
example : true :=
by do
type ← to_expr ``(nat × nat),
m₁ ← mk_meta_var type,
s ← mk_app ``prod.fst [m₁],
t₁ ← mk_app ``id [s],
t₂ ← to_expr ``(id (prod.fst (1, 2))),
unify t₁ t₂,
constructor
-- Unify (prod.fst (?m, 2)) with (id (prod.fst (3, 1)))
example : true :=
by do
type ← to_expr ``(nat),
m₁ ← mk_meta_var type,
two ← to_expr ``(2),
mk ← mk_app ``prod.mk [m₁, two],
t₁ ← mk_app ``prod.fst [mk],
t₂ ← to_expr ``(id (prod.fst (3, 1))),
trace t₁, trace t₂,
unify t₁ t₂,
four ← to_expr ``(4),
fail_if_success (unify m₁ four),
three ← to_expr ``(3),
unify m₁ three,
constructor