19.7 List expression [exp, , exp]
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.
|
From this translation, every element expression in a list expression must have the same type , and the type of a list expression is list, and the value of the expression is a data of the form ::(, ::(, ::(,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.