-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve overload resolution for generics and templates #346
Comments
I have a better proposal: let people = @[(name: "Sarah"), (name: "Jim")]
echo people.sortBy((v) => v.name)
echo people.sortBy(name) # CT error
echo people.sortBy(name.untyped) # ok explicit is better than implicit when it comes to
See also nim-lang/Nim#17196 which will reduce need for |
We can easily do both, it's certainly bad that |
untyped
in generics and templates
One more use case, currently it's impossible to override func find[T](list: openarray[T], check: (T) -> bool, start = 0): int =
if start <= (list.len - 1):
for i in start..(list.len - 1):
if check(list[i]): return i
-1
assert @[(name: "Jim")].find((u) => u.name == "Jim") == 0 |
When multiple routines match the call - Nim tries to find the proc with the best match.
It could be improved, explicit type should have priority over generic type and generic over
untyped
.With this improvement it would be possible to combine generic and non generic procs and templates. And it should be a cheap check and not slow down the compilation.
Example:
playground
Details about Overloading resolution in Manual.
The text was updated successfully, but these errors were encountered: