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_pis
opens all leading Π binders and replaces them with fresh local constants. This is defined in core. -
open_lambdas
opens leading λ binders instead. Example:open_lambdas `(λ (x : X) (y : Y), f x y) = ([`(_fresh.1), `(_fresh.2)], `(f _fresh.1 _fresh.2))
_fresh.1
and_fresh.2
are fresh local constants (with typesX
andY
, respectively). The second component of the pair is the lambda body withx
replaced by_fresh.1
andy
replaced by_fresh.2
. -
open_pis_metas
opens all leading Π binders and replaces them with fresh metavariables (instead of local constants). -
open_n_pis
opens only the firstn
leading Π binders and fails if there are not at leastn
leading binders. Example:open_n_pis `(Π (x : X) (y : Y), P x y) 1 = ([`(_fresh.1)], `(Π (y : Y), P _fresh.1 y))
-
open_lambdas_whnf
normalises 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_whnf
to 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 constantslcs
and the 'body'e'
ofe
. - Process
e'
in some way. - Reconstruct the binders using
tactic.pis
ortactic.lambdas
, which Π/λ-bind thelcs
ine'
. 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.