Type expressions (ref)
From Nemerle Homepage
Contents |
Intro
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.
Type constructor application
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.
Type variable reference
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).
Grouping types
This construct has no semantic meaning -- it exists only to enforce
particular syntax decomposition.
Void type
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.
Ref and Out types
These are for parameters passed by reference.
Array types
Define array type. The number is the rank. It defaults to one.
Tuple 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)
Function 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.