You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A function value stored in a variable has one type, like any variable, so calling it with different argument types is an error:
let id = fn(x) => x;
id(1);
id("a"); // error: id holds a function that doesn't accept String
let f = len;
f("abc");
f([1]); // error: f holds a function that doesn't accept List<Int>
An overloaded name used as a value is picked by the type expected where it's used (#246, #217), so a list of overloaded functions of different types can't be written either: [len, abs] has to say which abs is meant.
Today, declaring the function with fn (top-level fns are generic) or annotating the variable Any works around it.
Possible directions:
Generic let lambdas: a let lambda that's never reassigned is generic like a top-level fn (ML-style let-generalisation), reusing the generic-function instances.
Overload sets as values: a value that keeps all of a name's overloads and picks one at each call, statically where the call's types are known. This would also let [len, abs] and let f = len work, but needs a new kind of value in the VM and the type system, and an answer to what xs.map(f) passes when f is a set.
Activity