lean4-htt/tests/lean/run/apply4.lean
Leonardo de Moura f650a1b873 refactor(library/init/meta): avoid '_core' idiom using default parameters
I kept a few core methods (e.g., exact_core and apply_core). Reason:
if we use default parameters

    meta constant exact (e : expr) (md := semireducible) : tactic unit

then, we will not be able to write

    to_expr p >>= exact

The workaround is

    do t <- to_expr p, exact t

or
    to_expr p >>= (fun x, exact x)

One alternative is to change how we handle default parameters, and
eta-expand applications that involve default parameters.
We may also have an attribute [eta_expand]. Then

    attribute [eta_expand] foo

instructs the elaborator to automatically eta-expand foo-applications.
The attribute would give users more control, and avoid potential
performance problems. Without the attribute, then for every function
application the elaborator has to check the type and decide whether it
must be eta-expanded or not.

@gebner @kha What do you think?
2017-02-14 09:46:55 -08:00

50 lines
1 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 bool
universe variables u
constant foo {A : Type u} [inhabited A] (a b : A) : a = default A → a = b
example (a b : nat) : a = 0 → a = b :=
by do
intro `H,
apply (expr.const `foo [level.of_nat 0]),
trace_state,
assumption
definition ex : inhabited (nat × nat × bool) :=
by apply_instance
set_option pp.all true
print ex
set_option pp.all false
example (a b : nat) : a = 0 → a = b :=
by do
intro `H,
apply_core (expr.const `foo [level.of_nat 0]) {approx := ff, all := tt, use_instances := ff },
trace_state,
a ← get_local `a,
trace_state,
mk_app `inhabited.mk [a] >>= exact,
trace "--------",
trace_state,
reflexivity
print "----------------"
set_option pp.all true
example (a b : nat) : a = 0 → a = b :=
by do
intro `H,
foo ← mk_const `foo,
trace foo,
apply foo,
trace_state,
assumption
example (a b : nat) : a = 0 → a = b :=
by do
`[intro],
apply_core (expr.const `foo [level.of_nat 0]) {approx := ff, all := tt, use_instances := ff},
`[exact inhabited.mk a],
reflexivity