bearophile Wrote: > This post contains uncooked ideas. > > I'd like to create data structures: > - That once created are immutable, so there is no risk to write on them, etc; > - On the stack too, avoiding slower heap allocations and avoiding copying > them from the mutable to the immutable version; > - Avoiding to keep in the function name space a dead name of the mutable > version of the data structure; > - Avoiding calls to functions that may contain loops that DMD doesn't inline; > - Avoiding too much complex code for the programmer.
There was talk in the past of allowing a pure function create and modify a class and return that class as immutable. This was a suggestion on how to create immutable classes. The details were never really hashed out, but maybe it is possible for any returned value (of a pure function) to be implicitly converted to immutable. To me it sounds really nice an clean, do you think it would work for you?
