[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
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to