D array expansion and non-deterministic re-allocation

Bartosz Milewski bartosz-nospam at relisoft.com
Thu Nov 19 15:21:43 PST 2009


Steven Schveighoffer Wrote:

> I wonder what your expert opinion is:  Is something like unique possible  
> without introducing all the other type modifiers (like 'lent', etc.)?  If  
> not, what are the minimum type modifiers you'd need to get unique to  
> work?  I really like the unique concept, and think it is really one of the  
> biggest holes missing from the const system (aside from bug 1961).

The most complete description of "unique" that I've seen is in Haller/Odersky Scala paper "Capabilities for External Uniqueness." It's not an easy paper to read, but I'm planning on writing a blog post in which I'll try to make it more palatable. They use annotations to extend the type system, something that was pioneered in Java. The recent introduction of annotations (like @property) in D makes this approach quite attractive. They used the following annotations: @unique, @transient, and @exposed (@transient loosely corresponds to "lent").

Don't get me wrong, the full specification of uniqueness is non-trivial and I wouldn't propose it for D just to solve the array expansion problem. The real power of "unique" shows in multithreaded programming where you can pass unique objects between threads and safely operate on them without any synchronization. 




More information about the Digitalmars-d mailing list