<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 Dec 16, 2015, at 1:32 PM, Stephen Celis <<a href="mailto:stephen.celis@gmail.com" class="">stephen.celis@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">On Wed, Dec 16, 2015 at 2:18 PM, Matthew Johnson <span dir="ltr" class=""><<a href="mailto:matthew@anandabits.com" target="_blank" class="">matthew@anandabits.com</a>></span> wrote:<br class=""><div class="gmail_extra"><div class="gmail_quote"><br class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><div class="">I believe the dot abbreviation only works for enum cases right now.</div></div></blockquote><div class=""><br class=""></div><div class="">Nope :)</div><div class=""> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><div class="">I suppose those can be viewed as static members in some sense but they really something different than that. If I am mistaken I would like to be corrected.</div></div></blockquote><div class=""><br class=""></div><div class="">I'll do my best!</div><div class=""><br class=""></div><div class="">It works as I was trying to describe earlier. Any static member that returns Self. Try the following in a playground/REPL:<br class=""></div><div class=""><br class=""></div><div class=""><div class=""> struct Foo {</div><div class=""> static var bar: Foo {</div><div class=""> return Foo()</div><div class=""> }</div><div class=""> static func baz() -> Foo {</div><div class=""> return Foo()</div><div class=""> }</div><div class=""> }</div><div class=""> let bar: Foo = .bar</div><div class=""> let baz: Foo = .baz()</div></div><div class=""><br class=""></div><div class="">Here's a SwiftStub demonstrating the behavior: <a href="http://swiftstub.com/579553153" class="">http://swiftstub.com/579553153</a></div><div class=""><br class=""></div><div class="">Enum cases work with dot abbreviation _because_ they are static members that return Self. Enumerations aren't special-cased for dot abbreviation.</div><div class=""><br class=""></div></div></div></div></div></blockquote><div><br class=""></div><div>I stand corrected. This is pretty interesting. Is this covered in any documentation? I haven’t seen anything about it nor any code that uses this until now. It would be useful with factory methods. I appreciate your calling this to my attention!</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><div class=""><div class="">The shadowing is *current* behavior in the language. It is not something I propose.</div></div></div></blockquote><div class=""><br class=""></div><div class="">Is this true? Can you provide a full example that works in the playground and demonstrates this? The hypothetical you paste already has certain ambiguous issues (e.g. `var foo` and `func foo()` cannot compile together because of redefinition).</div></div></div></div></div></blockquote><div><br class=""></div><div>Here is an example. I tested it in an app rather than a playground (moving the print line into main).</div><div><br class=""></div>struct Foo {</div><div> //static var bar: Foo -> String = { _ in return "var" }<br class=""> static func bar(f: Foo) -> String { return "func" }<br class="">}</div><div>// prints “func”, but will compile and print “bar” if you uncomment the var<br class="">print(Foo.bar(Foo())) </div><div><br class=""></div><div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><div class=""><div class="">This would not refer to either. It cannot refer to Foo.bar because Foo has nothing to do with the array you are mapping over.</div></div></div></blockquote><div class=""><br class=""></div><div class=""><div class="">The example I give works in the playground. Try it! :)</div></div></div></div></div></div></blockquote><div><br class=""></div><div>You are right here as well. I didn’t read closely enough and didn’t notice the overload of map you added to Array.</div><div><br class=""></div><div>If you remove that overload your code will fail to compile. This is because the dot abbreviation is context sensitive. It only works when the type system knows the type the expression is expected to produce.</div><div><br class=""></div><div>Because of this context sensitivity no ambiguity would arise from the example you provided. As you note, the type of the static property or method must always be Self, which is never going to be a function type. This means that it is never going to have the same type as an unbound instance method (that its non-self arguments bound). </div><div><br class=""></div><div>Because of this the two shorthand notations will never be applicable in the same type context. I can see how the similarity could be confusing but it is not ambiguous. The potential confusion might even be enough to avoid introducing it into the language, but I’m not sure about that. </div><div><br class=""></div><div>I still think it’s an interesting idea.</div></div><br class=""><div class="">Matthew</div></body></html>