[swift-evolution] [Pitch] Add the DefaultConstructible protocol to the standard library
Adam Nemecek
adamnemecek at gmail.com
Sun Dec 25 13:23:02 CST 2016
This protocol is present in C++
http://en.cppreference.com/w/cpp/concept/DefaultConstructible as well as in
Rust https://doc.rust-lang.org/std/default/
It's the identity element/unit of a monoid or a zero.
The Swift implementation is very simple (I'm open to different names)
protocol DefaultConstructible {
init()
}
A lot of the standard types could then be made to conform to this protocol.
These include all the numeric types, collection types (array, set, dict),
string, basically at least every type that currently has a constructor
without any arguments.
The RangeReplaceableCollection protocol would inherit from this protocol as
well.
This protocol would simplify a lot of generic algorithms where you need the
concept of a zero (which shows up a lot)
Once introduced, Sequence could define an alternative implementation of
reduce where the initial result doesn't need to be provided as it can be
default constructed.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161225/ec920728/attachment.html>
More information about the swift-evolution
mailing list