Replies: 3 comments 4 replies
-
The given example would be supported even if the collection was not immutable. Swift uses “value types” which are similar to Immutable Data Structures, and I would expect something similar in Mojo. In Swift, these types use a “copy on write” mechanic to minimize unnecessary copying. Still, Swift doesn’t help much if you write code that could cause many copies of large amounts of data. There’s also the opportunity to support Persistent Immutable Data Structures that use trees internally to minimize the cost of “copies”, by “structural sharing”. However, the trade-off is that all operations are a bit slower. Considering the fact that Mojo is being made primary for Machine Learning tasks, I’m not sure if Persistent Data Structures would be particularly useful. Happy to be wrong about that though! Using some of the lessons from Swift’s value types, Mojo could implement Persistent Data Structures that are better than what usually exists out in the world today. Mojo could smartly do in-place mutations when it wouldn’t cause side-effects, but do shallow copies otherwise. Roc-lang is a great example of another language that supports Persistent data structures with extremely high performance! |
Beta Was this translation helpful? Give feedback.
-
I think given that Mojo supports ownership, mutable non-persistent data structures like Rust's make a lot of sense since you can guarantee that there is no sharing to support safe and efficient in-place updates. |
Beta Was this translation helpful? Give feedback.
-
I'd say if Mojo is meant to be truly general, including persistent data structures in some sort of library would be pretty important. I come from a Clojure background and it makes life so much easier. I foresee it being tricky/less-performant in a non-GC context though. |
Beta Was this translation helpful? Give feedback.
-
Scala has by far one of the most pleasant collections library (which is immutable by default) that I have ever used
If a similar implementation could be implemented in the std lib with the following syntax:
that would be awesome
Beta Was this translation helpful? Give feedback.
All reactions