4 A mutable variable, or "reference" in ML terminology, is simply a
5 record with a single mutable field `contents`.
8 (** {2 Generic references}
10 Creation, access, and assignment are provided as `ref`, prefix `!`, and
11 infix `:=`, respectively.
16 use export why3.Ref.Ref
18 let function (!) (r: ref 'a) = r.contents
20 let (:=) (ref r:'a) (v:'a) ensures { r = v } = r <- v
24 (** {2 Integer References}
26 A few operations specific to integer references. *)
33 let incr (ref r: int) ensures { r = old r + 1 } = r <- r + 1
34 let decr (ref r: int) ensures { r = old r - 1 } = r <- r - 1
36 let (+=) (ref r: int) (v: int) ensures { r = old r + v } = r <- r + v
37 let (-=) (ref r: int) (v: int) ensures { r = old r - v } = r <- r - v
38 let ( *= ) (ref r: int) (v: int) ensures { r = old r * v } = r <- r * v