<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 Jul 1, 2016, at 15:53, Russ Bishop <<a href="mailto:xenadu@gmail.com" class="">xenadu@gmail.com</a>> 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=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Jun 30, 2016, at 4:23 PM, Jordan Rose via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> 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: <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> ]</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. </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=""> associatedtype Index</div><div class=""><br class=""></div><div class=""> @infers(Index)</div><div class=""> var startIndex: Index { get }</div><div class=""><br class=""></div><div class=""> var endIndex: Index { get }</div><div class="">}</div><div class=""><br class=""></div><div class=""><div class="">protocol OptionB {</div><div class=""> @inferredFrom(startIndex) // allows a full name here for overload resolution</div><div class=""> associatedtype Index</div><div class=""><br class=""></div><div class=""> var startIndex: Index { get }</div><div class=""> var endIndex: Index { get }</div><div class="">} </div><div class=""><br class="Apple-interchange-newline">protocol OptionC {</div><div class=""> associatedtype Index in startIndex // sugar</div><div class=""><br class=""></div><div class=""> var startIndex: Index { get }</div><div class=""> 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> 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=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class=""><div class=""><div class="">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? </div><div class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">Would it be enough to have rules along these lines for a concrete type adopting a protocol with associated types?</div></div><div class=""><br class=""></div><div class="">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 class="">2. Otherwise if there exists only one default/extension satisfying the associated type, the type used in that default implementation is used.</div><div class="">3. In all other cases the user must specify the associated types explicitly.</div></div></div></blockquote><br class=""></div><div>I don't remember exactly how the current rules work, but I think the compiler looks at <i class="">all</i> the members that mention an associated type and tries to figure out if they're all in sync. Reducing that to just looking at <i class="">one</i> value requirement might be enough to satisfy Doug's concerns, even if it still has to do overload resolution…or you could follow the spirit of your rule 2 and say that <i class="">any</i> overloads force you to specify the element type explicitly.</div><div><br class=""></div><div>Rule 1, however, is the important one: "if more than one such member is present all must use the same exact type". I think that's already moving into the realm of spooky action and circularity issues that Doug's attempting to squash.</div><div><br class=""></div><div>Jordan</div><br class=""></body></html>