Module CList
module type ExtS = sig ... endinclude ExtS
include S
- val length : 'a list -> int
- val compare_lengths : 'a list -> 'b list -> int
- val compare_length_with : 'a list -> int -> int
- val cons : 'a -> 'a list -> 'a list
- val hd : 'a list -> 'a
- val tl : 'a list -> 'a list
- val nth : 'a list -> int -> 'a
- val nth_opt : 'a list -> int -> 'a option
- val rev : 'a list -> 'a list
- val init : int -> (int -> 'a) -> 'a list
- val append : 'a list -> 'a list -> 'a list
- val rev_append : 'a list -> 'a list -> 'a list
- val concat : 'a list list -> 'a list
- val flatten : 'a list list -> 'a list
- val equal : ('a -> 'a -> bool) -> 'a list -> 'a list -> bool
- val compare : ('a -> 'a -> int) -> 'a list -> 'a list -> int
- val iter : ('a -> unit) -> 'a list -> unit
- val iteri : (int -> 'a -> unit) -> 'a list -> unit
- val map : ('a -> 'b) -> 'a list -> 'b list
- val mapi : (int -> 'a -> 'b) -> 'a list -> 'b list
- val rev_map : ('a -> 'b) -> 'a list -> 'b list
- val filter_map : ('a -> 'b option) -> 'a list -> 'b list
- val concat_map : ('a -> 'b list) -> 'a list -> 'b list
- val fold_left_map : ('a -> 'b -> 'a * 'c) -> 'a -> 'b list -> 'a * 'c list
- val fold_left : ('a -> 'b -> 'a) -> 'a -> 'b list -> 'a
- val fold_right : ('a -> 'b -> 'b) -> 'a list -> 'b -> 'b
- val iter2 : ('a -> 'b -> unit) -> 'a list -> 'b list -> unit
- val map2 : ('a -> 'b -> 'c) -> 'a list -> 'b list -> 'c list
- val rev_map2 : ('a -> 'b -> 'c) -> 'a list -> 'b list -> 'c list
- val fold_left2 : ('a -> 'b -> 'c -> 'a) -> 'a -> 'b list -> 'c list -> 'a
- val fold_right2 : ('a -> 'b -> 'c -> 'c) -> 'a list -> 'b list -> 'c -> 'c
- val for_all : ('a -> bool) -> 'a list -> bool
- val exists : ('a -> bool) -> 'a list -> bool
- val for_all2 : ('a -> 'b -> bool) -> 'a list -> 'b list -> bool
- val exists2 : ('a -> 'b -> bool) -> 'a list -> 'b list -> bool
- val mem : 'a -> 'a list -> bool
- val memq : 'a -> 'a list -> bool
- val find : ('a -> bool) -> 'a list -> 'a
- val find_opt : ('a -> bool) -> 'a list -> 'a option
- val find_map : ('a -> 'b option) -> 'a list -> 'b option
- val filter : ('a -> bool) -> 'a list -> 'a list
- val find_all : ('a -> bool) -> 'a list -> 'a list
- val filteri : (int -> 'a -> bool) -> 'a list -> 'a list
- val partition : ('a -> bool) -> 'a list -> 'a list * 'a list
- val partition_map : ('a -> ('b, 'c) Stdlib.Either.t) -> 'a list -> 'b list * 'c list
- val assoc : 'a -> ('a * 'b) list -> 'b
- val assoc_opt : 'a -> ('a * 'b) list -> 'b option
- val assq : 'a -> ('a * 'b) list -> 'b
- val assq_opt : 'a -> ('a * 'b) list -> 'b option
- val mem_assoc : 'a -> ('a * 'b) list -> bool
- val mem_assq : 'a -> ('a * 'b) list -> bool
- val remove_assoc : 'a -> ('a * 'b) list -> ('a * 'b) list
- val remove_assq : 'a -> ('a * 'b) list -> ('a * 'b) list
- val split : ('a * 'b) list -> 'a list * 'b list
- val combine : 'a list -> 'b list -> ('a * 'b) list
- val sort : ('a -> 'a -> int) -> 'a list -> 'a list
- val stable_sort : ('a -> 'a -> int) -> 'a list -> 'a list
- val fast_sort : ('a -> 'a -> int) -> 'a list -> 'a list
- val sort_uniq : ('a -> 'a -> int) -> 'a list -> 'a list
- val merge : ('a -> 'a -> int) -> 'a list -> 'a list -> 'a list
- val to_seq : 'a list -> 'a Stdlib.Seq.t
- val of_seq : 'a Stdlib.Seq.t -> 'a list
Equality, testing
- val mem_f : 'a eq -> 'a -> 'a list -> bool
- Same as - List.mem, for some specific equality
- val for_all2eq : ('a -> 'b -> bool) -> 'a list -> 'b list -> bool
- Same as - List.for_all2but returning- falsewhen of different length
Creating lists
- val interval : int -> int -> int list
- interval i jcreates the list- [i; i + 1; ...; j], or- []when- j <= i.
- val make : int -> 'a -> 'a list
- make n xreturns a list made of- ntimes- x. Raise- Invalid_argument _if- nis negative.
Lists as arrays
Filtering
- val filter : ('a -> bool) -> 'a list -> 'a list
- Like OCaml - List.filterbut tail-recursive and physically returns the original list if the predicate holds for all elements.
- val filter2 : ('a -> 'b -> bool) -> 'a list -> 'b list -> 'a list * 'b list
- Like - List.filterbut with 2 arguments, raise- Invalid_argument _if the lists are not of same length.
- val filteri : (int -> 'a -> bool) -> 'a list -> 'a list
- Like - List.filterbut with an index starting from- 0
- val filter_with : bool list -> 'a list -> 'a list
- filter_with bl lselects elements of- lwhose corresponding element in- blis- true. Raise- Invalid_argument _if sizes differ.
Applying functorially
- val map_left : ('a -> 'b) -> 'a list -> 'b list
- As - mapbut ensures the left-to-right order of evaluation.
- val map_i : (int -> 'a -> 'b) -> int -> 'a list -> 'b list
- Like OCaml - List.mapibut tail-recursive. Alternatively, like- mapbut with an index
- val map2_i : (int -> 'a -> 'b -> 'c) -> int -> 'a list -> 'b list -> 'c list
- Like - map2but with an index
- val map3 : ('a -> 'b -> 'c -> 'd) -> 'a list -> 'b list -> 'c list -> 'd list
- Like - mapbut for 3 lists.
- val map4 : ('a -> 'b -> 'c -> 'd -> 'e) -> 'a list -> 'b list -> 'c list -> 'd list -> 'e list
- Like - mapbut for 4 lists.
- val map_of_array : ('a -> 'b) -> 'a array -> 'b list
- map_of_array f abehaves as- List.map f (Array.to_list a)
- val map_append : ('a -> 'b list) -> 'a list -> 'b list
- map_append f [x1; ...; xn]returns- f x1 @ ... @ f xn.
- val map_append2 : ('a -> 'b -> 'c list) -> 'a list -> 'b list -> 'c list
- Like - map_appendbut for two lists; raises- Invalid_argument _if the two lists do not have the same length.
Finding position
- val index : 'a eq -> 'a -> 'a list -> int
- indexreturns the 1st index of an element in a list (counting from 1).
- val safe_index : 'a eq -> 'a -> 'a list -> int option
- safe_indexreturns the 1st index of an element in a list (counting from 1) and None otherwise.
- val index0 : 'a eq -> 'a -> 'a list -> int
- index0behaves as- indexexcept that it starts counting at 0.
Folding
- val fold_left_until : ('c -> 'a -> 'c CSig.until) -> 'c -> 'a list -> 'c
- acts like - fold_left f acc swhile- freturns- Cont acc'; it stops returning- cas soon as- freturns- Stop c.
- val fold_right_i : (int -> 'a -> 'b -> 'b) -> int -> 'a list -> 'b -> 'b
- Like - List.fold_rightbut with an index
- val fold_left_i : (int -> 'a -> 'b -> 'a) -> int -> 'a -> 'b list -> 'a
- Like - List.fold_leftbut with an index
- val fold_right_and_left : ('b -> 'a -> 'a list -> 'b) -> 'a list -> 'b -> 'b
- fold_right_and_left f [a1;...;an] hdis- f (f (... (f (f hd an [an-1;...;a1]) an-1 [an-2;...;a1]) ...) a2 [a1]) a1 []
- val fold_left3 : ('a -> 'b -> 'c -> 'd -> 'a) -> 'a -> 'b list -> 'c list -> 'd list -> 'a
- Like - List.fold_leftbut for 3 lists; raise- Invalid_argument _if not all lists of the same size
- val fold_left2_set : exn -> ('a -> 'b -> 'c -> 'b list -> 'c list -> 'a) -> 'a -> 'b list -> 'c list -> 'a
- Fold sets, i.e. lists up to order; the folding function tells when elements match by returning a value and raising the given exception otherwise; sets should have the same size; raise the given exception if no pairing of the two sets is found;; complexity in O(n^2) 
- val fold_left_map : ('a -> 'b -> 'a * 'c) -> 'a -> 'b list -> 'a * 'c list
- fold_left_map f e_0 [a1;...;an]is- e_n,[k_1...k_n]where- (e_i,k_i)is- f e_{i-1} aifor each i<=n
- val fold_right_map : ('b -> 'a -> 'c * 'a) -> 'b list -> 'a -> 'c list * 'a
- Same, folding on the right 
- val fold_left2_map : ('a -> 'b -> 'c -> 'a * 'd) -> 'a -> 'b list -> 'c list -> 'a * 'd list
- Same with two lists, folding on the left 
- val fold_right2_map : ('b -> 'c -> 'a -> 'd * 'a) -> 'b list -> 'c list -> 'a -> 'd list * 'a
- Same with two lists, folding on the right 
Splitting
- val except : 'a eq -> 'a -> 'a list -> 'a list
- except eq a lRemove all occurrences of- ain- l
- val remove : 'a eq -> 'a -> 'a list -> 'a list
- Alias of - except
- val remove_first : ('a -> bool) -> 'a list -> 'a list
- Remove the first element satisfying a predicate, or raise - Not_found
- val extract_first : ('a -> bool) -> 'a list -> 'a list * 'a
- Remove and return the first element satisfying a predicate, or raise - Not_found
- val find_map : ('a -> 'b option) -> 'a list -> 'b
- Returns the first element that is mapped to - Some _. Raise- Not_foundif there is none.
- val goto : int -> 'a list -> 'a list * 'a list
- goto i lsplits- linto two lists- (l1,l2)such that- (List.rev l1)++l2=land- l1has length- i. It raises- IndexOutOfRangewhen- iis negative or greater than the length of- l.
- val split_when : ('a -> bool) -> 'a list -> 'a list * 'a list
- split_when p lsplits- linto two lists- (l1,a::l2)such that- l1++(a::l2)=l,- p a=trueand- p b = falsefor every element- bof- l1. if there is no such- a, then it returns- (l,[])instead.
- val sep_first : 'a list -> 'a * 'a list
- sep_first lreturns- (a,l')such that- lis- a::l'. It raises- Failure _if the list is empty.
- val sep_last : 'a list -> 'a * 'a list
- sep_last lreturns- (a,l')such that- lis- l'@[a]. It raises- Failure _if the list is empty.
- val drop_last : 'a list -> 'a list
- Remove the last element of the list. It raises - Failure _if the list is empty. This is the second part of- sep_last.
- val last : 'a list -> 'a
- Return the last element of the list. It raises - Failure _if the list is empty. This is the first part of- sep_last.
- val lastn : int -> 'a list -> 'a list
- lastn n lreturns the- nlast elements of- l. It raises- Failure _if- nis less than 0 or larger than the length of- l
- val chop : int -> 'a list -> 'a list * 'a list
- chop i lsplits- linto two lists- (l1,l2)such that- l1++l2=land- l1has length- i. It raises- Failure _when- iis negative or greater than the length of- l.
- val firstn : int -> 'a list -> 'a list
- firstn n lReturns the- nfirst elements of- l. It raises- Failure _if- nnegative or too large. This is the first part of- chop.
- val skipn : int -> 'a list -> 'a list
- skipn n ldrops the- nfirst elements of- l. It raises- Failure _if- nis less than 0 or larger than the length of- l. This is the second part of- chop.
- val skipn_at_least : int -> 'a list -> 'a list
- Same as - skipnbut returns- if- nis larger than the length of the list.
- val drop_prefix : 'a eq -> 'a list -> 'a list -> 'a list
- drop_prefix eq l1 lreturns- l2if- l=l1++l2else return- l.
- val insert : 'a eq -> 'a -> 'a list -> 'a list
- Insert at the (first) position so that if the list is ordered wrt to the total order given as argument, the order is preserved 
- share_tails l1 l2returns- (l1',l2',l)such that- l1is- l1'\@land- l2is- l2'\@land- lis maximal amongst all such decompositions
Association lists
- val map_assoc : ('a -> 'b) -> ('c * 'a) list -> ('c * 'b) list
- Applies a function on the codomain of an association list 
- val assoc_f : 'a eq -> 'a -> ('a * 'b) list -> 'b
- Like - List.assocbut using the equality given as argument
- val remove_assoc_f : 'a eq -> 'a -> ('a * 'b) list -> ('a * 'b) list
- Remove first matching element; unchanged if no such element 
- val mem_assoc_f : 'a eq -> 'a -> ('a * 'b) list -> bool
- Like - List.mem_assocbut using the equality given as argument
- val factorize_left : 'a eq -> ('a * 'b) list -> ('a * 'b list) list
- Create a list of associations from a list of pairs 
Operations on lists of tuples
Operations on lists seen as sets, preserving uniqueness of elements
- val add_set : 'a eq -> 'a -> 'a list -> 'a list
- add_set x ladds- xin- lif it is not already there, or returns- lotherwise.
- val eq_set : 'a eq -> 'a list eq
- Test equality up to permutation. It respects multiple occurrences and thus works also on multisets. 
- val subset : 'a list eq
- Tell if a list is a subset of another up to permutation. It expects each element to occur only once. 
- val merge_set : 'a cmp -> 'a list -> 'a list -> 'a list
- Merge two sorted lists and preserves the uniqueness property. 
- val intersect : 'a eq -> 'a list -> 'a list -> 'a list
- Return the intersection of two lists, assuming and preserving uniqueness of elements 
- val union : 'a eq -> 'a list -> 'a list -> 'a list
- Return the union of two lists, assuming and preserving uniqueness of elements 
- val subtract : 'a eq -> 'a list -> 'a list -> 'a list
- Remove from the first list all elements from the second list. 
Uniqueness and duplication
- val distinct_f : 'a cmp -> 'a list -> bool
- Like - distinctbut using the equality given as argument
- val duplicates : 'a eq -> 'a list -> 'a list
- Return the list of unique elements which appear at least twice. Elements are kept in the order of their first appearance. 
- val uniquize_key : ('a -> 'b) -> 'a list -> 'a list
- Return the list of elements without duplicates using the function to associate a comparison key to each element. This is the list unchanged if there was none. 
- val uniquize : 'a list -> 'a list
- Return the list of elements without duplicates. This is the list unchanged if there was none. 
- val sort_uniquize : 'a cmp -> 'a list -> 'a list
- Return a sorted version of a list without duplicates according to some comparison function. 
- val min : 'a cmp -> 'a list -> 'a
- Return minimum element according to some comparison function. - raises Not_found
- on an empty list. 
 
Cartesian product
- val cartesian : ('a -> 'b -> 'c) -> 'a list -> 'b list -> 'c list
- A generic binary cartesian product: for any operator (**), - cartesian (**) [x1;x2] [y1;y2] = [x1**y1; x1**y2; x2**y1; x2**y1], and so on if there are more elements in the lists.
- val cartesians : ('a -> 'b -> 'b) -> 'b -> 'a list list -> 'b list
- cartesians op init lis an n-ary cartesian product: it builds the list of all- op a1 .. (op an init) ..for- a1, ...,- anin the product of the elements of the lists
- val combinations : 'a list list -> 'a list list
- combinations lreturns the list of- n_1* ... *- n_ptuples- [a11;...;ap1];...;[a1n_1;...;apn_pd]whenever- lis a list- [a11;..;a1n_1];...;[ap1;apn_p]; otherwise said, it is- cartesians (::) [] l
- val cartesians_filter : ('a -> 'b -> 'b option) -> 'b -> 'a list list -> 'b list
- Like - cartesians op init lbut keep only the tuples for which- opreturns- Some _on all the elements of the tuple.
- module Smart : sig ... end
- When returning a list of same type as the input, maximally shares the suffix of the output which is physically equal to the corresponding suffix of the input 
module type MonoS = sig ... end