Module CCRAL
Random-Access Lists
This is an OCaml implementation of Okasaki's paper "Purely Functional Random Access Lists". It defines a list-like data structure with O(1) cons/tail operations, and O(log(n)) lookup/modification operations.
This module used to be part of containers.misc
status: stable
- since
 - 0.13
 
val empty : 'a tEmpty list.
val is_empty : _ t -> boolCheck whether the list is empty.
val return : 'a -> 'a tSingleton.
val hd : 'a t -> 'aFirst element of the list, or
- raises Invalid_argument
 if the list is empty.
val tl : 'a t -> 'a tRemove the first element from the list, or
- raises Invalid_argument
 if the list is empty.
val front_exn : 'a t -> 'a * 'a tUnsafe version of
front.- raises Invalid_argument
 if the list is empty.
val length : 'a t -> intNumber of elements. Complexity
O(ln n)where n=number of elements.
val get : 'a t -> int -> 'a optionget l iaccesses thei-th element of the list.O(log(n)).
val get_exn : 'a t -> int -> 'aUnsafe version of
get.- raises Invalid_argument
 if the list has less than
i+1elements.
val set : 'a t -> int -> 'a -> 'a tset l i vsets thei-th element of the list tov.O(log(n)).- raises Invalid_argument
 if the list has less than
i+1elements.
val remove : 'a t -> int -> 'a tremove l iremoves thei-th element ofv.- raises Invalid_argument
 if the list has less than
i+1elements.
val append : 'a t -> 'a t -> 'a tval filter : f:('a -> bool) -> 'a t -> 'a tval filter_map : f:('a -> 'b option) -> 'a t -> 'b tval flat_map : ('a -> 'b t) -> 'a t -> 'b tval flatten : 'a t t -> 'a tval app : ('a -> 'b) t -> 'a t -> 'b tval take : int -> 'a t -> 'a tval take_while : f:('a -> bool) -> 'a t -> 'a tval drop : int -> 'a t -> 'a tval drop_while : f:('a -> bool) -> 'a t -> 'a tval take_drop : int -> 'a t -> 'a t * 'a ttake_drop n lsplitslintoa, bsuch thatlength a = niflength l >= n, and such thatappend a b = l.
val iter : f:('a -> unit) -> 'a t -> unitIterate on the list's elements.
val iteri : f:(int -> 'a -> unit) -> 'a t -> unitval fold : f:('b -> 'a -> 'b) -> x:'b -> 'a t -> 'bFold on the list's elements.
val fold_rev : f:('b -> 'a -> 'b) -> x:'b -> 'a t -> 'bFold on the list's elements, in reverse order (starting from the tail).
val equal : eq:('a -> 'a -> bool) -> 'a t -> 'a t -> boolval compare : cmp:('a -> 'a -> int) -> 'a t -> 'a t -> intLexicographic comparison.
Utils
val make : int -> 'a -> 'a tval repeat : int -> 'a t -> 'a trepeat n lisappend l (append l ... l)ntimes.
val range : int -> int -> int trange i jisi; i+1; ... ; jorj; j-1; ...; i.
Conversions
val add_list : 'a t -> 'a list -> 'a tval of_list : 'a list -> 'a tConvert a list to a RAL. Caution: non tail-rec.
Infix
module Infix : sig ... end