ABSTRACT

Let expressions are useful for improving readability by contracting complicated expressions used more than once. For example, their use is fairly close to the mathematical convention in expressions such as:

Let be expressions are useful for abstracting away the inessential choice of an element from a set, in particular in formulating recursive definitions over sets:

Let be expressions are also useful where it is known that an element with some property exists but an explicit expression for such an element is not known or difficult to write:

Let and definition expressions provide a convenient way to access the components of a compound value. For a tuple value this is the only way:

For other compound values there is a choice between using a compound pattern and explicitly extracting the components. For example, with a sequence type, the following expressions are equivalent:

Table 22 Complex expressions

expression

value

def Pb1=E1,…,Pbn=En in E

; definition expression: the value of E in the context of matching each Pti to a value of Ei; choice limited to an element of Si or a value of Ti (Pbi is Pti: Ti or Pti Si)

let Pb1=E1,…,Pbn=En in E

; let binding expression: as for definition expression, but no variables allowed in Ei

let Pt S be st B in E

let Pt : T be st B in E

; let be expression: the value of E in the context of matching Pt to a value that satisfies B; choice limited to an element of S or a value of T.