<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Mar 29, 2017, at 4:52 PM, Brent Royal-Gordon &lt;<a href="mailto:brent@architechies.com" class="">brent@architechies.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=us-ascii" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><blockquote type="cite" class=""><div class="">On Mar 29, 2017, at 4:13 PM, Michael J LeHew Jr 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; line-break: after-white-space;" class="">Thanks for the feedback everyone! &nbsp;We have pushed a changed a bit ago to the proposal reflecting these desires.<br class=""><div class=""><br class=""></div><div class=""><a href="https://github.com/apple/swift-evolution/pull/644/files" class="">https://github.com/apple/swift-evolution/pull/644/files</a></div></div></div></blockquote><br class=""></div><div class="">Quoting from the proposal:</div><div class=""><br class=""></div><div class=""><blockquote type="cite" class="">luke[keyPath:&nbsp;#keyPath(.friends[0].name)]</blockquote><br class=""></div><div class="">Really? I can understand marking one or the other, but both, even when there's no ambiguity?</div></div></div></blockquote><div><br class=""></div><div>I had the same reaction initially -- but then after talking with Joe, he reminded me that this is the kind of code that only comes up in a 'this is how it works' context. &nbsp;Typically the key path will be a value and the syntax looks like: &nbsp;luke[keyPath: somePath]</div><div><br class=""></div><div>That example is a touch contrived to show that we'll be able to do the type inference where possible,&nbsp;</div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""></div><div class="">Let's pretend we're the type checker here. The `luke[keyPath: _]` part will create a context where we know we have an `AnyKeyPath`, `PartialKeyPath&lt;Person&gt;`, `KeyPath&lt;Person, U&gt;`, or `WritableKeyPath&lt;Person, U&gt;`. So if the core team's concern is about namespace clashes between `Person`'s static members and key paths, why not hang the key paths off the various `KeyPath` types? That is, this:</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>struct Person {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                </span>var friends: [Person]</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                </span>var name: String</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div class=""><br class=""></div><div class="">Implies this:</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>extension PartialKeyPath where Root == Person {</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                </span>static let friends: WritableKeyPath&lt;Person, [Person]&gt;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">                </span>static let name: WritableKeyPath&lt;Person, String&gt;</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div class=""><br class=""></div><div class="">And this:</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>#keyPath(Person, .friends[0].name)</div><div class=""><br class=""></div><div class="">Desugars to this:</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>PartialKeyPath&lt;Person&gt;.friends[0].name</div><div class=""><br class=""></div><div class="">So in a context where you already know you're passing a key path, you can simply write this:</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>luke[keyPath:&nbsp;.friends[0].name]</div><div class=""><br class=""></div><div class="">Which applies normal "unresolved member" logic to look it up in `PartialKeyPath`.</div></div></div></blockquote><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""></div><div class="">The result would be that you would have to explicitly, syntactically mark key paths except when the context already implied you were looking for one. In an unconstrained generic context, you would not get a key path without using `#keyPath` or explicitly naming a key path type. You would only need to worry about clashes if a call was overloaded to accept *both* `T` and `PartialKeyPath&lt;T&gt;`; if we found that possibility troubling, we could penalize unresolved member lookups that resolve to key paths, so type inference would favor static members over key paths even in those cases.</div><div class=""><br class=""></div><div class="">Would that work for people?&nbsp;</div></div></div></blockquote><div><br class=""></div><div>I'll let Joe speak to this aspect since this touches a lot more on implementation.&nbsp;</div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class="">
<span class="Apple-style-span" style="border-collapse: separate; font-variant-ligatures: normal; font-variant-east-asian: normal; font-variant-position: normal; line-height: normal; border-spacing: 0px;"><div class=""><div style="font-size: 12px; " class="">--&nbsp;</div><div style="font-size: 12px; " class="">Brent Royal-Gordon</div><div style="font-size: 12px; " class="">Architechies</div></div></span>

</div>
<br class=""></div></div></blockquote></div><br class=""></body></html>