λ

1.11: Recursive types

Types may be recursive, making it easy to define recursive data structures like lists or trees. For example, a list of 'as could be defined using two cases:

A binary tree could be defined as two cases as well:

User-defined operators, like +: used here, may be made usable infix, that is, between two arguments, by using the infixr <N> op and infix <N> op keywords. Taking subtraction as an example, e.g., 3 - 4 - 5 - 6:

<N> specifies how tightly operators bind to their arguments. Given two operators, * and -, and the expression 3 * 4 - 5:

(* examples/recursive-datatypes.sml *)