[swift-evolution] [Pitch] Add the DefaultConstructible protocol to the standard library

Adam Nemecek adamnemecek at gmail.com
Mon Dec 26 13:42:49 CST 2016


> For integers, 0 is an additive identity. Is there a reason it should be
given special treatment over 1, the multiplicative identity?

E.g. for statistical reasons. When I have a collection of users with age
etc it makes sense to ask what is the combined age of the collection? What
is the semantic meaning of multiplying their ages?

> Mathematically, identities are associated with (type, operation) pairs,
not types alone.

Correct, however we aren't talking about mathematics, we are talking about
the implementation of a language that runs on very concrete architectures
where very concrete bit patterns mean very concrete things that are
unlikely to change any time soon.

On Mon, Dec 26, 2016 at 11:35 AM, Tony Allevato <allevato at google.com> wrote:

> For integers, 0 is an additive identity. Is there a reason it should be
> given special treatment over 1, the multiplicative identity? Historically
> the only reason is because it has the all-clear bit pattern.
>
> Mathematically, identities are associated with (type, operation) pairs,
> not types alone.
>
> This conversation has put me in the column of "numeric types shouldn't
> have default initializers at all", personally.
> On Mon, Dec 26, 2016 at 11:27 AM Adam Nemecek via swift-evolution <
> swift-evolution at swift.org> wrote:
>
>> The elements already have an Identity, the one that you get when you
>> invoke the default constructor. It's 0 for Int, "" for String.
>>
>> On Mon, Dec 26, 2016 at 11:24 AM, David Sweeris <davesweeris at mac.com>
>> wrote:
>>
>>
>> On Dec 26, 2016, at 11:12, Tino Heth via swift-evolution <
>> swift-evolution at swift.org> wrote:
>>
>> There is an older discussion that is somewhat linked to this topic:
>> "Removing the empty initialiser requirement from
>> RangeReplaceableCollection"
>> https://lists.swift.org/pipermail/swift-evolution/
>> Week-of-Mon-20160704/023642.html
>>
>> Imho "DefaultConstructible" types can be very handy, but so far, it seems
>> no one has presented a single use case that is important enough to justify
>> the inclusion in the stdlib.
>> On the other hand, I'm quite sure that there's much functionality in the
>> stdlib that many people consider as superfluous…
>>
>> I guess adding the protocol wouldn't have a big impact on size, so for
>> for me, the question is "Does this protocol confuse users of Swift?", which
>> I'd answer with "yes, possibly" (unless someone comes up with a name that
>> is more intuitive).
>>
>>
>> "Identity", but, at least for many numeric types, you'd need a mechanism
>> for specifying which one you mean.
>>
>> - Dave Sweeris
>>
>>
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161226/6d9e2d5c/attachment.html>


More information about the swift-evolution mailing list