2010-06-15 10:49:03 +02:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Heptagon *)
|
|
|
|
(* *)
|
|
|
|
(* Author : Marc Pouzet *)
|
|
|
|
(* Organization : Demons, LRI, University of Paris-Sud, Orsay *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
|
|
|
|
|
|
|
(* Misc. functions *)
|
|
|
|
val optional : ('a -> 'b) -> 'a option -> 'b option
|
2010-07-08 17:41:00 +02:00
|
|
|
(** Optional with accumulator *)
|
|
|
|
val optional_wacc : ('a -> 'b -> 'c*'a) -> 'a -> 'b option -> ('c option * 'a)
|
2010-06-15 10:49:03 +02:00
|
|
|
val optunit : ('a -> unit) -> 'a option -> unit
|
2011-01-07 17:16:50 +01:00
|
|
|
|
2011-04-29 14:13:54 +02:00
|
|
|
(** [split_string s c] splits the string [s] according to the separator
|
|
|
|
[c] into a list of string without [c] *)
|
2011-01-07 17:16:50 +01:00
|
|
|
val split_string : string -> string -> string list
|
2010-06-15 10:49:03 +02:00
|
|
|
|
|
|
|
(* Generation of unique names. Mandatory call of reset_symbol between
|
|
|
|
set_min_symbol and gen_symbol *)
|
|
|
|
(*val set_min_symbol : int -> unit*)
|
|
|
|
val gen_symbol : unit -> string
|
|
|
|
val reset_symbol : unit -> unit
|
|
|
|
|
|
|
|
(** [unique l] returns the [l] list without duplicates. O([length l]). *)
|
|
|
|
val unique : 'a list -> 'a list
|
|
|
|
|
2010-12-14 18:31:09 +01:00
|
|
|
(** [map_butlast f l] applies f to all the elements of
|
|
|
|
l except the last element. *)
|
|
|
|
val map_butlast : ('a -> 'a) -> 'a list -> 'a list
|
2010-06-15 10:49:03 +02:00
|
|
|
|
2011-06-27 10:58:14 +02:00
|
|
|
(** [map_butnlast f l] applies f to all the elements of
|
|
|
|
l except the n last element. *)
|
|
|
|
val map_butnlast : int -> ('a -> 'a) -> 'a list -> 'a list
|
|
|
|
|
2010-06-15 10:49:03 +02:00
|
|
|
(** [last_element l] returns the last element of the list l.*)
|
2010-06-26 16:53:25 +02:00
|
|
|
val last_element : 'a list -> 'a
|
2010-06-15 10:49:03 +02:00
|
|
|
|
2010-06-26 16:53:25 +02:00
|
|
|
(** [split_last l] returns the list l without its last element
|
2010-06-15 10:49:03 +02:00
|
|
|
and the last element of the list .*)
|
2010-06-26 16:53:25 +02:00
|
|
|
val split_last : 'a list -> ('a list * 'a)
|
2010-06-15 10:49:03 +02:00
|
|
|
|
2011-06-27 10:58:14 +02:00
|
|
|
(** [split_nlast l] returns the list l without its n last elements
|
|
|
|
and the last element of the list .*)
|
|
|
|
val split_nlast : int -> 'a list -> ('a list * 'a list)
|
|
|
|
|
2011-03-21 17:22:03 +01:00
|
|
|
exception List_too_short
|
2011-06-30 17:41:25 +02:00
|
|
|
(** [split_at n l] splits [l] in two after the [n]th value (starting at 0).
|
2011-03-21 17:22:03 +01:00
|
|
|
Raises List_too_short exception if the list is too short. *)
|
|
|
|
val split_at : int -> 'a list -> 'a list * 'a list
|
|
|
|
|
2011-07-04 11:25:01 +02:00
|
|
|
(** [take n l] returns the [n] first elements of the list [l] *)
|
|
|
|
val take : int -> 'a list -> 'a list
|
|
|
|
|
2010-06-15 10:49:03 +02:00
|
|
|
(** [remove x l] removes all occurrences of x from list l.*)
|
|
|
|
val remove : 'a -> 'a list -> 'a list
|
|
|
|
|
|
|
|
(** [is_empty l] returns whether the list l is empty.*)
|
|
|
|
val is_empty : 'a list -> bool
|
|
|
|
|
|
|
|
(** [repeat_list v n] returns a list with n times the value v. *)
|
|
|
|
val repeat_list : 'a -> int -> 'a list
|
|
|
|
|
|
|
|
(** Same as List.mem_assoc but using the value instead of the key. *)
|
|
|
|
val memd_assoc : 'b -> ('a * 'b) list -> bool
|
|
|
|
|
|
|
|
(** Same as List.assoc but searching for a data and returning the key. *)
|
2010-08-24 11:07:05 +02:00
|
|
|
val assocd : 'b -> ('a * 'b) list -> 'a
|
|
|
|
|
2010-09-30 19:24:41 +02:00
|
|
|
(** [list_compare c l1 l2] compares the lists [l1] and [l2] according to
|
|
|
|
lexicographical order induced by [c]. *)
|
|
|
|
val list_compare : ('a -> 'a -> int) -> 'a list -> 'a list -> int
|
|
|
|
|
|
|
|
val option_compare : ('a -> 'a -> int) -> 'a option -> 'a option -> int
|
2010-08-24 11:07:05 +02:00
|
|
|
|
2011-09-07 17:27:58 +02:00
|
|
|
(** [list_diff l dl] returns [l] without the elements belonging to [dl].*)
|
|
|
|
val list_diff : 'a list -> 'a list -> 'a list
|
|
|
|
|
2010-07-07 15:11:32 +02:00
|
|
|
(** Mapfold *)
|
2011-04-29 14:13:54 +02:00
|
|
|
val mapfold: ('acc -> 'b -> 'c * 'acc) -> 'acc -> 'b list -> 'c list * 'acc
|
2011-05-02 10:12:42 +02:00
|
|
|
val mapfold2: ('acc -> 'b -> 'd -> 'c * 'acc) -> 'acc -> 'b list -> 'd list -> 'c list * 'acc
|
2010-07-09 15:28:26 +02:00
|
|
|
|
2010-07-19 17:19:02 +02:00
|
|
|
(** Mapfold, right version. *)
|
|
|
|
val mapfold_right
|
|
|
|
: ('a -> 'acc -> 'acc * 'b) -> 'a list -> 'acc -> 'acc * 'b list
|
|
|
|
|
2011-06-30 17:41:25 +02:00
|
|
|
(** [fold_right_1 f [x1; x2; ...; xn]] = f x1 (f x2 (f ... xn)). The list should
|
|
|
|
have at least one element! *)
|
|
|
|
val fold_right_1 :
|
|
|
|
('a -> 'a -> 'a) -> 'a list -> 'a
|
|
|
|
|
2011-07-04 11:25:01 +02:00
|
|
|
(** [fold_left_1 f [x1; x2; ...; xn]] = f (f ... (f x1 x2) ...) xn. The list should
|
|
|
|
have at least one element! *)
|
|
|
|
val fold_left_1 :
|
|
|
|
('a -> 'a -> 'a) -> 'a list -> 'a
|
|
|
|
|
2011-07-05 17:42:31 +02:00
|
|
|
(** [fold_left4] is fold_left with four lists *)
|
|
|
|
val fold_left4 :
|
|
|
|
('a -> 'b -> 'c -> 'd -> 'e -> 'a) -> 'a -> 'b list -> 'c list -> 'd list -> 'e list -> 'a
|
|
|
|
|
2010-07-09 15:28:26 +02:00
|
|
|
(** Mapi *)
|
2011-09-07 17:27:58 +02:00
|
|
|
val map3: ('a -> 'b -> 'c -> 'd) ->
|
|
|
|
'a list -> 'b list -> 'c list -> 'd list
|
2010-07-09 15:28:26 +02:00
|
|
|
val mapi: (int -> 'a -> 'b) -> 'a list -> 'b list
|
|
|
|
val mapi2: (int -> 'a -> 'b -> 'c) -> 'a list -> 'b list -> 'c list
|
|
|
|
val mapi3: (int -> 'a -> 'b -> 'c -> 'd) ->
|
|
|
|
'a list -> 'b list -> 'c list -> 'd list
|
2010-09-30 19:24:41 +02:00
|
|
|
val fold_righti : (int -> 'a -> 'b -> 'b) -> 'a list -> 'b -> 'b
|
2010-09-09 00:35:06 +02:00
|
|
|
|
2011-04-20 15:41:15 +02:00
|
|
|
(** [iter_couple f l] calls f for all x and y distinct in [l]. *)
|
|
|
|
val iter_couple : ('a -> 'a -> unit) -> 'a list -> unit
|
|
|
|
(** [iter_couple_2 f l1 l2] calls f for all x in [l1] and y in [l2]. *)
|
|
|
|
val iter_couple_2 : ('a -> 'a -> unit) -> 'a list -> 'a list -> unit
|
2011-04-26 18:02:18 +02:00
|
|
|
(** [index p l] returns the idx of the first element in l
|
|
|
|
that satisfies predicate p.*)
|
|
|
|
val index : ('a -> bool) -> 'a list -> int
|
2011-04-20 15:41:15 +02:00
|
|
|
|
2010-09-13 13:32:35 +02:00
|
|
|
(** Functions to decompose a list into a tuple *)
|
|
|
|
val assert_empty : 'a list -> unit
|
|
|
|
val assert_1 : 'a list -> 'a
|
2010-09-13 16:02:33 +02:00
|
|
|
val assert_1min : 'a list -> 'a * 'a list
|
2010-09-13 13:32:35 +02:00
|
|
|
val assert_2 : 'a list -> 'a * 'a
|
|
|
|
val assert_2min : 'a list -> 'a * 'a * 'a list
|
|
|
|
val assert_3 : 'a list -> 'a * 'a * 'a
|
2010-12-14 18:29:55 +01:00
|
|
|
|
|
|
|
(** Print to string *)
|
|
|
|
val print_pp_to_string : (Format.formatter -> 'a -> unit) -> 'a -> string
|
|
|
|
|
|
|
|
(** Replace all non [a-z A-Z 0-9] character of a string by [_] *)
|
|
|
|
val sanitize_string : string -> string
|
|
|
|
|
2011-01-07 17:16:50 +01:00
|
|
|
(** Pipe a value to a function *)
|
|
|
|
val (|>) : 'a -> ('a -> 'b) -> 'b
|
|
|
|
|
|
|
|
(** Return the extension of a filename string *)
|
|
|
|
val file_extension : string -> string
|
2011-01-24 16:07:26 +01:00
|
|
|
|
|
|
|
(** Internal error : Is used when an assertion wrong *)
|
2011-05-23 09:24:57 +02:00
|
|
|
val internal_error : string -> 'a
|
2011-01-24 16:07:26 +01:00
|
|
|
|
|
|
|
(** Unsupported : Is used when something should work but is not currently supported *)
|
2011-05-23 09:24:57 +02:00
|
|
|
val unsupported : string -> 'a
|
2011-04-20 15:41:15 +02:00
|
|
|
|
|
|
|
(** Memoize the result of the function [f]*)
|
|
|
|
val memoize : ('a -> 'b) -> ('a -> 'b)
|
|
|
|
|
|
|
|
(** Memoize the result of the function [f], taht should expect a
|
|
|
|
tuple as input and be reflexive (f (x,y) = f (y,x)) *)
|
|
|
|
val memoize_couple : (('a * 'a) -> 'b) -> (('a * 'a) -> 'b)
|