dec_agree.v 1.94 KB
Newer Older
1
From iris.algebra Require Export cmra.
2 3 4
Local Arguments validN _ _ _ !_ /.
Local Arguments valid _ _  !_ /.
Local Arguments op _ _ _ !_ /.
Ralf Jung's avatar
Ralf Jung committed
5
Local Arguments core _ _ !_ /.
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 28

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.
Instance dec_agree_equiv : Equiv (dec_agree A) := equivL.
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.
Ralf Jung's avatar
Ralf Jung committed
29
Instance dec_agree_core : Core (dec_agree A) := id.
30 31 32 33 34 35 36

Definition dec_agree_ra : RA (dec_agree A).
Proof.
  split.
  - apply _.
  - apply _.
  - apply _.
Robbert Krebbers's avatar
Robbert Krebbers committed
37 38 39 40 41 42
  - intros [?|] [?|] [?|]; by repeat (simplify_eq/= || case_match).
  - intros [?|] [?|]; by repeat (simplify_eq/= || case_match).
  - intros [?|]; by repeat (simplify_eq/= || case_match).
  - intros [?|]; by repeat (simplify_eq/= || case_match).
  - by intros [?|] [?|] ?.
  - by intros [?|] [?|] ?.
43 44
Qed.

45
Canonical Structure dec_agreeR : cmraT := discreteR dec_agree_ra.
Ralf Jung's avatar
...  
Ralf Jung committed
46

Ralf Jung's avatar
Ralf Jung committed
47
(* Some properties of this CMRA *)
48 49
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
50

51 52 53 54
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
55
Proof. destruct x1, x2; by repeat (simplify_eq/= || case_match). Qed.
Ralf Jung's avatar
Ralf Jung committed
56
End dec_agree.
57

58
Arguments dec_agreeR _ {_}.