Language constructs
Identifiers
Variables and type variables
In regular expression:
[a-z_]([-]*[a-zA-Z0-9_]+)*['?]*
seq,x',some?,foo-barfooBar,a0,take_while
Constructor, type constructor, and trait names
In regular expression:
[A-Z][a-zA-Z0-9_]*
List,Nil,Eq,Iter
Module names
In regular expression:
[a-z_]([-]*[a-zA-Z0-9_]+)*
core,cmp,iter
Module path (qualified module names)
A sequence of module names separated by
::
::core::cmp,::core::listAbsolute pathcmp,list,foo::barRelative path
Qualified names
A module path followed by a variable, constructor, type constructor, or trait name
::core::iter::seq,::core::iter::Seq,::core::iter::Iteriter::seq,iter::Seq,iter::Iter
Literals
()Unit value literaltrue,falseBoolean value literals0,100,-1Integer value literals
Primitive types
()Unit typeBoolBoolean typeIntInteger type(t,),(t1, t2)Tuple type@{x:t1, y:t2}Record typet1 -> t2Function typeT t,t1 t2Type-level function application
Operators
Infix (binary) operators
==,!=Equality / Non-equality operators<=,<,>,>=Comparison operators&&,||Logical operators+,-,*,/,%Arithmetic operators|>,<|Pipeline operators>>,<<Function composition operators
Prefix operators
nagete,-Arithmetic negationnot,!Boolean not
User defined infix operators
In regular expression:
[*+\-/!$%&=^?<>]+
?>,===,++
Operators as functions
(==) 1 1(+) 1 2
Functions and constructors as operators
1 `Cons` Nilx `@{Eq Int}.(==)` y
Declarations
At the top level of a module:
modDefine sub-moduleuseImport identifierstypeDefine Algebraic Data Type (ADT)traitDefine Multi-Parameter Type Class (MPTC)implDefine MPTC instance implementation*letDefine generic/overloaded function templateletDefine a variable or functionlet recDefine a recursive function
Statements
Within a local scope:
letVariable / function bindinglet recRecursive function binding
Note
In the case of
let rec p = e;,
pmust be a variable pattern.In the case of
let p = e;,
- At the top level of a module,
pmust be a variable pattern.- Within a local scope, any pattern can be used for
p.
Expressions
Value expressions
(evaluate to themselves; safe to generalize)
(),true,0Literalsλp.e/\p.eLambda abstraction (function)(e1,),(e1, e2)Tuple value@{x = e1, y = e2}Record value@{T t1 t2}Trait record value|(e op)/|(e op _)Infix-operator partial application (bind the 1st argument)|(op e)/|(_ op e)Infix-operator partial application (bind the 2nd argument)
Infix-operator partial applications (a.k.a. section syntax) are desugared into lambda abstraction.
Note
Old section syntax
#(e op)/#(e op _)and#(op e)/#(_ op e)are deprecated.
Use new syntax|(e op)/|(e op _)and|(op e)/|(_ op e)instead.
Important
Old record value syntax
@{x: e1, y: e2}are deprecated and no longer supported.
Use new syntax@{x = e1, y = e2}instead.
Non-value expressions
(require evaluation; not eligible for generalization)
xEvaluate variablee1 e2Function applicatione.0Tuple index accesse.xRecord field access{ stmt1; stmt2; expr }Block expression (evaluates to the last expression; introduces a new scope)if (e1) e2 else e3If then elsematch (e) { p1 => e1, .. }Pattern matching
Patterns
_Wildcard pattern(),true,0Literal patternx,fooVariable patternNil,Cons p psConstructor pattern(p1,),(p1, p2)Tuple pattern@{x = p1, y = p2},@{x, y}Record pattern
Important
Old record pattern syntax
@{x: p1, y: p2}are deprecated and no longer supported.
Use new syntax@{x = p1, y = p2}instead.