Relational structure

May 20, 2026 · View on GitHub

Up to index

The Relational structure provides aggregation, comparison, and set operations that are used in Morel from expressions. These functions extend Standard ML with relational-algebra capabilities.

Synopsis

datatype 'a descending = DESC of 'a

val compare : 'a * 'a -> order
val count : 'a bag -> int
val empty : 'a bag -> bool
val iterate : 'a bag -> ('a bag * 'a bag -> 'a bag) -> 'a bag
val max : 'a bag -> 'a
val min : 'a bag -> 'a
val nonEmpty : 'a bag -> bool
val only : 'a bag -> 'a
val sum : 'a bag -> 'a

datatype 'a descending

wraps a value so that it sorts in descending order when used with Relational.compare.

compare

compare (x, y) returns LESS, EQUAL, or GREATER according to whether its first argument is less than, equal to, or greater than the second.

Comparisons are based on the structure of the type α. Primitive types are compared using their natural order; Option types compare with NONE last; Tuple types compare lexicographically; Record types compare lexicographically, with the fields compared in alphabetical order; List values compare lexicographically; Bag values compare lexicographically, the elements appearing in an order that is arbitrary but is consistent for each particular value.

count

count list (or list.count ()) returns the number of elements in list. Often used with group, for example from e in emps group e.deptno compute countId = count.

empty

empty list (or list.empty ()) returns whether the list is empty, for example from d in depts where empty (from e where e.deptno = d.deptno).

iterate

iterate initialList listUpdate (or initialList.iterate listUpdate) computes a fixed point, starting with initialList and calling listUpdate (prevList, newList) each iteration, terminating the iteration when it returns newList.

max

max list (or list.max ()) returns the greatest element of list. Often used with group, for example from e in emps group e.deptno compute maxId = max of e.id.

min

min list (or list.min ()) returns the least element of list. Often used with group, for example from e in emps group e.deptno compute minId = min of e.id.

nonEmpty

nonEmpty list (or list.nonEmpty ()) returns whether the list has at least one element, for example from d in depts where nonEmpty (from e where e.deptno = d.deptno).

only

only list (or list.only ()) returns the sole element of list, for example from e in emps yield only (from d where d.deptno = e.deptno).

sum

sum list (or list.sum ()) returns the sum of the elements of list. Often used with group, for example from e in emps group e.deptno compute sumId = sum of e.id.