-
Notifications
You must be signed in to change notification settings - Fork 13.4k
pseudo-overloading functions with enums #1838
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
Comments
This looks like a poster-child use-case for impls. Wouldn't that be a much simpler and more efficient way to do it?
|
Using boxed iface values, they can. |
Yes, I know... what I meant is, you can't write it that way. We'd have to auto-coerce to a boxed iface. I think that so long as boxed iface allocations require allocation this isn't such a good idea, but maybe with #1567 it would be more reasonable. |
Looks like "revisit this when #1567 is done" to me. |
This bug is effectively asking for implicit-conversion operators. At the point we're at now, I'm .. pretty disinterested in those as a feature; they have a lot of expressive power but they interact with a lot of already-overcomplex pieces of the language. Also, IME they tend to bring a lot of headache to maintenance programmers / readers when trying to figure out what code does (for example, in C++). I think we have a bunch of reasonable ways of doing polymorphic code now that are not too painful, and could grow more (for example, I think we're nearly at the point of being able to write the |
Co-authored-by: Celina G. Val <[email protected]>
I've been working on a couple different serialization libraries, and I often find taking advantage of enum variants living in a different namespace than types. It's really nice to declare:
But calling these functions can get a bit noisy, especially when using arrays:
I'm not sure if we're planning on supporting overloading functions, but what if the type system could automatically box arguments if an enum name is the same as the type? As in allowing us to write:
and automatically convert it to the boxed form from above. I'm not sure if this would play well with generics or typeclasses, but it'd really clean up some code I'm writing. Is this possible, or even a good idea?
The text was updated successfully, but these errors were encountered: