Features of the routine type can be generic. That means they can be defined with type parameters that need to be replaced by actual types when the feature is called.
Generic List Example
Here is the list example from section References
generic type parameters. These type parameters are then used to create a list
i32 elements and a list of
Compatibility of Generic Types
Two types that differ only in the actual generic parameters are incompatible
in Fuzion. This means, e.g., that a value of
Array<String> cannot be assigned to a field of
Array<Object>. This avoids run-time errors such as the
ArrayStoreException found in Java.
Constrained Generic Types
TBW: Generic type constraints are not supported yet.
Open Generic Types
Fuzion allows the definition of open generic types, i.e., generic types that can be replaced by an arbitrary number of actual generic types. Open Generic types are seldom useful in application code, but they provide a powerful mechanism to define Choice Types , Functions and Tuples using generic Fuzion features.
As an example from the standard library, this is the code for a
Function(R type, A type...) ref is call(a A) R is abstract
Function declares an abstract feature
returns a result of type
R specified as a generic argument and that
receives zero or more arguments defined by the open generic
Fields of an open generic type can be accessed for instances with actual
generic parameters that are not open. Since there might be an arbitrary number
of actual generic types, there might be an arbitrary number of such
fields. Field accesses therefore require
.1, etc. to select the field
corresponding to the first, second, etc. actual generic argument See
for an example of how this is done.