<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 May 22, 2016, at 1:23 PM, Dave Abrahams 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=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">on Fri May 20 2016, Matthew Johnson <</span><a href="mailto:swift-evolution@swift.org" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">swift-evolution@swift.org</a><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">> wrote:</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" class="">On May 20, 2016, at 7:40 PM, Brent Royal-Gordon via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class=""><br class=""><blockquote type="cite" class="">The Any-class requirement could replace the current `AnyObject`<br class="">protocol with a typealias like this: `typealias AnyObject =<br class="">Any<class>`<br class=""></blockquote></blockquote><br class=""><blockquote type="cite" class=""><blockquote type="cite" class=""><br class="">Assume Swift would introduce Any-struct and Any-enum requirement<br class="">one day. How would one name a typealias for these, where `AnyClass`<br class="">means `AnyObject.Type`?<br class=""><br class="">I suggest we drop the current `AnyClass` and rename `AnyObject` to<br class="">`AnyClass`. If one would need the old `AnyClass` behavior it will<br class="">become `AnyClass.Type`.<br class=""></blockquote><br class="">I propose that we deprecate `AnyObject` in favor of `Any<class>`. No<br class="">typealias, just directly using `Any<>`. We would also deprecate<br class="">`AnyClass` in favor of `Any<class>.Type`. (Presumably we would do<br class="">this by providing `AnyObject` and `AnyClass` typealiases in Swift 3,<br class="">but marking them as deprecated.)<br class=""><br class="">I like this approach because it exposes people to `Any<>` and more<br class="">quickly gets them to see how it's connected to a protocol<br class="">declaration's conformance list. They might then guess that `Any<>`<br class="">has other capabilities from that list, like the ability to handle<br class="">multiple protocols.<br class=""><br class=""><blockquote type="cite" class="">In the future we could have typealiases like this, which are more clear:<br class=""><br class="">`typealias AnyClass = Any<class>`<br class="">`typealias AnyStruct = Any<struct>`<br class="">`typealias AnyEnum = Any<enum>`<br class=""></blockquote><br class="">Even in the long term, I don't see any good reason to support<br class="">`Any<struct>` vs. `Any<enum>`. There is no semantic distinction*<br class="">between a struct and an enum; you can always implement something<br class="">enum-y using a struct with a mode field, or something struct-y using<br class="">an enum with associated values. `Bool`, for instance, was once an<br class="">enum and was changed to a struct for implementation reasons; this<br class="">change made no difference to how it was used.<br class=""><br class="">Now, there *is* a semantic distinction between struct/enum and<br class="">class—one is a value type, the other is a reference type. To support<br class="">that distinction, it might make sense to support an `Any<value>` or<br class="">`Any<!class>` syntax. Again, I would prefer to use the raw `Any<>`<br class="">syntax, though, not a typealias.<br class=""></blockquote><br class="">You can implement reference types with value semantics and value types<br class="">with reference semantics. Until the compiler can verify value<br class="">semantics I am not sure there is a benefit to `any<value>`. The<br class="">semantic distinction is what is important. There has been discussion<br class="">about strengthening the “value type == value semantics” and “reference<br class="">type == reference semantics” relations but that hasn’t yet moved<br class="">beyond talk.<br class=""><br class=""><blockquote type="cite" class=""><br class="">(I've read the arguments about pure vs. non-pure value type<br class="">conformances and I'm not convinced. It is always possible to<br class="">nominally "conform" to a protocol in a way that actually undermines<br class="">its guarantees; for example, you could implement<br class="">`RangeReplaceableCollection.remove(at:)` as a no-op. The compiler<br class="">cannot reject all invalid conformances; it can only reject ones<br class="">which it can trivially show are invalid, because for instance they<br class="">do not even attempt to provide a required method. Similarly, the<br class="">compiler may not be able to prove you are providing value semantics,<br class="">but it *can* reject conformances of reference types to a protocol<br class="">requiring value semantics, since those cannot possibly be valid<br class="">conformances.<br class=""></blockquote><br class="">Immutable reference types actually *can* provide valid value semantics<br class="">(at least as long as as they can provide their own implementation of<br class="">`==` which I believe Dave A is arguing against).<br class=""></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">I am not making a strong argument against that, though it might be</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">reasonable. I am mostly arguing in favor of a default definition of ==</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">for all reference types that is equivalent to ===.</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""></div></blockquote><div><br class=""></div><div>Sorry I misunderstood. To make sure I understand clearly: you’re not arguing against reference types with value semantics, just that we should allow reference semantics to be assumed unless custom equality is implemented. Is that correct? </div><br class=""><blockquote type="cite" class=""><div class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">There is a big difference between semantics that the compiler *could*<br class="">but *does not yet* verify and semantics that simply cannot be<br class="">verified.<br class=""><br class=""><blockquote type="cite" class=""><br class="">Incidentally, I am not convinced that it *ever* makes sense to have<br class="">a mutating protocol which does not specify either value or reference<br class="">semantics.<br class="">The only intentional Stdlib examples I'm aware of are<br class="">`IteratorProtocol` and `OutputStream`, and I think both of those<br class="">should be reference-only.<br class=""><br class="">(On the other hand, it might make sense to be able to mark a struct<br class="">or enum as "this is actually a reference type". For instance, if you<br class="">import libc, UnsafeMutablePointer<FILE> is essentially a reference<br class="">type. But on the gripping hand, you *could*, and perhaps should,<br class="">just wrap it in a class, either through importer magic or a<br class="">manually-created type. That would permit you to conform it to<br class="">reference-typed mutating protocols.))<br class=""></blockquote><br class="">This is a good example of why the semantics aren’t so simple. <br class=""><br class=""><blockquote type="cite" class=""><br class=""><br class=""><br class="">* There *are* some distinctions, particularly in pattern matching, but protocols can't model them anyway. Incidentally, it is not possible to satisfy static property/method requirements with cases, but it probably should be:<br class=""><br class=""> protocol OptionalProtocol {<span class="Apple-converted-space"> </span><br class=""> associatedtype W<br class=""> static var none: Self { get }<span class="Apple-converted-space"> </span><br class=""> static func some(value: W) -> Self<span class="Apple-converted-space"> </span><br class=""> }<span class="Apple-converted-space"> </span><br class=""> extension Optional: OptionalProtocol {<br class=""> typealias W = Wrapped<br class=""> }<br class=""></blockquote><br class="">I think there was discussion at some point about introducing enum case<br class="">requirements into protocols. But that is mostly tangential to this<br class="">discussion.<br class=""><br class=""><blockquote type="cite" class=""><br class=""><br class="">--<span class="Apple-converted-space"> </span><br class="">Brent Royal-Gordon<br class="">Architechies<br class=""><br class="">_______________________________________________<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=""></blockquote><br class="">_______________________________________________<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=""></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">--<span class="Apple-converted-space"> </span></span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">-Dave</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">_______________________________________________</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">swift-evolution mailing list</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="mailto:swift-evolution@swift.org" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">swift-evolution@swift.org</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br class=""></body></html>