Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

`context` expression in Coq

I am trying to understand 'context' expression (opposed to context pattern). In the manual it is described as:

context ident [ expr ]

ident must denote a context variable bound by a context pattern of a match expression. This expression evaluates replaces the hole of the value of ident by the value of expr.

Could somebody share an example illustrating the usage of this construct? I guess it must involve match using context pattern and then abovementioned form to use matched context.

like image 330
krokodil Avatar asked Oct 26 '25 10:10

krokodil


1 Answers

Here is an example that replaces fst (a, _) with a and snd (_, b) with b, but doesn't touch fst and snd applied to anything other than pair:

Ltac unfold_proj_pair :=
    repeat match goal with
           | [ |- context G[fst (?a, _)] ]
             => let G' := context G[a] in change G'
           | [ |- context G[snd (_, ?b)] ]
             => let G' := context G[b] in change G'
           end.

(Note that cbn [fst snd] is a simpler way to do this, and that also works under binders.)

like image 62
Jason Gross Avatar answered Oct 29 '25 06:10

Jason Gross



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!