-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMonotonicCounter.v
27 lines (20 loc) · 966 Bytes
/
MonotonicCounter.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Require Import Coq.Arith.Arith.
Require Import RGref.DSL.DSL.
(** * A Monotonic Counter
A monotonically increasing counter.*)
Definition increasing : hrel nat :=
(fun n => fun n' => fun _ => fun _ => n <= n').
Hint Unfold increasing.
(** We'll give the Program extension some hints for this module *)
Local Obligation Tactic := intros; eauto with arith; compute; eauto with arith.
(** Now the definition of a verified monotonically increasing counter is
barely more work than a completely unchecked counter. *)
Program Definition monotonic_counter := ref nat any increasing increasing.
Program Definition read_counter (c:monotonic_counter) : nat := !c.
Program Definition inc_monotonic { Γ } (p:monotonic_counter) : rgref Γ unit Γ :=
[p]:= !p + 1.
Program Definition mkCounter { Γ } (u:unit) : rgref Γ monotonic_counter Γ :=
Alloc 0.
Program Example test_counter { Γ } (u:unit) : rgref Γ unit Γ :=
x <- mkCounter tt;
inc_monotonic x.