I want to create my own Tuple type
Ola Fosheim Grøstad
ola.fosheim.grostad at gmail.com
Mon Jan 11 20:14:51 UTC 2021
On Monday, 11 January 2021 at 19:25:06 UTC, Paul Backus wrote:
> On Monday, 11 January 2021 at 18:02:19 UTC, Ola Fosheim Grøstad
> wrote:
>> On Monday, 11 January 2021 at 17:48:13 UTC, Paul Backus wrote:
>>> Why? I'd say that an `immutable(Tuple)` should be immutable,
>>> and a `Tuple` should be mutable, as is the case with
>>> literally every other type in D.
>>
>> Tuples are usually immutable, it brings more correctness.
>
> I agree that immutability has benefits, but I don't see why
> tuples should be singled out for special treatment in this
> regard. Why is immutability more important for tuples than for
> any other kind of data?
Well, maybe not more important, but at least consistent with
mathematics. :-)
I guess my real reason is that I am not ready to reimplement the
type system and add one-level "readonly" semantics to the
language at this point, so just preventing writable reference
from leaking out seems one temporary approach that could work.
What I don't want is to have a tuple accidentally modified, so if
one wants to modify the tuple then one should bind it to
variables through destructuring? I guess that is a good reason?
The caller of a function can decide to set up the return value
from a function for mutation by destructuring the tuple.
I guess that would be the "idiomatic" pattern...
More information about the Digitalmars-d-learn
mailing list