Merge branch 'upgrade_proofs_coq_8_11_to_8_16' into 'master'
[why3.git] / stdlib / ref.mlw
blob18bfbe491a9377d7ca1fd6c1cff68e5d73c44baa
2 (** {1 References}
4    A mutable variable, or "reference" in ML terminology, is simply a
5    record with a single mutable field `contents`.
6 *)
8 (** {2 Generic references}
10    Creation, access, and assignment are provided as `ref`, prefix `!`, and
11    infix `:=`, respectively.
14 module Ref
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
22 end
24 (** {2 Integer References}
26 A few operations specific to integer references. *)
28 module Refint
30   use int.Int
31   use export Ref
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
40 end