Type declarations (ref)

From Nemerle Homepage

<< Back to Reference Manual.

Contents

Type header

<type_header> ::=

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

<type_attributes> ::=
    <attributes>


Type parameters

<type_parameters> ::=
    '[' <IDENTIFIER> { ',' <IDENTIFIER> } ']'
<where_constraints> ::=
    { 'where' <IDENTIFIER> ':' <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.

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

Declarations

<type_declaration> ::=
    <type_alias>


Type alias

<type_alias> ::=
    <type_attributes> 'type' <type_header> '=' <type> ';'


Much like typedef in C.

Interface

<interface_declaration> ::=
    <type_attributes> 'interface' <type_header> '{' { <interface_member> } '}'


Class like

<class_like_declaration> ::=
    <type_attributes> 'class' <type_header> '{' { <type_member> } '}'
|   <type_attributes> 'struct' <type_header> '{' { <type_member> } '}'
|   <type_attributes> 'module' <type_header> '{' { <type_member> } '}'


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.

Struct types are like classes, but they are passed by value and cannot inherit from other types.

Variants

<variant_declaration> ::=
    <type_attributes> 'variant' <type_header> '{' { <variant_option> } '}'
<variant_option> ::=
    '|' <IDENTIFIER> [ '{' { <field_definition> } '}' ]


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

The variant option describes the constructor associated with this variant type. An option may take an argument. Option name must be capitalized.

Variants (unlike variant options) can also have other members (methods and fields). These fields and methods are inherited by all the options.

Enums

<enum_declaration> ::=
    <type_attributes> 'enum' <type_header> '{' { '|' <IDENTIFIER> [ '=' <literal> ] } '}'


Enums are like variants, but cannot take arguments. They are passed by value and can be used with bitwise operations.

Delegates

<delegate_declaration> ::=

remember
You are very welcome to contribute to the documentation here!