Nemerle Language Reference

1. Introduction

This document presents in a semi-formal way the syntax and semantics of the Nemerle language. It is not meant to be a tutorial.

We often refer to .NET terminology [FIXME: reference it].

2. Lexical Conventions

Programs are written using the Unicode character set. Every Nemerle source file is reduced to a sequence of lexical units (tokens) separated by sequences of white characters (blanks).

2.1. Tokens

There are five classes of lexical tokens:

/* A comment. */
// Also a comment

foo               // identifier
foo_bar foo' foo3 // other identifiers
42                // integer literal
1_000_000         // _ can be used for readability
1_42_00           // or unreadability...
0x2a              // hexadecimal integer literal
0o52              // octal integer literal
0b101010          // binary integer literal
'a'               // character literal
'\n'              // also a character literal
"foo\nbar"        // string literal
"foo" "bar"       // same as "foobar"
@"x\n"            // same as "x\\n"
@if               // keyword used as identifier
3.14f             // float literal
3.14d, 3.14       // double literal
3.14m             // decimal literal
10         // int
10u        // unsigned int
10b        // signed byte
10ub, 10bu // unsigned byte
10l        // long
10ul, 10lu // unsigned long

2.2. Blanks

Spaces, vertical and horizontal tabulation characters, new-page characters, new-line characters and comments (called blanks altogether) are discarded, but can separate other lexical tokens.

A traditional comment begins with a /*, and ends with */. An end-of-line comment starts with //, and ends with the line terminator (ASCII LF character).

2.3. Preprocessing directives

There is a set of preprocessing directives used for conditional compilation and changing line numbering context. They are the same as in C#. Allowed directives are: #define, #undef, #if, #elif, #else, #endif, #line, #error, #warning, #region and #endregion.

2.4. Identifiers

Ordinary identifiers consist of letters, digits, underscores and apostrophe, but cannot begin with a digit nor an apostrophe. Identifiers may be quoted with the @ character, which is stripped. It removes any lexical and syntactic meaning from the following string of characters until blank, thus enabling programmer to use keywords as identifiers.

There is an important difference between identifiers starting with underscore character _ and the other ones. When you define local value with name starting with _ and won't use it, compiler won't complain about it. It will warn about other unused values though.

Symbolic identifiers consist of following characters: =, <, >, @, ^, |, &, +, -, *, /, $, %, !, ?, ~, ., :, #. Symbolic identifiers are treated as standard identifiers except to the fact that they are always treated as infix operators.

2.5. Keywords

Following identifiers are used as keywords, and may not be used in any other context unquoted: _, abstract, and, array, as, base, catch, class, def, delegate, do, else, enum, event, extern, false, finally, for, foreach, fun, if, implements, in, interface, internal, lock, macro, match, module, mutable, namespace, new, null, out, override, params, private, protected, public, ref, sealed, static, struct, syntax, this, throw, true, try, type, typeof, unless, using, variant, virtual, void, when, where, while, assert, ignore.

Following infix identifiers are reserved keywords: =, $, ?, |, <-, ->, =>, <[, ]>, &&, ||.

2.6. Literals

There are few kinds of literals:

3. Compilation units

compilation_unit ::=

A Nemerle program consists of one or more compilation units. Compilation units are text files with the .n extension. A compilation unit consists of namespace-related declarations and types within them.

toplevel_declaration ::=

Add the specified namespace (which, unlike in C#, can also be a type name) to the symbol search path. Every symbol till end of current namespace or compilation unit (if not within namespace) will be searched also in location specified by this path.

toplevel_declaration ::=
using IDENTIFIER = qualified_identifier ;

Define an alias for a namespace or type. After using Foo = Bar.Baz; any reference to Foo.bar will be expanded to Bar.Baz.bar.

toplevel_declaration ::=

Put declarations within the specified namespace. Namespaces can be nested, creating a tree of namespaces.

toplevel_declaration ::=

Define a new top level type.

4. Stuff that doesn't fit anywhere else

This section lists grammar rules common to most of other sections.

4.1. Identifier or dummy

identifier_or_dummy ::=
IDENTIFIER
identifier_or_dummy ::=
_

In several places it is possible to use the _ keyword to denote the intent to ignore a parameter or a return value. Semantics of _ in such places is to generate a new temporary name.

4.2. Qualified identifier

qualified_identifier ::=
IDENTIFIER { . IDENTIFIER }

Identifiers can be qualified with namespaces.

5. Type declarations

Types are defined at the top level, within namespaces or within other types. Top level type names are prefixed with the namespace they are defined in. Nested type names are prefixed with the parent type name. Nesting affects accessibility of a type.

5.1. Type header

type_header ::=
IDENTIFIER [ type_parameters ] [ : type { , type } ] where_constraints

Type header is similar to .NET. The main difference is the optional type_parameters list, defined below.

5.2. Type parameters

type_parameters ::=
< TYPE_VARIABLE { , TYPE_VARIABLE } >
where_constraints ::=
{ where TYPE_VARIABLE : type { , type } }

When defining polymorphic type one has to specify list of type variables in declaration. It can have following form:

class Foo <a, b>

An optional list of where parameters can be used to add constraints to the type variables (type coercion).

where a : Nemerle.Collections.IEnumerable, IComparable
where b : Nemerle.Collections.IDictionary

5.3. Type alias

type_declaration ::=

This type declaration creates an alias to another type.

5.4. Interface definition

type_declaration ::=

Nemerle interfaces are similar to .NET.

5.5. Class definition

type_declaration ::=

Class definition is similar to .NET.

5.6. Structure definition

type_declaration ::=

5.7. Module definition

type_declaration ::=

A module is much like a class, but all module members are static. There is no need to place static attributes on module members. It is also not possible to create instances of module types.

5.8. Variant definition

type_declaration ::=

A variant declaration consists of a type name and a list of bar-separated constructors enclosed in brackets.

variant_option ::=
| IDENTIFIER [ { { field_definition } } ]

The constructor declaration describes the constructor associated to this variant type. A constructor may take an argument. Constructor name must be capitalized.

variant_option ::=

Variants (unlike variant options) can also have other members (methods and fields).

5.9. Enum type definition

type_declaration ::=
attributes enum type_header { { | IDENTIFIER [ = literal ] } }

Nemerle enums are similar to enums in C#.

5.10. Delegate type definition

type_declaration ::=

6. Attributes

The semantics of attributes is the same as in C#, except for mutable attribute, meaning lack of readonly.

attributes ::=
{ attribute }
attribute ::=
new
attribute ::=
volatile
attribute ::=
public
attribute ::=
protected
attribute ::=
internal
attribute ::=
private
attribute ::=
abstract
attribute ::=
sealed
attribute ::=
override
attribute ::=
static
attribute ::=
mutable
attribute ::=
custom_attribute ::=
[ [ attribute_target ] expr { , expr } ]
attribute_target ::=
assembly
attribute_target ::=
field
attribute_target ::=
event
attribute_target ::=
method
attribute_target ::=
module
attribute_target ::=
param
attribute_target ::=
property
attribute_target ::=
return
attribute_target ::=
type

7. Declarations within types

The following fields are allowed in class or module body:

type_member ::=
type_member ::=
type_member ::=
type_member ::=
type_member ::=

7.1. Field definition

field_definition ::=
attributes IDENTIFIER : type [ = expr ] ;

Unless the optional mutable attribute is used, the field can be modified only inside the constructor.

7.2. Property definition

property_definition ::=
attributes IDENTIFIER : type { property_body }
property_body ::=
property_body ::=

The fields defined in a property are local for it, they cannot be referenced outside the property.

7.3. Event definition

event_definition ::=
attributes event IDENTIFIER : type { event_body }
event_body ::=
add block remove block
event_body ::=
remove block add block

7.4. Interface member

interface_member ::=
[ new ] method_header ;

Keyword new is necessary when the declared method hides the inherited one from another interface.

interface_member ::=
[ new ] event IDENTIFIER : type ;
interface_member ::=
[ new ] IDENTIFIER : type property_body

7.5. Method definition

method_definition ::=

This is a definition of method within class or module. Program entry point is method static Main.

7.6. Method header

method_type_parameters ::=
< TYPE_VARIABLE { , TYPE_VARIABLE } >

The declaration of a polymorphic method needs its type variables listed after the identifier.

method_header ::=

This is a declaration of method. Unlike in C#, the type is specified after the parameters list.

method_header ::=

A special method named this specifies a constructor. This declaration cannot contain the method type and the method has to have type void.

method_implements ::=

7.7. Method parameters

method_parameter ::=
[ params ] identifier_or_dummy [ : type ]

A method parameter is a pair consisting of identifier or _ and its type specification. Type declaration can be omitted in local functions definitions.

method_parameters ::=

Method parameters are comma-separated list of parameter specification.

7.8. Method body

method_body ::=
= extern STRING_LITERAL ;

The method body can be linked to an external function, for example:

static ps (s : string) : void = extern "System.Console.Write";

This feature is used to give meaning to infix operators. It is not currently fully supported. It should not be considered rock-stable feature.

method_body ::=
;

Empty method body (a ;) is a method declaration.

method_body ::=

This is a classical method definition.

8. Type expressions

Type expressions relate to type declarations much like function calls relate to function and value definitions. Type declarations define ways of constructing types and type expressions define actual types.

Types are both static and dynamic characterization of values. The static type of expression depends on its building blocks and is defined in the paragraph describing given expression. The dynamic (runtime) type is bound to the value at the moment it is created, and remains there until the value is garbage collected.

The type system is modeled after .NET Generics design, except for tuple and function types, which are new, but can be easily simulated using generics.

8.1. Type constructor application

primary_type ::=

A type constructor (defined with type declaration) can be applied to zero or more arguments forming a type expression. The number of type arguments in type application must match the number of type arguments in definition. Moreover, actual type arguments must solve where constraints imposed on formal type arguments.

8.2. Type variable reference

primary_type ::=
TYPE_VARIABLE

Refer to the type substituted to a given type variable. The type variable has to be defined (bound, quantified) before it is used. A type variable can be defined in type arguments or method header (of a global or local function).

8.3. Grouping types

primary_type ::=
( type )

This construct has no semantic meaning -- it exists only to enforce particular syntax decomposition.

8.4. Void type

primary_type ::=
void

This is mostly an alias for System.Void -- a type with exactly one inhibiting value. It is, however, a first class value -- it can be passed as a function parameter as well as returned from functions.

The name comes from System.Void, but should be in fact unit.

8.5. Ref and Out types

primary_type ::=
primary_type ::=

These are for parameters passed by reference.

8.6. Array types

primary_type ::=
array < [ NUMBER_LITERAL , ] type >

Define array type. The number is the rank. It defaults to one.

8.7. Tuple type

type ::=

Construct product (tuple) type. This operator is not associative, which means that each two of following types are different:

int * int * int
(int * int) * int
int * (int * int)

8.8. Function type

type ::=
type -> type

Construct function type with a specified argument and return types respectively. The -> operator is right associative, which means that the following types are equivalent:

int -> int -> int
int -> (int -> int)

Multi-argument function types are written using tuple notation, for example after local declaration:

def some_function (a : int, b : string) : float { ... }

the expression some_function has type int * string -> float.

9. Literal expressions

These are used in expressions and patterns.

9.1. Boolean

literal ::=
true
literal ::=
false

These literals have type bool and represent respectively true (false) boolean value.

9.2. Null

literal ::=
null

Represents null reference, one that does not refer to any object. It possesses types of all reference types -- can be used in any context reference type is required. It does not, however, possess the void type nor any value type (like System.Int32 or System.Single).

9.3. Void

literal ::=
( )

Indicates returning no value. It is the only possible value of type void. See also void type.

9.4. String

literal ::=
STRING_LITERAL

Represents string constant. Nemerle supports two forms of string:

A regular string literal consists of zero or more characters enclosed in double quotes and may include both simple escape sequences (such as \n for the newline character) and hexadecimal and Unicode escape sequences (See character literals for details).

A verbatim string literal consists of an @ character followed by a double-quote character, zero or more characters, and a closing double-quote character. In a verbatim string literal, the characters between the double-quotes are recognized verbatim, the only exception is a sequence "" (used to indicate '"' character) (Note that simple escape sequences and hexadecimal and Unicode escape sequences are not recognized in verbatim string literals). A verbatim string literal may span multiple lines.

Examples:

def s1 = "Nemerle string !";            // Nemerle string !
def s2 = @"Nemerle string !";           // Nemerle string !
def s3 = "Nemerle\tstring !";           // Nemerle    string !
def s4 = @"Nemerle\tstring !";          // Nemerle\tstring !
def s5 = "I heard \"zonk !\"";          // I heard "zonk !"
def s6 = @"I heard ""zonk !""";         // I heard "zonk !"
def s7 = "\\\\trunk\\ncc\\ncc.exe";     // \\trunk\ncc\ncc.exe
def s8 = @"\\trunk\ncc\ncc.exe";        // \\trunk\ncc\ncc.exe
def s9 = "\"Nemerle\"\nstring\n!";      // "Nemerle"
                                        // string
                                        // !
def s10 = @"""Nemerle""                 // same as s9
rocks
!";

String s10 is a verbatim string literal that spans 3 lines.

9.5. Number

literal ::=
NUMBER_LITERAL

Represents one of numeric types. See literals for details of representing particular numerical types.

9.6. Character

literal ::=
CHARACTER_LITERAL

A character literal consists of one character enclosed in single-quotes (' ') or escape character of form '\X' where X can be one of the following: [FIXME: characters with (N) are not implemented yet (will they?)]

It has type char.

10. Primary expressions

Primary expressions are a grammar category referring to expressions that have a closed structure and are otherwise simple. Primary expressions and plain expressions do not differ at the semantic level.

10.1. Literal expression

primary_expr ::=

The value and type of an expression being literal is the value and the type of the respective literal.

10.2. Variable reference

primary_expr ::=

This expression result is a variable itself (not its value). [[FIXME: hem?!]] Type of this expression is ref 'a where 'a is a type of variable being referenced.

10.3. this pointer reference

primary_expr ::=
this

This expression can only be used within non-static methods and indicates a reference to the current instance of the class (which posses this method).

Expression like this.foo can be shortened to foo unless it would generate an identifier ambiguity with some variable being in this lexical scope.

The this keyword can be also used to call instance constructor from another constructor.

10.4. base pointer reference

primary_expr ::=
base

This expression can only be used within non-static methods and indicates a reference to the current instance of the class coerced to the type of the base class. Calls made on base pointer are non virtual.

The base keyword can be also used to call instance constructor of base class from another constructor.

10.5. Grouping expression

primary_expr ::=
( expr )

A grouping expression allows to enforce particular syntax decomposition of expression.

10.6. Member reference

primary_expr ::=
primary_expr . IDENTIFIER

This expression allows referring to the field or method that the object represented by primary_expr contains.

10.7. Tuple constructor

primary_expr ::=
( expr { , expr }+ )

This expression allows creating a tuple of expr whose types may differ. The type of that tuple is type_1 * ... * type_n where type_1 and the following are types of corresponding expressions.

10.8. Indexer reference

primary_expr ::=
expr [ expr { , expr } ]

This expression allows to refer to indexed (even by multiple indexes) fields of objects represented by leftmost expr where second (and further) expr are indexes values of the field we want to refer to. expr must refer to an indexing object.

11. Core Expressions

11.1. Primary expression

expr ::=

The value and type are the same as primary_expr we are referring to.

11.2. Function call

expr ::=

Call a function with given parameters. The type of the function call expression is the same as the type of the function return value; that is, if the function's type is 'a -> 'b, then the type of the function call expression is 'b. The value of the whole expression is the return value of the function.

11.3. Assignment

expr ::=

Assign a value to a variable. The left side of the assignment expression must evaluate to a mutable variable. The type of the assignment is always void.

In earlier versions there was <- assignment operator, which is now (Nemerle 0.2.x) deprecated.

11.4. Match expression

expr ::=
match ( expr ) { [ | ] match_case { | match_case } }

expr is matched sequentially to the patterns in given match cases. If one of the patterns is consistent with the value of expr, then the corresponding computation branch of the match case is evaluated. Patterns in all the match cases must be of the same type. Expressions being computation branches in all the match cases must be of the same type, as well. The type of the match expression is the same as the type of the computation branch in all the match cases.

11.5. Throw expression

expr ::=
throw expr

Throws given exception. The expression given must be of type System.Exception.

11.6. Try..catch expression

expr ::=
try block catch { [ | ] try_catch_handler { | try_catch_handler } } [ finally block ]

If the evaluation of expr does not throw any exception, then the result is that of the evaluation of expr. Otherwise, the runtime type of the exception which was thrown is compared against each type description in handlers. The first matching handler is executed and its value returned. If none of the handlers matches, the exception is propagated. The type of the whole expression is the same as type of guarded expression. The value is the value of expression or launched handler. Consult .NET specification if you want to know more about exceptions.

The optional finally clause has the same meaning as below.

11.7. Try..finally expression

expr ::=
try block finally block

Evaluates the first expression and -- regardless of whether the evaluation has finished correctly or some exception has been thrown during the evaluation -- the second expression is evaluated. The value (and thus the type) of the whole expression is the value of the first expression.

11.8. Unary operator application

expr ::=
OPERATOR expr

11.9. Binary operator application

expr ::=
expr OPERATOR expr

11.10. Type cast

expr ::=
expr :> type

This expression allows dynamic type coercion. It is done during runtime and if it cannot be realized then System.InvalidCastException is thrown. If it succeeds, the type of this expression is equal to the type of type.

11.11. Type enforcement

expr ::=

This expression allows static type enforcement. It is checked during compile-time and an error is reported if expr type is not a subtype of type. It allows only type widening. If it succeeds, the type of this expression is equal to the type of type.

11.12. One-case matching

expr ::=
expr matches pattern

Equivalent to match (expr) { pattern => true | _ => false }.

11.13. Dynamic type check

expr ::=
expr is type

Equivalent to expr matches _ : type.

11.14. checked/unchecked blocks

expr ::=
checked expr
expr ::=
unchecked expr

Turn on/off overflow checking for arithmetic operators. Checks are on by default.

11.15. Block expression

expr ::=

The value (and thus the type) of the whole expression is the value of the last expression in the sequence.

11.16. Array constructor

expr ::=
array [ < NUMBER_LITERAL > ] [ [ { expr , } expr ] ]

Create an array consisting of given elements. All elements must be of the same type. If the elements are of the type 'a then the whole expression is of the type array ('a).

The number in <> is array rank. It defaults to 1. If rank is specified, rows, columns and so on are specified using nested [], like in:

array <2> [[1, 2], [3, 4], [5, 6]]
array <3> [[[1, 2], [10, 20]], [[11, 12], [110, 120]]]

11.17. Value definition

expr ::=
def pattern = expr

Defines the binding between the variables in the pattern and the value of the expression expr which will be known to all subsequent expressions in the current block.

11.18. Local function definition

expr ::=

Defines the functions which will be known to all subsequent expressions in the current block. Names of all defined functions are put into the symbol space before their bodies are parsed.

11.19. Mutable value definition

expr ::=
mutable IDENTIFIER = expr

Defines a new variable, value of which can be changed at any time using the assignment expression.

12. Secondary Expressions

This section describes expressions that are in fact just syntactic sugar over Core Expressions. We just present a translation of Secondary Expressions into Core Expressions.

12.1. Conditional expression

expr ::=
if ( expr ) expr else expr

A standard branch, which executes and returns value of first expression if the condition evaluates to true or second elsewhere.

Internally it is translated into

match (cond) {
  | true => expr1
  | false => expr2
}

12.2. While loop

expr ::=
while ( expr ) expr

A loop, executing body expression as long as the condition is true. Its value is always checked before the execution of body and if it evaluates to false, then the loop ends.The body must be of type void.

The loop is translated internally into the following code

def loop () {
  if (cond) 
    { body; loop () }
  else
    ()
};
loop ()

12.3. do ... while loop

expr ::=
do expr while ( expr )

This loop is similar to while loop, but body is executed before the first time the condition is checked.

12.4. When expression

expr ::=
when ( expr ) expr

A version of the if condition, but having only one branch -- execution of body only when the condition is satisfied. If its value if false, then nothing is done (i. e. () is returned).

Its semantics is the same as

if (cond) body else ()

12.5. Unless expression

expr ::=
unless ( expr ) expr

An opposite version of when. It executes and returns value of body only if conditions are not satisfied (i. e. evaluates to false).

Its semantics is the same as

if (cond) () else body

12.6. Lambda expression

expr ::=

Lambda expressions can be thought as of anonymous local functions. This construct defines such a function and returns it as a functional value. This value can be used just like the name of a regular local function.

Example:

List.Iter (fun (x) { printf ("%d\n", x) }, intList)

is equivalent to

def tmpfunc (x) { printf ("%d\n", x) };
List.Iter (tmpfunc, intList)

Lambda expression is actually translated internally to

expr ::=

where temporary_name is automatically created by the compiler.

12.7. List constructor

expr ::=
[ [ { expr , } expr ] ]

[1, 2, 3] is translated to Cons (1, Cons (2, Cons (3, Nil ()))).

12.8. Increment operator

expr ::=
++ expr

Prefix operator ++ is used to increment integer value of assignable expression. It is translated to something similar to e = e + 1, except that e is evaluated only once, so ++a[x.Next()] can be used safely. The entire expression has type void (the incremented value is not returned).

12.9. Decrement operator

expr ::=
-- expr

Prefix operator -- is used to increment integer value of assignable expression. It is translated to something similar to e = e - 1, except that e is evaluated only once, so --a[x.Next()] can be used safely. The entire expression has type void (the decremented value is not returned).

12.10. Swap operator

expr ::=
expr <-> expr

Infix operator <-> is used to swap values of two assignable expressions. You can think about it as being translated to

def temp = e1;
e2 = e1;
e1 = e2

except that expressions are evaluated only once (there is a special macro to assure this), so a[x.Next()] <-> a[x.Next()] can be used safely.

13. Expression helpers

This section describes some constructs used in Expressions section.

13.1. Sequence

sequence ::=
expr { ; expr } [ ; ]

Expressions in the sequence are evaluated sequentially, and the value (and thus the type) of the sequence is the value of the last expression in the sequence.

Values of expression (except for the last one) are ignored, and thus if the type of some expression is not void -- a warning is generated.

The ; is optional after after } inside a sequence.

13.2. Block

block ::=
{ sequence }

This is just a standard execution of a sequence of expressions. The value (and type) of this block is the same as the last expression in the sequence.

block ::=

This syntax is a shortcut for matching parameters of a defined function with a given list of patterns. It is equivalent to making a tuple from parameters of function and creating match expression.

def f (p1, p2, p3) { 
  | (1, 3, "a") => 1
  | _ => 2
}

translates to

def f (p1, p2, p3) { 
  match ((p1, p2, p3)) {
    | (1, 3, "a") => 1
    | _ => 2
  }
}

It is also to note that when a function has only one parameter, the matching goes just on this parameter itself (no one-element tuple is created).

13.3. Try..catch handler

try_catch_handler ::=

13.4. Function parameter

parameter ::=
[ ref ] expr
parameter ::=
[ out ] expr

parameter ::=
[ ref ] IDENTIFIER = expr
parameter ::=
[ out ] IDENTIFIER = expr

ref and out are used to denote a parameter passed by reference.

13.5. Match case

guarded_pattern ::=
pattern [ when expr ]

A guarded pattern requires expression expr to be of type bool. An expression e satisfies the guarded pattern only if it is pattern-matched with pattern and expression expr is evaluated to true.

match_case ::=

An expression e satisfies this match case if and only if it satisfies one of the guarded patterns in this match case.

14. Patterns

Patterns are a form of accessing data structures, especially trees. Patterns can match values. A definition of the term to match is given with each pattern construct. However, the main idea behind patterns is that they match values that look like them.

Pattern are used in match expression and value definitions.

14.1. Constructor pattern

pattern ::=

The identifier should refer to the name of variant option. This pattern matches a value if it is a specified variant option, and sub-pattern matches variant option payload.

14.2. Throw-away pattern

pattern ::=
_

This pattern matches any value.

14.3. Record pattern

pattern ::=
{ IDENTIFIER = pattern { ; IDENTIFIER = pattern } [ ; ] }

This pattern matches a value of a class, that has all specified fields (this is checked statically), and a value of each field matches respective pattern.

14.4. As binding

pattern ::=
( pattern ) as IDENTIFIER

This pattern matches the same value as an enclosed pattern does. However, in addition the value matched by the enclosed pattern is bound to a specified variable, which can be used in when guard or match body.

14.5. Type-check pattern

pattern ::=
IDENTIFIER : type

This pattern matches a value if it possesses a given type. In addition, the value matched is bound to a specified variable, which gets the given type.

This pattern can be used both for checking the type and hinting the type checker (if the value is statically known to always have given type no runtime checks are performed).

14.6. Tuple pattern

pattern ::=
( pattern { , pattern } )

This pattern matches a tuple with specified contents (each tuple member is matched be respective pattern).

In addition, when a tuple pattern is seen, where a record pattern would be otherwise expected -- the tuple pattern is transformed to record pattern by adding field identifiers in order they appear in the definition of the given class. A tuple pattern transformed to a record pattern cannot match fields inherited from the base class.

14.7. List constructor pattern

pattern ::=

The following two lines are equivalent:

pattern1 :: pattern2
Cons (pattern1, pattern2)

14.8. List literal pattern

pattern ::=
[ [ { pattern , } pattern [ , ] ] ]

The following are equivalent:

[ pattern1 , pattern2 , ... , patternN ]
Cons (pattern1, Cons (pattern2, ... Cons (pattern2, Nil) ... ))

14.9. Literal pattern

pattern ::=

This pattern matches a specified constant value.

15. Macros

Please refer to macros.html for now.