mojo icon indicating copy to clipboard operation
mojo copied to clipboard

Traits, overlapping instances and lessons from Julia/Dex[Feature Request]

Open AriMKatz opened this issue 1 year ago • 1 comments

Review Mojo's 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.

AriMKatz avatar Jun 01 '23 14:06 AriMKatz

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.

lattner avatar Jun 02 '23 18:06 lattner

Going to close this for now since it seems more in line with a discussion. Traits are planned on the roadmap.

Mogball avatar Jun 05 '23 21:06 Mogball