lean4-htt/tests/lean/run/dep_coe_to_fn3.lean
Leonardo de Moura 5cef84709f refactor(library): avoid auxiliary definitions such as add/mul/le/etc
See Section "Other goodies" at
https://github.com/leanprover/lean/wiki/Refactoring-structures

This commit also improves the support for projections in the
unifier/matcher.

Now, we consider the extra case-split for projections.
Given a projection `proj`, and the constraint `proj s =?= proj t`, we need to try first `s =?= t` and if it fails, then try to reduce.
This is needed in the standard library because we now have constraints such as:
```
@has_le.le ?A ?s ?a ?b  =?=  @has_le.le nat nat.has_add x y
```
If we reduce the right hand side, we get the unsolvable constraint
```
@has_le.le ?A ?s ?a ?b  =?=  nat.le x y
```
Before this change, the constraint was `@le ?A ?s ?a ?b  =?=  @le nat nat.has_add x y`, and we already perform a case-split in this case.
Moreover, projections were eagerly reduced whenever possible.
The extra case-split generates a performance problem in several tests. For example `fib 8 = 34` was timing out.
I worked around this issue by performing the case-split only when the constraint contains meta-variables.
There are also minor issues. Example. `<` is notation for `has_lt.lt`, but `>` is for `gt`.
2017-05-01 08:52:19 -07:00

36 lines
723 B
Text

universe variables u v
structure Func :=
(A : Type u) (B : A → Type v) (fn : Π a, B a → B a)
instance F_to_fn : has_coe_to_fun Func :=
{ F := λ f, Π a, f^.B a → f^.B a,
coe := λ f a b, f^.fn a (f^.fn a b) }
variables (f : Func) (a : f^.A) (b : f^.B a)
#check (f a b)
def f1 : Func :=
{ A := nat,
B := λ a, nat,
fn := (+) }
-- set_option trace.type_context.is_def_eq_detail true
/- We need to mark 10 as a nat.
Reason: f1 is not reducible, then type class resolution
cannot find an instance for `has_one (Func.A f1)` -/
example : f1 (10:nat) (30:nat) = (50:nat) :=
rfl
/-
#exit
attribute [reducible] f1
example : f1 10 30 = 50 :=
rfl
example (n m : nat) : f1 n m = n + (n + m) :=
rfl
-/