<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jun 30, 2016, at 4:23 PM, Jordan Rose via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">[Proposal:&nbsp;<a href="https://github.com/apple/swift-evolution/blob/master/proposals/0108-remove-assoctype-inference.md" class="">https://github.com/apple/swift-evolution/blob/master/proposals/0108-remove-assoctype-inference.md</a>&nbsp;]</div><div class=""><br class=""></div><div class="">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.&nbsp;</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class="">protocol OptionA {</div><div class="">&nbsp; associatedtype Index</div><div class=""><br class=""></div><div class="">&nbsp; @infers(Index)</div><div class="">&nbsp; var startIndex: Index { get }</div><div class=""><br class=""></div><div class="">&nbsp; var endIndex: Index { get }</div><div class="">}</div><div class=""><br class=""></div><div class=""><div class="">protocol OptionB {</div><div class="">&nbsp; @inferredFrom(startIndex) // allows a full name here for overload resolution</div><div class="">&nbsp; associatedtype Index</div><div class=""><br class=""></div><div class="">&nbsp; var startIndex: Index { get }</div><div class="">&nbsp; var endIndex: Index { get }</div><div class="">}&nbsp;</div><div class=""><br class="Apple-interchange-newline">protocol OptionC {</div><div class="">&nbsp; associatedtype Index in startIndex // sugar</div><div class=""><br class=""></div><div class="">&nbsp; var startIndex: Index { get }</div><div class="">&nbsp; var endIndex: Index { get }</div><div class="">}</div></div></blockquote><br class=""><div class="">OptionC is the prettiest, but OptionA is probably the most flexible (consider overloading on associated types).</div><div class=""><br class=""></div><div class="">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 <i class="">is</i>&nbsp;just an impression, though.</div><div class=""><br class=""></div><div class="">Jordan</div></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""><div class=""><div>I’m trying to fill a gap in my own knowledge here. How does explicitly stating that startIndex is the inference point for Index help?&nbsp;</div><div><br class=""></div><div>Is it because various extensions and default implementations can provide different concrete types for Index, so the type checker is trying to resolve the ambiguity? If that’s the case, specifying startIndex here restricts the defaults/extensions that need to be considered from all to just ones that implement startIndex? Is that good enough generally or does it just solve the standard library’s problems?</div><div><br class=""></div><div>Would it be enough to have rules along these lines for a concrete type adopting a protocol with associated types?</div></div><div><br class=""></div><div>1. If the type’s main declaration (not defaults or extensions) contains a member satisfying a protocol requirement (where the requirement is specified in terms of an associated type) the associated type is locked to the type used in that member, so no global inference is necessary. If more than one such member is present all must use the same exact type.</div><div>2. Otherwise if there exists only one default/extension satisfying the associated type, the type used in that default implementation is used.</div><div>3. In all other cases the user must specify the associated types explicitly.</div><div><br class=""></div><div>Apologies if this is stuff I should already know.</div><div><br class=""></div><div>Russ</div><div><br class=""></div><div class=""><br class=""></div></body></html>