[swift-evolution] Three quick(ish) generics enhancements; *maybe* phase 1

David Sweeris davesweeris at mac.com
Thu Dec 22 22:30:53 CST 2016

I want to revisit some specific generics idea that, IIRC, were generally well-recieved at the time, but the conversation died down and nobody got around to writing formal proposals. I want to revisit them now (as opposed to in phase 2) because I don’t know how much “growing room” there is in the ABI for generics to gain features. It’d be a shame to close the door on these simply because nobody said anything. Anyway...

1) Allow generic parameters to have optional labels: struct Array <Element T> {…} //`let x = Array<Element: Double>` Not the best example, though, since I’d definitely argue against adding a label here
2) Allow literals as generic arguments:                       struct Array <T, Length: Int> {…} //Allows for `let x = Array<Double, Length: 10>()`
3) Allow generic parameters to have default values:  struct Array <T, Length: Int, FixedSize: Bool = false> {…} //The `let x…` from above still works, as well as `let y = Array<Double, Length: 10, FixedSize: true>()`

In addition to concerns regarding binary backwards compatibility, there’s one part where it might affect source code compatibility, too… If generic arguments get optional labels, would we need to use a `_` like with function arguments to indicate that we don’t intend for a label? Personally, I think a better solution would be to just make the labels be the same as the parameter name and have their use be optional altogether (except for parameters with default values — those would always need labels in case the type has several and you skip some), but perhaps others will feel differently.

Anyway, if this is phase 1 material, I’ll cheerfully get a informal proposal written up to kick off the discussion thread. If not, I’ll shelve them until phase 2.

- Dave Sweeris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20161222/3fe81876/attachment.html>

More information about the swift-evolution mailing list