package / ocaml-base-compiler.4.10.0 / utils / identifiable.mli
1 (**************************************************************************)
2 (* *)
3 (* OCaml *)
4 (* *)
5 (* Pierre Chambart, OCamlPro *)
6 (* Mark Shinwell and Leo White, Jane Street Europe *)
7 (* *)
8 (* Copyright 2013--2016 OCamlPro SAS *)
9 (* Copyright 2014--2016 Jane Street Group LLC *)
10 (* *)
11 (* All rights reserved. This file is distributed under the terms of *)
12 (* the GNU Lesser General Public License version 2.1, with the *)
13 (* special exception on linking described in the file LICENSE. *)
14 (* *)
15 (**************************************************************************)
16
17 (** Uniform interface for common data structures over various things.
18
19 {b Warning:} this module is unstable and part of
20 {{!Compiler_libs}compiler-libs}.
21
22 *)
23
24 module type Thing = sig
25 type t
26
27 include Hashtbl.HashedType with type t := t
28 include Map.OrderedType with type t := t
29
30 val output : out_channel -> t -> unit
31 val print : Format.formatter -> t -> unit
32 end
33
34 module Pair : functor (A : Thing) (B : Thing) -> Thing with type t = A.t * B.t
35
36 module type Set = sig
37 module T : Set.OrderedType
38 include Set.S
39 with type elt = T.t
40 and type t = Set.Make (T).t
41
42 val output : out_channel -> t -> unit
43 val print : Format.formatter -> t -> unit
44 val to_string : t -> string
45 val of_list : elt list -> t
46 val map : (elt -> elt) -> t -> t
47 end
48
49 module type Map = sig
50 module T : Map.OrderedType
51 include Map.S
52 with type key = T.t
53 and type 'a t = 'a Map.Make (T).t
54
55 val filter_map : 'a t -> f:(key -> 'a -> 'b option) -> 'b t
56 val of_list : (key * 'a) list -> 'a t
57
58 (** [disjoint_union m1 m2] contains all bindings from [m1] and
59 [m2]. If some binding is present in both and the associated
60 value is not equal, a Fatal_error is raised *)
61 val disjoint_union :
62 ?eq:('a -> 'a -> bool) -> ?print:(Format.formatter -> 'a -> unit) -> 'a t ->
63 'a t -> 'a t
64
65 (** [union_right m1 m2] contains all bindings from [m1] and [m2]. If
66 some binding is present in both, the one from [m2] is taken *)
67 val union_right : 'a t -> 'a t -> 'a t
68
69 (** [union_left m1 m2 = union_right m2 m1] *)
70 val union_left : 'a t -> 'a t -> 'a t
71
72 val union_merge : ('a -> 'a -> 'a) -> 'a t -> 'a t -> 'a t
73 val rename : key t -> key -> key
74 val map_keys : (key -> key) -> 'a t -> 'a t
75 val keys : 'a t -> Set.Make(T).t
76 val data : 'a t -> 'a list
77 val of_set : (key -> 'a) -> Set.Make(T).t -> 'a t
78 val transpose_keys_and_data : key t -> key t
79 val transpose_keys_and_data_set : key t -> Set.Make(T).t t
80 val print :
81 (Format.formatter -> 'a -> unit) -> Format.formatter -> 'a t -> unit
82 end
83
84 module type Tbl = sig
85 module T : sig
86 type t
87 include Map.OrderedType with type t := t
88 include Hashtbl.HashedType with type t := t
89 end
90 include Hashtbl.S
91 with type key = T.t
92 and type 'a t = 'a Hashtbl.Make (T).t
93
94 val to_list : 'a t -> (T.t * 'a) list
95 val of_list : (T.t * 'a) list -> 'a t
96
97 val to_map : 'a t -> 'a Map.Make(T).t
98 val of_map : 'a Map.Make(T).t -> 'a t
99 val memoize : 'a t -> (key -> 'a) -> key -> 'a
100 val map : 'a t -> ('a -> 'b) -> 'b t
101 end
102
103 module type S = sig
104 type t
105
106 module T : Thing with type t = t
107 include Thing with type t := T.t
108
109 module Set : Set with module T := T
110 module Map : Map with module T := T
111 module Tbl : Tbl with module T := T
112 end
113
114 module Make (T : Thing) : S with type t := T.t
115