[swift-evolution] Default Generic Arguments

Alexis abeingessner at apple.com
Mon Jan 23 15:09:04 CST 2017

> On Jan 23, 2017, at 3:18 PM, Srđan Rašić via swift-evolution <swift-evolution at swift.org> wrote:
> I think such cases would be extremely rare and one would have to be very ignorant about the types he/she works with. Additionally, that syntax is useful only for types with one generic argument. Say we have `Promise<T, E = Error>` and declare property as `let p: Promise<Int>`. How would you convey the information that there is a second argument that could be changed? Keeping the comma would be very ugly :)

To elaborate on this, default arguments are also a powerful tool for introducing new generic parameters in a way that’s source compatible. (potentially ABI compatible? Haven’t thought out implications of that). For instance, if you have a collection type, and decide to expose the allocator as a type parameter, defaults give you a backwards compatible way to do that. Making developers annotate “I’m using defaults” throws that away. If you make this “only” a warning then you’re just making busywork for the 99% of developers who always wanted the default behaviour, and couldn’t care less that it’s now configurable.

This would also go against the massive precedent set by default function arguments, which never need to be acknowledged.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170123/a8cde166/attachment.html>

More information about the swift-evolution mailing list