Alice ML is based on the Standard ML programming language (SML), as defined in
However, Alice ML features several major extensions relative to SML:
You should also be aware of some
Alice defines some additional identifiers as reserved words:
any assert assertd constructor exttype fct finally from import non lazy pack spawn unpack withfun withval _file_ _line_
The following grammar collects all syntactic extensions of Alice ML relative to Standard ML. Derived forms are marked (*).
atexp | ::= | ... | |
#[ exp1 , ... , expn ] | vector (n≥0) | ||
{ atexp where exprow } | record update | ||
_file_ | source file (*) | ||
_line_ | source line (*) | ||
exp | ::= | ... | |
lazy exp | lazy | ||
spawn exp | concurrent | ||
exp1 finally exp2 | finalization (L) (*) | ||
rec pat => exp | recursion (*) | ||
pack strexp : sigexp | transparent packing | ||
pack strexp :> sigexp | opaque packing (*) | ||
assert<d> exp | boolean assertion (*) | ||
assert<d> exp of pat | pattern assertion (*) | ||
assert<d> exp raise pat | exception assertion (*) | ||
assert<d> exp do exp | boolean precondition (*) | ||
assert<d> exp of pat do exp | pattern precondition (*) | ||
exprow | ::= | ... | |
vid <: ty> <, exprow> | label as expression (*) |
atpat | ::= | ... | |
#[ pat1 , ... , patn ] | vector (n≥0) | ||
( pat1 | ... | patn ) | alternative (n≥2) | ||
pat | ::= | ... | |
pat as pat | layered (R) | ||
pat where atexp | guarded (L) |
ty | ::= | ... | |
_ | wildcard |
dec | ::= | ... | 1) |
exttype extbind | extensible datatype | ||
constructor econbind | generative constructor | ||
fvalbind | ::= | <lazy | spawn> | lazy/concurrent function (m,n≥1) (*) |
<op> vid atpat11 ... atpat1n <: ty1> = exp1 | |||
| <op> vid atpat21 ... atpat2n <: ty2> = exp2 | |||
| ... | |||
| <op> vid atpatm1 ... atpatmn <: tym> = expm | |||
<and fvalbind> | |||
extbind | ::= | tyvarseq tycon | extensible datatype |
econbind | ::= | <op> vid <of ty> : tyvarseq longtycon <and econbind> | new constructor |
<op> vid = <op> longvid <and econbind> | synonym | ||
strbind | ::= | ... | |
_ <: sigexp> = strexp <and strbind> | anonymous structure (*) | ||
funbind | ::= | <lazy | spawn> strid strpat1 ... strpatn < : | :> sigexp> = strexp <and funbind> | functor binding (n≥1) (*) 2 |
1) The extended phrase class dec contains all of Standard ML's dec, strdec and topdec.
2) See the module syntax summary for a more precise grammar of functor bindings.
strexp | ::= | ... | |
( strexp ) | parentheses | ||
( dec ) | structure (*) | ||
strexp strexp | functor application 1 | ||
fct strpat => strexp | functor | ||
unpack infexp : sigexp | unpacking | ||
lazy strexp | laziness | ||
spawn strexp | concurrency | ||
strpat | ::= | strid : sigexp | parameter |
_ : sigexp | anonymous parameter (*) | ||
( strid : sigexp ) | parameter (*) | ||
( _ : sigexp ) | anonymous parameter (*) | ||
( spec ) | signature as parameter (*) |
1) See the module syntax summary for a more precise grammar of structure expressions and functor application.
sigexp | ::= | ... | |
longsigid | signature identifier | ||
( sigexp ) | parentheses | ||
( spec ) | signature (*) | ||
fct strpat -> sigexp | functor | ||
sigexp1 -> sigexp2 | non-dependent functor 1 |
1) See the module syntax summary for a more precise grammar of functor signatures.
spec | ::= | ... | |
exttype extdesc | extensible datatype | ||
constructor econdesc | generative constructor | ||
functor fundesc | functor specification (*) | ||
signature sigdesc | signature specification | ||
extdesc | ::= | tyvarseq tycon | extensible datatype |
econdesc | ::= | <op> vid <of ty> : tyvarseq longtycon <and econdesc> | new constructor |
fundesc | ::= | strid strpat1 ... strpatn : sigexp <and fundesc> | functor description (n≥1) (*) 1 |
sigdesc | ::= | sigid <= sigexp> <and sigdesc> | signature description |
1) See the module syntax summary for a more precise grammar of functor specifications.
component | ::= | ann <program> | component |
ann | ::= | import imp from string | import announcement |
import string | import all (*) | ||
empty | |||
ann <;> ann | |||
imp | ::= | val valitem | |
type typitem | |||
datatype datitem | |||
exttype extitem | |||
constructor econitem | |||
exception exitem | (*) | ||
structure stritem | |||
functor funitem | (*) | ||
signature sigitem | |||
infix <d> vid1 ... vidn | (n≥1) | ||
infixr <d> vid1 ... vidn | (n≥1) | ||
nonfix vid1 ... vidn | (n≥1) | ||
empty | |||
imp <;> imp | |||
valitem | ::= | <op> vid <and valitem> | |
<op> vid : ty <and valitem> | |||
typitem | ::= | tycon <and typitem> | |
tyvarseq tycon <and typitem> | |||
datitem | ::= | tycon <and datitem> | |
tyvarseq tycon = conitem <and datitem> | |||
conitem | ::= | <op> vid <of ty> <| conitem> | |
extitem | ::= | tycon <and extitem> | |
tyvarseq tycon <and extitem> | |||
econitem | ::= | <op> vid <and econitem> | |
exitem | ::= | <op> vid <and exitem> | (*) |
<op> vid of ty <and exitem> | (*) | ||
stritem | ::= | strid <and stritem> | |
strid : sigexp <and stritem> | |||
funitem | ::= | strid <and funitem> | (*) |
strid strpat1 ... strpatn : sigexp <and funitem> | (n≥1) (*) 1 | ||
sigitem | ::= | sigid <and sigitem> |
1) See the component syntax summary for a more precise grammar of functor items.