| 1 |
From Corelib Require Export Morphisms Setoid . |
| 2 |
|
| 3 |
Class Equiv A := equiv: relation A. |
| 4 |
|
| 5 |
Infix "≡" := equiv (at level 70, no associativity). |
| 6 |
Infix "≡@{ A }" := (@equiv A _) |
| 7 |
(at level 70, only parsing, no associativity). |
| 8 |
|
| 9 |
Notation "(≡)" := equiv (only parsing). |
| 10 |
|
| 11 |
(** Unbundled version *) |
| 12 |
Class Dist A := dist : nat -> relation A. |
| 13 |
|
| 14 |
Notation "x ≡{ n }≡ y" := (dist n x y) |
| 15 |
(at level 70, n at next level, format "x ≡{ n }≡ y"). |
| 16 |
Notation "x ≡{ n }@{ A }≡ y" := (dist (A:=A) n x y) |
| 17 |
(at level 70, n at next level, only parsing). |
| 18 |
|
| 19 |
Notation NonExpansive f := (forall n, Proper (dist n ==> dist n ==> dist n) f). |
| 20 |
|
| 21 |
Record OfeMixin A `{Equiv A, Dist A} := { |
| 22 |
mixin_equiv_dist (x y : A) : x ≡ y <-> forall n, x ≡{n}≡ y; |
| 23 |
}. |
| 24 |
|
| 25 |
(** Bundled version *) |
| 26 |
Structure ofeT := OfeT { |
| 27 |
ofe_car :> Type; |
| 28 |
ofe_equiv : Equiv ofe_car; |
| 29 |
ofe_dist : Dist ofe_car; |
| 30 |
ofe_mixin : OfeMixin ofe_car |
| 31 |
}. |
| 32 |
#[export] Hint Extern 0 (Equiv _) => eapply (@ofe_equiv _) : typeclass_instances. |
| 33 |
#[export] Hint Extern 0 (Dist _) => eapply (@ofe_dist _) : typeclass_instances. |
| 34 |
|
| 35 |
(** Lifting properties from the mixin *) |
| 36 |
Section ofe_mixin. |
| 37 |
Context {A : ofeT}. |
| 38 |
Implicit Types x y : A. |
| 39 |
Lemma equiv_dist x y : x ≡ y <-> forall n, x ≡{n}≡ y. |
| 40 |
Proof. apply (mixin_equiv_dist _ (ofe_mixin A)). Qed. |
| 41 |
End ofe_mixin. |
| 42 |
|
| 43 |
Axiom _0 : Prop. (* dummy which somehow bothers mangle names *) |
| 44 |
Set Mangle Names. |
| 45 |
|
| 46 |
(** General properties *) |
| 47 |
Section ofe. |
| 48 |
Context {A : ofeT}. |
| 49 |
|
| 50 |
Lemma ne_proper_2 {B C : ofeT} (f : A -> B -> C) `{Hf:!NonExpansive f} : |
| 51 |
Proper ((≡) ==> (≡) ==> (≡)) f. |
| 52 |
Proof. |
| 53 |
unfold Proper, respectful. |
| 54 |
setoid_rewrite equiv_dist. |
| 55 |
intros. |
| 56 |
apply Hf;auto. |
| 57 |
Qed. |
| 58 |
End ofe. |