-
Notifications
You must be signed in to change notification settings - Fork 90
Type declarations (ref)
type_header =
Lexical_structure_(ref):IDENTIFIER [ type_parameters ]
[ ':' Type_expressions_(ref):type { ',' type } ] where_constraints type_attributes = Attributes_(ref):attributestype_parameters =
'[' Lexical_structure_(ref):IDENTIFIER { ',' IDENTIFIER } ']'
where_constraints =
{ 'where' Lexical_structure_(ref):IDENTIFIER ':' Type_expressions_(ref):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.IDictionarytype_declaration =
type_alias
| interface_declaration
| class_like_declaration
| variant_declaration
| enum_declaration
| delegate_declarationtype_alias =
type_attributes 'type' type_header '=' Type_expressions_(ref):type ';'Much like typedef in C.
interface_declaration =
type_attributes 'interface' type_header '{' { interface_member } '}'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.
variant_declaration =
type_attributes 'variant' type_header '{' { variant_option } '}'
variant_option =
'|' Lexical_structure_(ref):IDENTIFIER [ '{' {
Type_members_(ref):field_definition } '}' ]
| Type_members_(ref):type_memberA 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.
enum_declaration =
type_attributes 'enum' type_header '{' {
'|' Lexical_structure_(ref):IDENTIFIER [ '=' Lexical_structure_(ref):literal ] } '}'Enums are like variants, but cannot take arguments. They are passed by value and can be used with bitwise operations.
delegate_declaration =
type_attributes 'delegate' Type_members_(ref):method_header