Debian Codegraph @

clib/store.ml

raw symbols SCIP
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 (** This module implements an "untyped store", in this particular case
12 we see it as an extensible record whose fields are left
13 unspecified. ***)
14
15 (** We use a dynamic "name" allocator. But if we needed to serialise
16 stores, we might want something static to avoid troubles with
17 plugins order. *)
18
19 module type S =
20 sig
21 type t
22 type 'a field
23 val field : string -> 'a field
24 val empty : t
25 val set : t -> 'a field -> 'a -> t
26 val get : t -> 'a field -> 'a option
27 val remove : t -> 'a field -> t
28 val merge : t -> t -> t
29 end
30
31 module Make() : S =
32 struct
33 module Dyn = Dyn.Make()
34 module Map = Dyn.Map(struct type 'a t = 'a end)
35
36 type t = Map.t
37 type 'a field = 'a Dyn.tag
38
39 let field = Dyn.create
40
41 let empty =
42 Map.empty
43 let set s f v =
44 Map.add f v s
45 let get s f =
46 try Some (Map.find f s)
47 with Not_found -> None
48 let remove s f =
49 Map.remove f s
50 let merge s1 s2 =
51 Map.fold (fun (Map.Any (f, v)) s -> Map.add f v s) s1 s2
52 end