[swift-evolution] [swift-evolution-announce] [Review] SE-0108: Remove associated type inference
Jordan Rose
jordan_rose at apple.com
Thu Jun 30 18:23:25 CDT 2016
[Proposal: https://github.com/apple/swift-evolution/blob/master/proposals/0108-remove-assoctype-inference.md <https://github.com/apple/swift-evolution/blob/master/proposals/0108-remove-assoctype-inference.md> ]
I’m pretty concerned about completely removing this feature. Yes, it’s a type-checker / decl-checker nightmare, but I think Paolo’s example in the initial discussion showed how it’s being used effectively today. I’d much rather have some kind of inference marker that maps one-to-one between an associated type and a value requirement (method, initializer, property, or subscript), also as brought up in the original discussion.
protocol OptionA {
associatedtype Index
@infers(Index)
var startIndex: Index { get }
var endIndex: Index { get }
}
protocol OptionB {
@inferredFrom(startIndex) // allows a full name here for overload resolution
associatedtype Index
var startIndex: Index { get }
var endIndex: Index { get }
}
protocol OptionC {
associatedtype Index in startIndex // sugar
var startIndex: Index { get }
var endIndex: Index { get }
}
OptionC is the prettiest, but OptionA is probably the most flexible (consider overloading on associated types).
I know we want to lock down on things now, and I know we can do better in the future, but I think inferring associated types is really quite common, and I’m concerned about taking it out without giving people a good alternative. This is just an impression, though.
Jordan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160630/167507b3/attachment.html>
More information about the swift-evolution
mailing list