Forlan Manual


The ListAux Module


Synopsis

signature LIST_AUX
structure ListAux :> LIST_AUX

This module defines auxiliary functions on lists.


Interface

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

Description

sum xs
computes the sum of the elements in xs, yielding 0 if xs is empty.

prod xs
computes the product of the elements in xs, yielding 1 if xs is empty.

max xs
returns the largest element of xs. Raises Empty if xs is empty.

min xs
returns the smallest element of xs. Raises Empty if xs is empty.

sub(xs, n)
returns the nth element of xs, counting from 1. Raises Subscript if n is less than 1 or greater than the length of xs.

update(xs, n, y)
returns a list that is just like xs except that the element at position n (counting from 1) is y. Raises Subscript if n is less than 1 or greater than the length of xs.

position f xs
returns 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)
returns the list of length n, all of whose elements are x. Raises Domain if n is negative.

allButLast xs
return the sub-list consisting of all but the last element of xs. Raises Empty if xs is empty.

splitAt(xs, n)
returns (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
returns the list of pairs (ys, zs) such that ys @ zs = xs, ordered according to the length of their first components (length 0, then 1, etc.).

adjacentElts xs
returns the list whose first element is (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)
returns the list of integers that are greater than or equal to n and less than or equal to m, listed in strictly ascending order.


[ Top | Parent | Root | Contents | Index ]

Forlan Version 4.12
Copyright © 2019 Alley Stoughton