ListAux
Module
signature LIST_AUX
structure ListAux
:> LIST_AUX
This module defines auxiliary functions on lists.
val sum : int list -> int
val prod : int list -> int
val max : int list -> int
val min : int list -> int
val sub : 'a list * int -> 'a
val update : 'a list * int * 'a -> 'a list
val position : ('a -> bool) -> 'a list -> int option
val repeat : 'a * int -> 'a list
val allButLast : 'a list -> 'a list
val splitAt : 'a list * int -> 'a list * 'a list
val allSplittings : 'a list -> ('a list * 'a list) list
val adjacentElts : 'a list -> ('a * 'a) list
val fromTo : int * int -> int list
sum xs
0
if xs is empty.
prod xs
1
if xs is empty.
max xs
Empty
if xs is empty.
min xs
Empty
if xs is empty.
sub(xs, n)
1
. Raises Subscript
if n is less than 1
or greater than the length of xs.
update(xs, n, y)
1
) is y. Raises Subscript
if n is less than 1
or greater than the length of xs.
position f xs
NONE
if f x
returns false
for all elements x of xs. Otherwise returns SOME n
where n is least such that f(sub(xs, n))
returns true
. f is called on the elements of xs in order, until the needed n is found, or the elements of xs are exausted.
repeat(x, n)
Domain
if n is negative.
allButLast xs
Empty
if xs is empty.
splitAt(xs, n)
(ys, zs)
, where ys is the first n elements of xs, and ys is the rest of xs. Raises Domain
if n is negative or greater than the length of xs.
allSplittings xs
(ys, zs)
such that ys @ zs = xs
, ordered according to the length of their first components (length 0
, then 1
, etc.).
adjacentElts xs
(sub(xs, 1), sub(xs, 2))
, second element is (sub(xs, 2), sub(xs, 3))
, third element is (sub(xs, 3), sub(xs, 4))
, etc., until one or thus, returns nil
if xs doesn't have at least two elements.
fromTo(n, m)
Forlan Version 4.15
Copyright © 2022 Alley Stoughton