diff --git a/CHANGELOG.md b/CHANGELOG.md index a604255c99d28516e1c3be1a0e2e1f579e5d7e0d..9fbaaccf662a919813f392543d95b707a3d69a83 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,8 @@ Coq 8.19 is newly supported by this version of std++. to refer to a hypothesis on the goal (`inv 1`). - Add `prod_swap : A * B → B * A` and some basic theory about it. - Add lemma `join_app`. +- Allow patterns and type annotations in propset notation, e.g. + `{[ (x, y) : nat * nat | x = y ]}` The following `sed` script should perform most of the renaming (on macOS, replace `sed` by `gsed`, installed via e.g. `brew install gnu-sed`). diff --git a/stdpp/propset.v b/stdpp/propset.v index 1ed3af52c216d25065133279d39c7b2481216f68..7a220edc8b008ad18e199a4d4c67c30375901bd4 100644 --- a/stdpp/propset.v +++ b/stdpp/propset.v @@ -6,8 +6,13 @@ Record propset (A : Type) : Type := PropSet { propset_car : A → Prop }. Add Printing Constructor propset. Global Arguments PropSet {_} _ : assert. Global Arguments propset_car {_} _ _ : assert. +(** Here we are using the notation "at level 200 as pattern" because we want to + be compatible with all the rules that start with [ {[ TERM ] such as + records, singletons, and map singletons. See + https://coq.inria.fr/refman/user-extensions/syntax-extensions.html#binders-bound-in-the-notation-and-parsed-as-terms + and https://gitlab.mpi-sws.org/iris/stdpp/-/merge_requests/533#note_98003 *) Notation "{[ x | P ]}" := (PropSet (λ x, P)) - (at level 1, format "{[ x | P ]}") : stdpp_scope. + (at level 1, x at level 200 as pattern, format "{[ x | P ]}") : stdpp_scope. Global Instance propset_elem_of {A} : ElemOf A (propset A) := λ x X, propset_car X x. diff --git a/tests/propset.ref b/tests/propset.ref new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/tests/propset.v b/tests/propset.v new file mode 100644 index 0000000000000000000000000000000000000000..6d356cbcca5f05e7b8a9800129303db129bca0ca --- /dev/null +++ b/tests/propset.v @@ -0,0 +1,20 @@ +From stdpp Require Import propset. + +Lemma diagonal : {[ (a,b) : nat * nat | a = b ]} ≡ (λ x, (x,x)) <$> ⊤. +Proof. set_unfold. intros []. naive_solver. Qed. + +Lemma diagonal2 : {[ (a,b) | a =@{nat} b ]} ≡ {[ x | x.1 = x.2 ]}. +Proof. set_unfold. intros []. naive_solver. Qed. + +Lemma firstis42 : {[ (x, _) : nat * nat | x = 42 ]} ≡ (42,.) <$> ⊤. +Proof. set_unfold. intros []. naive_solver. Qed. + +Inductive foo := Foo (n : nat). + +Definition set_of_positive_foos : {[ Foo x | x ≠0 ]} ≡ Foo <$> (Pos.to_nat <$> ⊤). +Proof. + set_unfold. intros [[]]; naive_solver by (rewrite SuccNat2Pos.id_succ || lia). +Qed. + +Lemma simple_pattern_does_not_match : {[ x : nat | x = x]} = PropSet (λ x, x = x). +Proof. exact eq_refl. Qed.