Generics
Closed this issue · 0 comments
prakhar1989 commented
Strategy for type-checking generics
Decisions
- For generic functions at the time of declaration, only typecheck signature and not bodies.
- Calls to generic functions, requires concrete type-resolution to be done apriori.
- Cannot pass generic functions are arguments.
val num_to_sign = /\(x: num): string => {
if (x >= 0) then "non-negative" else "negative";
};
val bool_to_string = /\(x: bool): string => {
if x then "true" else "false";
};
val apply = /\[T, U](fn: (T) -> U, x: T): U => {
fn(x);
};
val is_positive = apply(num_to_sign, -10);
val to_string = apply(bool_to_string, 10 == 10);