Debian Codegraph @

lib/util.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 (** This module contains numerous utility functions on strings, lists,
12 arrays, etc. *)
13
14 (** Mapping under pairs *)
15
16 val on_fst : ('a -> 'b) -> 'a * 'c -> 'b * 'c
17 val on_snd : ('a -> 'b) -> 'c * 'a -> 'c * 'b
18 val map_pair : ('a -> 'b) -> 'a * 'a -> 'b * 'b
19
20 (** Folding under pairs *)
21
22 val fold_fst : ('c -> 'a -> 'c * 'a) -> 'c -> 'a * 'b -> 'c * ('a * 'b)
23 val fold_snd : ('c -> 'b -> 'c * 'b) -> 'c -> 'a * 'b -> 'c * ('a * 'b)
24
25 (** Equality on pairs *)
26
27 val eq_pair : ('a -> 'a -> bool) -> ('b -> 'b -> bool) -> ('a * 'b -> 'a * 'b -> bool)
28
29 (** Mapping under triplets *)
30
31 val on_pi1 : ('a -> 'b) -> 'a * 'c * 'd -> 'b * 'c * 'd
32 val on_pi2 : ('a -> 'b) -> 'c * 'a * 'd -> 'c * 'b * 'd
33 val on_pi3 : ('a -> 'b) -> 'c * 'd * 'a -> 'c * 'd * 'b
34
35 (** {6 Projections from triplets } *)
36
37 val pi1 : 'a * 'b * 'c -> 'a
38 val pi2 : 'a * 'b * 'c -> 'b
39 val pi3 : 'a * 'b * 'c -> 'c
40
41 (** {6 Chars. } *)
42
43 val is_letter : char -> bool
44 val is_digit : char -> bool
45 val is_ident_tail : char -> bool
46 val is_blank : char -> bool
47
48 (** {6 Empty type} *)
49
50 module Empty :
51 sig
52 type t
53 val abort : t -> 'a
54 end
55
56 (** {6 Strings. } *)
57
58 module String = CString
59
60 (** Substitute %s in the first chain by the second chain *)
61 val subst_command_placeholder : string -> string -> string
62
63 (** {6 Lists. } *)
64
65 module List = CList
66
67 val (@) : 'a list -> 'a list -> 'a list
68
69 (** {6 Arrays. } *)
70
71 module Array = CArray
72
73 (** {6 Sets. } *)
74
75 module Set = CSet
76
77 (** {6 Maps. } *)
78
79 module Map = CMap
80
81 (** {6 Matrices. } *)
82
83 val matrix_transpose : 'a list list -> 'a list list
84
85 (** {6 Functions. } *)
86
87 val identity : 'a -> 'a
88
89 (** Left-to-right function composition:
90
91 [f1 %> f2] is [fun x -> f2 (f1 x)].
92
93 [f1 %> f2 %> f3] is [fun x -> f3 (f2 (f1 x))].
94
95 [f1 %> f2 %> f3 %> f4] is [fun x -> f4 (f3 (f2 (f1 x)))]
96
97 etc.
98 *)
99 val ( %> ) : ('a -> 'b) -> ('b -> 'c) -> 'a -> 'c
100
101 val const : 'a -> 'b -> 'a
102 val iterate : ('a -> 'a) -> int -> 'a -> 'a
103 val repeat : int -> ('a -> unit) -> 'a -> unit
104 val app_opt : ('a -> 'a) option -> 'a -> 'a
105
106 (** {6 Delayed computations. } *)
107
108 type 'a delayed = unit -> 'a
109
110 val delayed_force : 'a delayed -> 'a
111
112 (** [try_finally f x g y] applies the main code [f] to [x] and
113 returns the result after having applied the finalization
114 code [g] to [y]. If the main code raises the exception
115 [exn], the finalization code is executed and [exn] is raised.
116 If the finalization code itself fails, the exception
117 returned is always the one from the finalization code.
118 Credit X.Leroy, D.Remy. *)
119 val try_finally: ('a -> 'b) -> 'a -> ('c -> unit) -> 'c -> 'b
120
121 val protect_ref : scope:(unit -> 'a) -> 'b ref -> 'a
122
123 val protect_state : freeze:(unit -> 'st) -> unfreeze:('st ->unit) -> scope:(unit -> 'a) -> 'a
124
125 val atomify : ('a -> 'b) -> 'a -> 'b
126
127 (** {6 Misc. } *)
128
129 type ('a, 'b) union = ('a, 'b) CSig.union = Inl of 'a | Inr of 'b
130 (** Union type *)
131
132 module Union :
133 sig
134 val map : ('a -> 'c) -> ('b -> 'd) -> ('a, 'b) union -> ('c, 'd) union
135 val equal : ('a -> 'a -> bool) -> ('b -> 'b -> bool) -> ('a, 'b) union -> ('a, 'b) union -> bool
136 val fold_left : ('c -> 'a -> 'c) -> ('c -> 'b -> 'c) -> 'c -> ('a, 'b) union -> 'c
137 end
138
139 val map_union : ('a -> 'c) -> ('b -> 'd) -> ('a, 'b) union -> ('c, 'd) union
140 (** Alias for [Union.map] *)
141
142 type 'a until = 'a CSig.until = Stop of 'a | Cont of 'a
143 (** Used for browsable-until structures. *)
144
145 type ('a, 'b) eq = ('a, 'b) CSig.eq = Refl : ('a, 'a) eq
146
147 val sym : ('a, 'b) eq -> ('b, 'a) eq
148
149 (** Helpers to write comparison functions *)
150 module Compare : sig
151 type list = [] | (::) : (('a -> 'a -> int) * 'a * 'a) * list -> list
152
153 val compare : list -> int
154 (** Compare the elements in the order they are given using the
155 provided comparison function until the first non-zero result. *)
156 end
157
158 val open_utf8_file_in : string -> in_channel
159 (** Open an utf-8 encoded file and skip the byte-order mark if any. *)
160
161 val set_temporary_memory : unit -> ('a -> 'a) * (unit -> 'a)
162 (** A trick which can typically be used to store on the fly the
163 computation of values in the "when" clause of a "match" then
164 retrieve the evaluated result in the r.h.s of the clause *)