Imandra_prelude.List
This module contains many safe functions for manipulating lists.
type 'a t = 'a list
val empty : 'a list
val is_empty : 'a list -> bool
Test whether a list is empty
val return : 'a -> 'a list
Singleton list
Partial function to access the head of the list. This function will fail when applied to the empty list. NOTE it is recommended to rely on pattern matching instead
Partial function to access the tail of the list. This function will fail when applied to the empty list NOTE it is recommended to rely on pattern matching instead
List append / concatenation. append l1 l2
returns a list composed of all elements of l1
, followed by all elements of l2
val append_to_nil : 'a list -> bool
val length : 'a list -> Z.t
Compute the length of a list. Linear time.
val len_nonnegative : 'a list -> bool
val len_zero_is_empty : 'a list -> bool
Map a function over a list.
map f [] = []
map f [x] = [f x]
map f (x :: tail) = f x :: map f tail
val for_all : ( 'a -> bool ) -> 'a list -> bool
for_all f l
tests whether all elements of l
satisfy the predicate f
val exists : ( 'a -> bool ) -> 'a list -> bool
exists f l
tests whether there is an element of l
that satisfies the predicate f
val fold_left : ( 'a -> 'b -> 'a ) -> 'a -> 'b list -> 'a
Fold-left, with an accumulator that makes induction more challenging
val fold_right : ( 'a -> 'b -> 'b ) -> base:'b -> 'a list -> 'b
Fold-right, without accumulator. This is generally more friendly for induction than fold_left
.
filter f l
keeps only the elements of l
that satisfy f
.
find f l
returns Some x
if x
is the first element of l
such that f x
is true. Otherwise it returns None
val mem : 'a -> 'a list -> bool
mem x l
returns true
iff x
is an element of l
val mem_assoc : 'a -> ('a * 'b) list -> bool
take n l
returns a list composed of the first (at most) n
elements of l
. If length l <= n
then it returns l
drop n l
returns l
where the first (at most) n
elements have been removed. If length l <= n
then it returns []
Integer range. i -- j
is the list [i; i+1; i+2; …; j-1]
. Returns the empty list if i >= j
.
Insert x
in l
, keeping l
sorted.
val is_sorted : leq:( 'a -> 'a -> bool ) -> 'a list -> bool
Check whether a list is sorted, using the leq
small-or-equal-than predicatet