Generic objects can be defined using the for <T, ...> clause on any top level declaration.
This creates a generic type declaration. Generic types aren't actually translated to code directly. For compound types, any time a initialization process is called for a generic type, an implementation is generated that metamorphosizes the original declaration for the new types. For functions, this occurs anytime the function is called.
An instance can be declared for a generic type with invariance, contravariance, and covariance using the follow syntax:
Type<T> for invariance
Type<? : T> for covariance
Type<T : ?> for contravariance
Generic declarations can have bounds, like so:
for<T : Object>.
This is also the default bound.
Extended Implementation
Variable Length parameters
Enable multiple generic implementations per a single type based on number of arguments. For example for <T> class type and for <T, R> class type will be two separate implementations of the same type.
In addition, generics can have variadic argument in the last position using the following form:
for <T1, T2, ..., Tn, (HD:TL) (: bound)?>. The HD declaration is the first type parameter in the list, the TL part represents everything else. Both arguments can be empty. If the HD or TL is placed after a comma, but it is empty, the comma is ignored in terms of parameter count.
The following is can example of a use case for this:
for <R, (HD:TL)> class fn {
private fn<fn<R : ?, ? : TL>, HD> next;
public R enact(HD arg1, args...) {
fn<R : ?, ? : TL> func = next->enact(args1);
return func(args);
}
}
for <R> class fn {
public R enact();
}
Minimum Implementation
Generic objects can be defined using the
for <T, ...>
clause on any top level declaration. This creates a generic type declaration. Generic types aren't actually translated to code directly. For compound types, any time a initialization process is called for a generic type, an implementation is generated that metamorphosizes the original declaration for the new types. For functions, this occurs anytime the function is called.An instance can be declared for a generic type with invariance, contravariance, and covariance using the follow syntax:
Type<T>
for invarianceType<? : T>
for covarianceType<T : ?>
for contravarianceGeneric declarations can have bounds, like so:
for<T : Object>
. This is also the default bound.Extended Implementation
Variable Length parameters
Enable multiple generic implementations per a single type based on number of arguments. For example
for <T> class type
andfor <T, R> class type
will be two separate implementations of the same type. In addition, generics can have variadic argument in the last position using the following form:for <T1, T2, ..., Tn, (HD:TL) (: bound)?>
. The HD declaration is the first type parameter in the list, the TL part represents everything else. Both arguments can be empty. If the HD or TL is placed after a comma, but it is empty, the comma is ignored in terms of parameter count. The following is can example of a use case for this: