SML# Document Version 3.7.1
19 Expressions

19.7 List expression [exp1, , expn]

A list expression is a sequence of expressions of elements that is separated by commas and surrounded by [ and ]. When evaluated, a list expression yields the list type and a value of a list type. The list type is defined as the following data type.

infixr 5 ::
datatype ’a list = op :: of ’a * ’a list | nil

A list expression is syntactically translated as follows.

source result
[exp1,,expn] exp1 :: :: expn :: nil
(0n)

From this translation, every element expression in a list expression must have the same type τ, and the type of a list expression is ty list, and the value of the expression is a data of the form ::(v1, ::(v2, ::(vn,nil))).

The following shows an example.

# [1, 2, 3, 4];
val it = [1, 2, 3, 4] : int list
# [fn x => x, fn x => x + 1];
val it = [fn, fn] : (int -> int) list
# [];
val it = [] : [’a. ’a list]

As seen in the example, the empty list, [], has a polymorphic type.