mojo
mojo copied to clipboard
Traits, overlapping instances and lessons from Julia/Dex[Feature Request]
Review Mojo's priorities
- [X] I have read the roadmap and priorities and I believe this request falls within the priorities.
What is your request?
A trait/protocol system that allows for resolution of overlapping instances.
What is your motivation for this change?
This is part of Julia's secret sauce. Julia's nominal single inheritance abstract type system isn't strictly inferior to most trait/protocol/typelcass systems that permit post hoc associations with multiple types because it allows for the existence of multiple overlapping types and instances. This is crucial for generic, parametric algorithms and is a critical component of Julia's power, along with multiple dispatch.
A system which allows inheriting association with multiple kinds/traits/types but also has some overlap resolution (as opposed to just disallowing them) would be very powerful, but also potentially intractable.
Any other details?
For related discussion and explication, including lessons from Julia: https://github.com/google-research/dex-lang/issues/671
Demonstrations of power: https://www.youtube.com/watch?v=kc9HwsxE1OY
Julia shows that it's likely overloading needs to be co-designed with traits. There's some nuance between overloading and compile time resolution of dynamic dispatch. The former, which is in swift, seems to preclude the kind of generic but zero cost code in julia: https://forums.swift.org/t/operator-overloading-with-generics/34904
So it seems that designing overloading (even if single dispatch) to account for that would be important for any overlapping trait system to be fully actualized. The Julia video again demonstrates this.
this makes sense, we'll need to build out the initial traits system first, but this is the sort of thing I expect our implementation to support.
Going to close this for now since it seems more in line with a discussion. Traits are planned on the roadmap.