SML# Document Version 3.7.1
III Reference manual

Chapter 19 Expressions

The syntax for expressions (exp) is hierarchically defined below using infix operator expressions (infix), function application expressions (appexp), atomic expressions (atexp).


  • expressions (top-level)

    exp ::= infix
     | exp : ty
     | exp andalso exp
     | exp orelse exp
     | exp handle match
     | raise exp
     | if exp then exp else exp
     | while exp do exp
     | case exp of match
     | fn match
     | _import string : cfunty importing C function
     | exp : _import cfunty importing C function
     | _sizeof( ty ) size of type
     | _dynamic exp as ty Dynamic type cast
     | _dynamiccase exp of match case branches with dynamic type cast
     | _sqlserver (appexp)? : ty SQL servers
     | _sql pat => sqlfn SQL execution function
     | _sql sql SQL query fragments
    match ::= pat => exp (| match)? pattern matching
  • infix operator expressions

    infix ::= appexp
     | infix vid infix
  • function application expressions

    appexp ::= atexp
     | appexp atexp left associative function applications
     | appexp # { exprow } record field updates
  • atomic expressions

    atexp ::= scon constants
     | (op)? longVid identifiers
     | {(exprow)? } records
     | (exp1,,expn) tuples (n2)
     | () unit value
     | #lab record field selector
     | [exp1,,expn] lists (n0)
     | (exp1;;expn) sequential execution
     | let declList in exp1;;expn end local declarations
     | _sql (sql) SQL query fragments
     | (exp)
    exprow ::= lab = exp (, exprow)? record fields

The definitions for cfunty is given in Section 19.21 and those for sql and sqlfn are given in Chapter 22.

The above hierarchical definition for expressions represents associatibity among expression constructors. The associatibity of infix operator expressions infix are determined not by syntax but by the infix operator declarations. In the following sections, we first define in the next (19.1) elaboration rules of infix expressions. In the following sections, we define each of expression constructors and their types in the order of associatibity.