Immutable and unique in C#

Walter Bright newshound2 at digitalmars.com
Mon Nov 12 15:46:25 PST 2012


On 11/9/2012 5:53 AM, Sönke Ludwig wrote:
> Independent of this article I think D is currently missing out a lot by
> omitting a proper unique type (a _proper_ library solution would be a
> start, but I'm not sure if that can handle all details). It would make a
> lot of the cases work that are currently simply not practical because of
> loads of casts that are necessary.

Unique as a type qualifier comes with all kinds of subtle problems. For one 
thing, unique is more of a property of an expression rather than a property of 
the type.

But I was thinking - what if it's a storage class? Like ref is? Working through 
the use cases in my head, I think it can work. Unique being a property of an 
expression, this can be tested upon assignment to the unique variable. Upon 
reading that unique variable, the value of it is erased.

Function parameters can be qualified with "unique" as well, meaning their 
corresponding arguments can only be unique expressions.



More information about the Digitalmars-d mailing list