]> matita.cs.unibo.it Git - pkg-cerco/acc.git/blob - src/utilities/misc.mli
first version of the package
[pkg-cerco/acc.git] / src / utilities / misc.mli
1 (** This module extends the standard library of Objective Caml. *)
2
3 module LexingExt : sig
4
5   (** [new_line lexbuf] update lexbuf to increment its line 
6       counter. *)
7   val new_line : Lexing.lexbuf -> unit
8
9   val lex_num : string -> int -> (int * int * int) option
10
11 end
12
13 module ListExt : sig
14
15   (** [inv_assoc l] inverses a bijective associative list [l]. *)
16   val inv_assoc : ('a * 'b) list -> ('b * 'a) list
17
18   exception EmptyList
19
20   (** [last l] returns the last element of a list. 
21       Raise [EmptyList] if there is no such thing in [l]. *)
22   val last : 'a list -> 'a
23
24   (** [cut_last l] returns the last element of a list [l] and the
25       elements that come before it in [l].
26       Raise [EmptyList] if there is no such thing in [l]. *)
27   val cut_last : 'a list -> 'a * 'a list
28
29   (** [multi_set_of_list l] returns an associative list that 
30       relates every element of [l] to its frequency in [l]. *)
31   val multi_set_of_list : 'a list -> ('a * int) list
32
33   (** [hashtbl_of_assoc l] converts an associative list into 
34       an hash table. *)
35   val hashtbl_of_assoc : ('a * 'b) list -> ('a, 'b) Hashtbl.t
36
37   (** [assoc_diff l1 l2] returns the difference between two
38       associative lists. *)
39   val assoc_diff : ('a * 'b) list -> ('a * 'b) list 
40     -> ('a * ('b option * 'b option)) list
41
42   (** [transitive_forall2 p l] checks that the binary predicate [p] is 
43       true between each successive elements of [l]. If this is false,
44       the function returns the first pair of elements that falsify [p]. *)
45   val transitive_forall2 : ('a -> 'a -> bool) -> 'a list -> ('a * 'a) option
46
47   (** [repeat init n f] computes [f 0; ...; f n] threading an
48       accumulator along the way from [n] to [0]. *)
49   val repeat : 'b -> int -> ('b -> int -> 'b * 'a) -> 'b * 'a list
50
51 end
52
53 module ArgExt : sig
54
55   (** [extra_doc s] adds an extra line of documentation for an
56       Arg.spec row. *)
57   val extra_doc : string -> (Arg.key * Arg.spec * Arg.doc)
58
59 end
60
61 module SysExt : sig
62
63   (** [safe_remove filename] deletes a file named [filename], 
64       but do not crash if a system error happens. (For instance,
65       if the file does not exist.) *)
66   val safe_remove : string -> unit
67
68   (** [alternative filename] finds an alternative name different
69       from [filename] that is not already used. *)
70   val alternative : string -> string
71
72 end
73
74 module IOExt : sig
75
76   (** Buffered printf-based IO. *)
77   val printf  : ('a, Format.formatter, unit) Pervasives.format -> 'a
78   val eprintf : ('a, Format.formatter, unit) Pervasives.format -> 'a
79   val set_buffered_mode : unit -> unit
80   val get_buffers       : unit -> string * string
81
82 end
83
84 module Timed : sig
85
86   val time : 
87     (unit -> 'date) -> ('date -> 'date -> unit) 
88     -> ('a -> 'b) -> ('a -> 'b)
89
90   val set_now : (unit -> float) -> unit
91
92   val set_profiling_flag : bool -> unit
93
94   val profile : string -> ('a -> 'b) -> 'a -> 'b
95
96 end