dec_agree.v 2.09 KB
Newer Older
1
From iris.algebra Require Export cmra.
2 3 4
Local Arguments validN _ _ _ !_ /.
Local Arguments valid _ _  !_ /.
Local Arguments op _ _ _ !_ /.
Robbert Krebbers's avatar
Robbert Krebbers committed
5
Local Arguments pcore _ _ !_ /.
6

Robbert Krebbers's avatar
Robbert Krebbers committed
7
(* This is isomorphic to option, but has a very different RA structure. *)
8 9 10 11 12
Inductive dec_agree (A : Type) : Type := 
  | DecAgree : A  dec_agree A
  | DecAgreeBot : dec_agree A.
Arguments DecAgree {_} _.
Arguments DecAgreeBot {_}.
Robbert Krebbers's avatar
Robbert Krebbers committed
13 14
Instance maybe_DecAgree {A} : Maybe (@DecAgree A) := λ x,
  match x with DecAgree a => Some a | _ => None end.
15 16 17 18 19 20 21 22 23 24 25 26 27

Section dec_agree.
Context {A : Type} `{ x y : A, Decision (x = y)}.

Instance dec_agree_valid : Valid (dec_agree A) := λ x,
  if x is DecAgree _ then True else False.
Canonical Structure dec_agreeC : cofeT := leibnizC (dec_agree A).

Instance dec_agree_op : Op (dec_agree A) := λ x y,
  match x, y with
  | DecAgree a, DecAgree b => if decide (a = b) then DecAgree a else DecAgreeBot
  | _, _ => DecAgreeBot
  end.
Robbert Krebbers's avatar
Robbert Krebbers committed
28
Instance dec_agree_pcore : PCore (dec_agree A) := Some.
29

30
Definition dec_agree_ra_mixin : RAMixin (dec_agree A).
31 32 33
Proof.
  split.
  - apply _.
Robbert Krebbers's avatar
Robbert Krebbers committed
34
  - intros x y cx ? [=<-]; eauto.
35
  - apply _.
Robbert Krebbers's avatar
Robbert Krebbers committed
36 37
  - intros [?|] [?|] [?|]; by repeat (simplify_eq/= || case_match).
  - intros [?|] [?|]; by repeat (simplify_eq/= || case_match).
Robbert Krebbers's avatar
Robbert Krebbers committed
38
  - intros [?|] ? [=<-]; by repeat (simplify_eq/= || case_match).
Robbert Krebbers's avatar
Robbert Krebbers committed
39
  - intros [?|]; by repeat (simplify_eq/= || case_match).
Robbert Krebbers's avatar
Robbert Krebbers committed
40
  - intros [?|] [?|] ?? [=<-]; eauto.
Robbert Krebbers's avatar
Robbert Krebbers committed
41
  - by intros [?|] [?|] ?.
42 43
Qed.

44 45
Canonical Structure dec_agreeR : cmraT :=
  discreteR (dec_agree A) dec_agree_ra_mixin.
Ralf Jung's avatar
...  
Ralf Jung committed
46

Ralf Jung's avatar
Ralf Jung committed
47
(* Some properties of this CMRA *)
48
Global Instance dec_agree_persistent (x : dec_agreeR) : Persistent x.
Robbert Krebbers's avatar
Robbert Krebbers committed
49
Proof. by constructor. Qed.
50

51 52
Lemma dec_agree_ne a b : a  b  DecAgree a  DecAgree b = DecAgreeBot.
Proof. intros. by rewrite /= decide_False. Qed.
Ralf Jung's avatar
Ralf Jung committed
53

54 55 56 57
Lemma dec_agree_idemp (x : dec_agree A) : x  x = x.
Proof. destruct x; by rewrite /= ?decide_True. Qed.

Lemma dec_agree_op_inv (x1 x2 : dec_agree A) :  (x1  x2)  x1 = x2.
Robbert Krebbers's avatar
Robbert Krebbers committed
58
Proof. destruct x1, x2; by repeat (simplify_eq/= || case_match). Qed.
Ralf Jung's avatar
Ralf Jung committed
59
End dec_agree.
60

61
Arguments dec_agreeC : clear implicits.
62
Arguments dec_agreeR _ {_}.