▲ | ValentinA23 2 hours ago | |||||||
I'm wondering if a language could optimize immutable data structures to use mutable, in place semantics instead of duplication or structural sharing when it is possible. When an immutable data structure only has one consumer (only has one descendant in the flow graph), then it can easily be turned into a mutable version. Generalizing, any linear subgraph in the program's flow graph could be made to use in place semantics on the same mutable variable. The challenge I guess is figuring out how variables captures by lambdas should be dealt with. | ||||||||
▲ | masijo an hour ago | parent | next [-] | |||||||
This is how Clojure does it, take a look at this: https://clojure.org/reference/transients It's great, one of the many awesome features Clojure has. | ||||||||
▲ | zvrba an hour ago | parent | prev | next [-] | |||||||
I implemented an academic paper (join tree) in C# here https://github.com/zvrba/Pfm It provides the opposite: a mutable CoW data structure that is extremely cheap to "fork" so that all subsequent updates occur only on the new "fork" and are invisible to the old "fork". | ||||||||
| ||||||||
▲ | zellyn an hour ago | parent | prev [-] | |||||||
This is the bet Roc is taking. They call it "Opportunistic Mutation" and you can read about it at https://www.roc-lang.org/functional I didn't see links on that page, but IIRC, there's a particular paper they reference as the main idea. |