Matching expressions with leading binders #
This module defines a family of tactics for matching expressions with leading Π
or λ binders, similar to Core's mk_local_pis. They all iterate over an
expression, processing one leading binder at a time. The bound variable is
replaced by either a fresh local constant or a fresh metavariable in the binder
body, 'opening' the binder. We then recurse into this new body. This scheme is
implemented by tactic.open_binders and tactic.open_n_binders.
Based on these general tactics, we define many variations of this recipe:
-
open_pisopens all leading Π binders and replaces them with fresh local constants. This is defined in core. -
open_lambdasopens leading λ binders instead. Example:open_lambdas `(λ (x : X) (y : Y), f x y) = ([`(_fresh.1), `(_fresh.2)], `(f _fresh.1 _fresh.2))_fresh.1and_fresh.2are fresh local constants (with typesXandY, respectively). The second component of the pair is the lambda body withxreplaced by_fresh.1andyreplaced by_fresh.2. -
open_pis_metasopens all leading Π binders and replaces them with fresh metavariables (instead of local constants). -
open_n_pisopens only the firstnleading Π binders and fails if there are not at leastnleading binders. Example:open_n_pis `(Π (x : X) (y : Y), P x y) 1 = ([`(_fresh.1)], `(Π (y : Y), P _fresh.1 y)) -
open_lambdas_whnfnormalises the input expression each time before trying to match a binder. Example:open_lambdas_whnf `(let f := λ (x : X), g x y in f) = ([`(_fresh.1)], `(g _fresh.1 y)) -
Any combination of these features is also provided, e.g.
open_n_lambdas_metas_whnfto opennλ binders up to normalisation, replacing them with fresh metavariables.
The open_* functions are commonly used like this:
- Open (some of) the binders of an expression
e, producing local constantslcsand the 'body'e'ofe. - Process
e'in some way. - Reconstruct the binders using
tactic.pisortactic.lambdas, which Π/λ-bind thelcsine'. This reverts the effect ofopen_*.
Special-purpose tactics #
The following tactics are variations of the 'opening binders' theme that do not quite fit in the above scheme.