SML# Document Version 3.7.1
19 Expressions

19.19 Function expression fn match

This is for the anonymous function indicated by match. match is of the form

  pat1 => exp1
|
|
patn => expn

that indicates pairs of an argument pattern and its corresponding function body.

The type of each pair of a pattern and expression pati =¿ expi is calculated as follows: first, the type tyi of pati is calculated; second, under the environment extended with variables in the pattern, the type tyi of expi is calculated; and finally, the two types are combined into a function type tyi -> tyi. The type of this entire expression is ty -> ty’ that is obtained by unifying the types of the matching pairs. The value of this function is the function closure consisting of the current value environment and the function expression itself.