Debian Codegraph @

theories/Ltac2/Ref.v

raw
1 (************************************************************************)
2 (* * The Rocq Prover / The Rocq Development Team *)
3 (* v * Copyright INRIA, CNRS and contributors *)
4 (* <O___,, * (see version control and CREDITS file for authors & dates) *)
5 (* \VV/ **************************************************************)
6 (* // * This file is distributed under the terms of the *)
7 (* * GNU Lesser General Public License Version 2.1 *)
8 (* * (see LICENSE file for the text of the license) *)
9 (************************************************************************)
10
11 Require Import Ltac2.Init.
12 Require Import Ltac2.Int.
13
14 (** Type of a reference cell, similar to OCaml's ['a ref] type. *)
15 Ltac2 Type 'a ref := 'a Init.ref.
16
17 Ltac2 ref (v : 'a) : 'a ref := { contents := v}.
18 Ltac2 get (r : 'a ref) : 'a := r.(contents).
19 Ltac2 set (r : 'a ref) (v : 'a) : unit := r.(contents) := v.
20
21 Ltac2 incr (r : int ref) : unit := r.(contents) := add (r.(contents)) 1.
22 Ltac2 decr (r : int ref) : unit := r.(contents) := sub (r.(contents)) 1.
23
24 Ltac2 update (r : 'a ref) (f : 'a -> 'a) : unit :=
25 r.(contents) := f (r.(contents)).