4 Replies
Yes. Here is an example https://github.com/Mojo-Numerics-and-Algorithms-group/NuMojo/blob/main/numojo/traits/backend.mojo.
The main limitations of trait that I have run into are you can't parameterize at the trait level
trait ball[color:Color]:
, nor can you require fields to exist in conformant structs.Ah. I just needed to update to the latest nightly.
Edit: Actually, that was not the fix. I was trying to specialize in the type definition, but specialization occurs at the point of invocation, so the trait requirements have to be duplicated exactly in the type.
It does 😄
If you ever wonder, just run it in the playground: https://docs.modular.com/mojo/playground