lean4-htt/library/init/meta/occurrences.lean
Leonardo de Moura edd5e97045 feat(frontends/lean/elaborator): coercion from (decidable) Prop to bool
This is a hard coded extra case. It is not an instance of has_coe.
Even if we change has_coe to accomodate this case, it will not be a
satisfactory solution because this coercion depends on the element and
not the type, and the element usually contains metavariables.

We should eventually write a tactic for synthesizing coercions.
2017-02-14 18:41:32 -08:00

52 lines
1.5 KiB
Text

/-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import init.logic init.data.to_string init.meta.format
import init.meta.contradiction_tactic init.meta.constructor_tactic
import init.meta.relation_tactics init.meta.injection_tactic
/- We can specify the scope of application of some tactics using
the following type.
- all : all occurrences of a given term are considered.
- pos [1, 3] : only the first and third occurrences of a given
term are consiered.
- neg [2] : all but the second occurrence of a given term
are considered. -/
inductive occurrences
| all
| pos : list nat → occurrences
| neg : list nat → occurrences
open occurrences
def occurrences.contains : occurrences → nat → bool
| all p := tt
| (occurrences.pos ps) p := p ∈ ps
| (occurrences.neg ps) p := p ∉ ps
instance : inhabited occurrences :=
⟨all⟩
def occurrences_to_string : occurrences → string
| occurrences.all := "*"
| (occurrences.pos l) := to_string l
| (occurrences.neg l) := "-" ++ to_string l
instance : has_to_string occurrences :=
⟨occurrences_to_string⟩
meta def occurrences_to_format : occurrences → format
| occurrences.all := to_fmt "*"
| (occurrences.pos l) := to_fmt l
| (occurrences.neg l) := to_fmt "-" ++ to_fmt l
meta instance : has_to_format occurrences :=
⟨occurrences_to_format⟩
open decidable tactic