Replies: 2 comments 12 replies
-
What I referred to is actually present in the road map, see ⏬⬇️ https://docs.modular.com/mojo/roadmap.html#traits-support We plan to expand traits support in future releases. Planned features include: More traits built in to the standard library, and expanded use of traits throughout the standard library. Support for default implementations of required methods. Support for a feature like Swift’s extensions, allowing you to add a trait to a preexisting type. |
Beta Was this translation helpful? Give feedback.
-
Swift's |
Beta Was this translation helpful? Give feedback.
-
I could not find this on the roadmap, so I proceeded to creare an idea as suggested.
Probably related to the issue about union types: #43.
Hello, these days I tried out Mojo and I liked it a lot.
However, when I started writing some sort of "hello world" program, I found myself into trouble when implementing a function to print the elements of a
DynamicVector
. E.g.:Clearly,
print_no_newline(v[i])
fails at compile time asv[i]
is notStringable
.The perfection for me would have been something like this:
Very similar to what happens already in typescript.
Here I add all the code I needed to achieve the final result:
Also note that I had to wrap
Int
to achieve the result, quite inconvenient.I think this would be already covered by a part of your roadmap: Support for a feature like Swift’s extensions, allowing you to add a trait to a preexisting type. If this is available, I could have implemented
Stringable
forInt
withoutMyInt
, still the intersection type would have been needed.If I may ask also, why like Swift's extensions and not as it happens in Rust? Do you think that those are equivalent?
Beta Was this translation helpful? Give feedback.
All reactions