Lists

The List structure provides a typical collection of list operations.

The "@" operator will append two lists but this will result in copying the first list in order that it remain immutable. Only prepending an element with "::" is cheap. You can prepend in bulk using the revAppend function. This will push all of the elements of the first list onto the front of the second. This is useful when building lists in reverse in tail-recursive functions.

The apply function, app, applies a function only for side-effects. These might be for writing to an output stream or updating an imperative table.

The tabulate function can be useful for creating lists of a given length. For example

implode(List.tabulate(100, fn _ => #" "))

will make a string of 100 blanks.

The ListPair structure adds some functions for dealing with lists of pairs.