Generic function annotations allow functions to implement generic types. Follows #84 and #85.
func lessThan1<U> implements Comparator1 (a: U, b: U): int {
; % ...
}
func lessThan2 implements Comparator2.<float> (a: float, b: float): int {
; % ...
}
The only thing to remember here is that the generic parameters of a function declaration come right after the function name, before the implements clause. This allows us to use the parameter as an argument of the annotation, if needed.
type Voider<A, B> = (A, B) => void;
func myFunction<T> implements Voider.<str, T> (x: str, y: T): void {
% ^ generic parameter is here, on the function name
;
}
myFunction.<bool>('hello', false);
myFunction.<int>('hello', 42);
The function myFunction above has a generic parameter, which is required whenever the function is called. That parameter also happens to be used as an argument of the Voider generic type.
Generic function annotations allow functions to implement generic types. Follows #84 and #85.
The only thing to remember here is that the generic parameters of a function declaration come right after the function name, before the
implements
clause. This allows us to use the parameter as an argument of the annotation, if needed.The function
myFunction
above has a generic parameter, which is required whenever the function is called. That parameter also happens to be used as an argument of theVoider
generic type.More examples:
And as mentioned in #84, functions that have an
implements
clause don’t need to have explicit parameter/return types written.