SML# Document Version 3.7.1
19 Expressions

19.4 Record expression {⟨lab1⟩ = ⟨exp1⟩, …, ⟨labn⟩ = ⟨expn⟩}

A record expression is a collection of pairs of labels ⟨labi⟩ and expressions ⟨expi⟩.

A record expression is evaluated as follows. First, it is checked whether all of its labels are distinct. If not, a type error occurs. Second, each expression ⟨expi⟩ is evaluated to a type ⟨tyi⟩ and value vi in the order of their occurrences in the record expression. Finally, they are sorted in the order of label strings and constitutes a record type

{⟨lab1′⟩ : ⟨ty1′⟩, …, ⟨labn′⟩ : ⟨tyn′⟩}

and record value

{⟨lab1′⟩ = v1′, …, ⟨labn′⟩ = vn′}

as the type and value of the record expression.

Therefore, for example, when

val x = {SML = (print "SML#";"SML#"), IS = (print " is ";" is "), SHARP = (print " sharp!\n";" sharp!\n")}

is evaluated, it prints "SML# is sharp!" and then x is bound to the type and value like the following

val x = {IS = " is ", SHARP = " sharp!\n", SML = "SML#"} : {IS: string, SHARP: string, SML: string}