Debian Codegraph @

clib/dyn.mli

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 (** Dynamically typed values *)
12
13 module type ValueS =
14 sig
15 type 'a t
16 end
17
18 module type MapS =
19 sig
20 type t
21 type 'a key
22 type 'a value
23 val empty : t
24 val add : 'a key -> 'a value -> t -> t
25 val remove : 'a key -> t -> t
26 val find : 'a key -> t -> 'a value
27 val mem : 'a key -> t -> bool
28 val modify : 'a key -> ('a value -> 'a value) -> t -> t
29
30 type map = { map : 'a. 'a key -> 'a value -> 'a value }
31 val map : map -> t -> t
32
33 type any = Any : 'a key * 'a value -> any
34 val iter : (any -> unit) -> t -> unit
35 val fold : (any -> 'r -> 'r) -> t -> 'r -> 'r
36
37 type filter = { filter : 'a. 'a key -> 'a value -> bool }
38 val filter : filter -> t -> t
39 end
40
41 module type S =
42 sig
43 type 'a tag
44 (** Type of dynamic tags *)
45
46 type t = Dyn : 'a tag * 'a -> t
47 (** Type of dynamic values *)
48
49 val create : string -> 'a tag
50 (** [create n] returns a tag describing a type called [n].
51 [create] raises an exception if [n] is already registered.
52 Type names are hashed, so [create] may raise even if no type with
53 the exact same name was registered due to a collision. *)
54
55 val eq : 'a tag -> 'b tag -> ('a, 'b) CSig.eq option
56 (** [eq t1 t2] returns [Some witness] if [t1] is the same as [t2], [None] otherwise. *)
57
58 val repr : 'a tag -> string
59 (** [repr tag] returns the name of the type represented by [tag]. *)
60
61 val dump : unit -> (int * string) list
62 (** [dump ()] returns a list of (tag, name) pairs for every type tag registered
63 in this [Dyn.Make] instance. *)
64
65 type any = Any : 'a tag -> any
66 (** Type of boxed dynamic tags *)
67
68 val name : string -> any option
69 (** [name n] returns [Some t] where t is a boxed tag previously registered
70 with [create n], or [None] if there is no such tag. *)
71
72 module Map(Value : ValueS) :
73 MapS with type 'a key = 'a tag and type 'a value = 'a Value.t
74 (** Map from type tags to values parameterized by the tag type *)
75
76 module HMap (V1 : ValueS)(V2 : ValueS) :
77 sig
78 type map = { map : 'a. 'a tag -> 'a V1.t -> 'a V2.t }
79 val map : map -> Map(V1).t -> Map(V2).t
80
81 type filter = { filter : 'a. 'a tag -> 'a V1.t -> bool }
82 val filter : filter -> Map(V1).t -> Map(V1).t
83 end
84
85 module Easy : sig
86 (* To create a dynamic type on the fly *)
87 val make_dyn_tag : string -> ('a -> t) * (t -> 'a) * 'a tag
88 val make_dyn : string -> ('a -> t) * (t -> 'a)
89
90 (* For types declared with the [create] function above *)
91 val inj : 'a -> 'a tag -> t
92 val prj : t -> 'a tag -> 'a option
93 end
94 end
95
96 module Make () : S