The TABLE signature

Overview

Tables are mappings of keys to values. They can be defined formally
as a set of key-value pairs, but we choose to denote tables as sets of
mappings $(k \mapsto v)$. The key type is fixed by the
Key substructure while the value type is polymorphic.
Tables do not contain duplicate keys, and therefore each table associates a
unique value with each key it contains. We include a
Set substructure to reinforce the relationship
between tables and sets.

We use a number of notational conventions which can be seen
here. For example,
we write $|t|$ for the number of key-value pairs in a table $t$, and the
empty table is denoted either $\{\}$ or $\emptyset$.

Substructures

The Key substructure defines the key type of
tables, providing equality and other useful functions.

structure Seq :
SEQUENCE

The Seq substructure defines the sequence type to
and from which tables can be converted.

structure Set :
SET where Key = Key and Seq = Seq

The Set substructure contains operations on
sets with elements of type Key.t.

Types

type α t

The abstract table type.

type α table =
α t

An alias for α t, for readability.

Values

val size :
α table → int

Return the number of key-value pairs in a table.

val domain :
α table → Set.t

Return the set of all keys in a table.

val range :
α table → α Seq.t

Return a sequence of all values in a table. The order of the elements
is implementation-defined.

val toString :
(α → string) → α table → string

(toString f t) evaluates to a string representation of $t$
where each key is converted to a string with Key.toString
and each value is converted with $f$. For example, the table
$\{ (1 \mapsto 2), (3 \mapsto 42) \}$ might be represented by the string
“{(1->2),(3->42)}“. The ordering of key-value
pairs in the resulting string is implementation-defined.

val toSeq :
α table → (Key.t * α) Seq.t

Return a sequence of all key-value pairs in a table. The order of the
sequence is implementation-defined.

restrict is basically an alias for intersection
in that it restricts a table's domain by the elements of a set.
The name is motivated by the interpretation of a table as a function,
and therefore (restrict (t, x)) evaluates to $t\,|_x$.

val subtract :
α table * Set.t → α table

subtract is basically an alias for difference
in that it removes all mappings whose keys are given in a set. The name
is once again motivated by the interpretation of a table as a function,
where (subtract (t, x)) performs the domain subtraction
of $t$ by $x$. This is also sometimes referred to as the domain
anti-restriction.