<html><head><style>body{font-family:Helvetica,Arial;font-size:13px}</style></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">As Thorstan forgot to resend his message to the list, here it is (read below). It should make things about `any<>` more clear.</div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><br></div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;">———</div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px; color: rgba(0,0,0,1.0); margin: 0px; line-height: auto;"><br></div> <div><blockquote type="cite" class="clean_bq" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: 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;"><span style="white-space: pre-wrap;">func f(obj: class<SomeClass,SomeProtocl>) {..}</span></blockquote></div><div><div><blockquote type="cite" class="clean_bq" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: 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;"><span style="white-space: pre-wrap;">if obj is class<SomeClass,SomeProtocl> {..}</span></blockquote></div><div><div><div><blockquote type="cite" class="clean_bq" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: 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;"><span style="white-space: pre-wrap;">obj2 = obj as! class<SomeClass,SomeProtocol></span></blockquote></div></div><div><div><blockquote type="cite" class="clean_bq" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span style="white-space: pre-wrap;"> </span></blockquote></div><div><blockquote type="cite" class="clean_bq" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: 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;"><span style="white-space: pre-wrap;">and yes, probably struct<SomeStruct,SomeProtocol></span></blockquote></div><p>Why would you want to add all of these different formats where only one could serve them all. This is redundant in my opinion. </p><p>`struct<>` and `enum<>` would have same rules, only the first element would be a different value-type. I might consider this as an alternative.</p><p>Correct me if I’m wrong with the redundancy.</p><p>———</p><div><div><blockquote type="cite" class="clean_bq" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: 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;"><span style="font-family: 'helvetica Neue', helvetica;">The & type operator would produce a “flattened" all<> with its operands. It could be overloaded to accept either a concrete type or a protocol on the lhs and would produce `type` for an lhs that is a type and `all` when lhs is a protocol. "Type operators” would be evaluated during compile time and would produce a type that is used where the expression was present in the code. This is a long-term idea, not something that needs to be considered right now. It would be way out of scope for Swift 3. </span></blockquote></div><p>Which part of your statement is exactly out of scope for Swift 3, “Type operators“ I guess? </p><p>So is it a good idea to add `&` operator for "flattened“ `all<>` whereas “Type operators“ would be a better way to go (for Swift 4 maybe)? As far as I understand the idea behind `&` operator I’m not sure how it could be overloaded, because I thought it would be baked right into the language.</p><p>If I mixed something up here please feel free to correct me.</p><p>———</p><p>Would you mind to give me some feedback for the rules I've summarized.</p><p>———</p><p>The overall feedback seems to be positive so for and my fingers are crossed for this feature to be accepted.</p></div></div></div></div> <div id="bloop_sign_1463156138312271104" class="bloop_sign"><div style="font-family:helvetica,arial;font-size:13px">-- <br>Adrian Zubarev<br>Sent with Airmail</div></div> <br><p class="airmail_on">Am 13. Mai 2016 bei 08:16:51, Thorsten Seitz (<a href="mailto:tseitz42@icloud.com">tseitz42@icloud.com</a>) schrieb:</p> <blockquote type="cite" class="clean_bq"><span><div><div></div><div>
<title></title>
<div><br></div>
<div><br>
Am 12. Mai 2016 um 22:08 schrieb Adrian Zubarev via swift-evolution
<swift-evolution@swift.org>:<br>
<br>
<div>
<blockquote type="cite">
<div class="msg-quote" style="word-wrap: break-word;" data-mce-style="word-wrap: break-word;">
<div id="bloop_customfont" style="font-family: 'helvetica' , 'arial'; font-size: 13px; color: rgba(0 , 0 , 0 , 1.0); margin: 0px;" data-mce-style="font-family: 'helvetica' , 'arial'; font-size: 13px; color: rgba(0 , 0 , 0 , 1.0); margin: 0px;">
I don’t get the part how `all<>` should allow `any<>`.
Could you explain that a little bit in detail (I’m not familiar
with Ceylon)?</div>
</div>
</blockquote>
</div>
<div><span><br data-mce-bogus="1"></span></div>
<div><span>`all<>` and `any<>` form a pair of
complementary type operators, one creating the intersection of the
given types (your proposal) and the other creating the union of the
given types. As Ceylon has demonstrated that both are really useful
I'd like to have both in Swift and therefore would prefer that both
should be named such that this duality is visible. Having
`type<>` and `any<>` would certainly be possible
technically but the naming would not be good.</span></div>
<div><span><br></span>
<blockquote type="cite">
<div class="msg-quote" style="word-wrap: break-word;" data-mce-style="word-wrap: break-word;">
<div id="bloop_customfont" style="font-family: 'helvetica' , 'arial'; font-size: 13px; color: rgba(0 , 0 , 0 , 1.0); margin: 0px;" data-mce-style="font-family: 'helvetica' , 'arial'; font-size: 13px; color: rgba(0 , 0 , 0 , 1.0); margin: 0px;">
</div>
<div id="bloop_customfont" style="font-family: 'helvetica' , 'arial'; font-size: 13px; color: rgba(0 , 0 , 0 , 1.0); margin: 0px;" data-mce-style="font-family: 'helvetica' , 'arial'; font-size: 13px; color: rgba(0 , 0 , 0 , 1.0); margin: 0px;">
<br></div>
<div id="bloop_customfont" style="font-family: 'helvetica' , 'arial'; font-size: 13px; color: rgba(0 , 0 , 0 , 1.0); margin: 0px;" data-mce-style="font-family: 'helvetica' , 'arial'; font-size: 13px; color: rgba(0 , 0 , 0 , 1.0); margin: 0px;">
From my point of view `any<>` is something different that I
pitched here. `any<>` could be proposed in its own thread,
because it is way different than `type<>`. Or can we refine
the rules of `type<>` to get to `any<>`?</div>
</div>
</blockquote>
</div>
<div><span><br data-mce-bogus="1"></span></div>
<div><span>You are right, `any<>` is something different and
could be proposed in its own thread. I just wanted to extend the
context for finding a good name for `type<>`.</span></div>
<div><span><br></span>
<blockquote type="cite">
<div class="msg-quote" style="word-wrap: break-word;" data-mce-style="word-wrap: break-word;">
<div id="bloop_customfont" style="font-family: 'helvetica' , 'arial'; font-size: 13px; color: rgba(0 , 0 , 0 , 1.0); margin: 0px;" data-mce-style="font-family: 'helvetica' , 'arial'; font-size: 13px; color: rgba(0 , 0 , 0 , 1.0); margin: 0px;">
</div>
<div id="bloop_customfont" style="font-family: 'helvetica' , 'arial'; font-size: 13px; color: rgba(0 , 0 , 0 , 1.0); margin: 0px;" data-mce-style="font-family: 'helvetica' , 'arial'; font-size: 13px; color: rgba(0 , 0 , 0 , 1.0); margin: 0px;">
<br></div>
<div id="bloop_customfont" style="font-family: 'helvetica' , 'arial'; font-size: 13px; color: rgba(0 , 0 , 0 , 1.0); margin: 0px;" data-mce-style="font-family: 'helvetica' , 'arial'; font-size: 13px; color: rgba(0 , 0 , 0 , 1.0); margin: 0px;">
Here is a little example where `any<>` gets strange:</div>
<div id="bloop_customfont" style="font-family: 'helvetica' , 'arial'; font-size: 13px; color: rgba(0 , 0 , 0 , 1.0); margin: 0px;" data-mce-style="font-family: 'helvetica' , 'arial'; font-size: 13px; color: rgba(0 , 0 , 0 , 1.0); margin: 0px;">
<br></div>
<div id="bloop_customfont" style="font-family: 'helvetica' , 'arial'; font-size: 13px; color: rgba(0 , 0 , 0 , 1.0); margin: 0px;" data-mce-style="font-family: 'helvetica' , 'arial'; font-size: 13px; color: rgba(0 , 0 , 0 , 1.0); margin: 0px;">
func foo(value: any<String, Int>) -> any<String,
Int> {</div>
<div id="bloop_customfont" style="font-family: 'helvetica' , 'arial'; font-size: 13px; color: rgba(0 , 0 , 0 , 1.0); margin: 0px;" data-mce-style="font-family: 'helvetica' , 'arial'; font-size: 13px; color: rgba(0 , 0 , 0 , 1.0); margin: 0px;">
<br></div>
<div id="bloop_customfont" style="font-family: 'helvetica' , 'arial'; font-size: 13px; color: rgba(0 , 0 , 0 , 1.0); margin: 0px;" data-mce-style="font-family: 'helvetica' , 'arial'; font-size: 13px; color: rgba(0 , 0 , 0 , 1.0); margin: 0px;">
// how would one use value here?</div>
<div id="bloop_customfont" style="font-family: 'helvetica' , 'arial'; font-size: 13px; color: rgba(0 , 0 , 0 , 1.0); margin: 0px;" data-mce-style="font-family: 'helvetica' , 'arial'; font-size: 13px; color: rgba(0 , 0 , 0 , 1.0); margin: 0px;">
// what about its properties</div>
<div id="bloop_customfont" style="font-family: 'helvetica' , 'arial'; font-size: 13px; color: rgba(0 , 0 , 0 , 1.0); margin: 0px;" data-mce-style="font-family: 'helvetica' , 'arial'; font-size: 13px; color: rgba(0 , 0 , 0 , 1.0); margin: 0px;">
// what will foo return and how to use the
result</div>
<div id="bloop_customfont" style="font-family: 'helvetica' , 'arial'; font-size: 13px; color: rgba(0 , 0 , 0 , 1.0); margin: 0px;" data-mce-style="font-family: 'helvetica' , 'arial'; font-size: 13px; color: rgba(0 , 0 , 0 , 1.0); margin: 0px;">
}</div>
<div id="bloop_customfont" style="font-family: 'helvetica' , 'arial'; font-size: 13px; color: rgba(0 , 0 , 0 , 1.0); margin: 0px;" data-mce-style="font-family: 'helvetica' , 'arial'; font-size: 13px; color: rgba(0 , 0 , 0 , 1.0); margin: 0px;">
</div>
</div>
</blockquote>
</div>
<div><span><br data-mce-bogus="1"></span></div>
<div><span>Ceylon uses flow typing for that (if (is String value) {
/* value has type String here */ }).</span></div>
<div><span>In Swift the equivalent would be `if let string = value
as? String { ... }`:<br data-mce-bogus="1"></span></div>
<div><span><br data-mce-bogus="1"></span></div>
<div><span>func foo(value: any<Strint, Int>) ->
any<String, Int> {<br data-mce-bogus="1"></span></div>
<div><span> if let string = value as? String
{<br></span></div>
<div><span> return
string.characters.count<br></span></div>
<div><span> }</span></div>
<div><span> else if let int= value as? Int
{<br></span></div>
<div><span> return
String(int)<br></span></div>
<div><span> }</span></div>
<div><span>}<br data-mce-bogus="1"></span></div>
<div><span><br data-mce-bogus="1"></span></div>
<div><span>A more sensical example using a type union would be the
union of two sets:<br data-mce-bogus="1"></span></div>
<div><span><br data-mce-bogus="1"></span></div>
<div><span>func union<T, U>(a: Set<T>, b: Set<U>)
-> Set<any<T, U>> { ... }<br data-mce-bogus="1"></span></div>
<div><span><br data-mce-bogus="1"></span></div>
<div><span>And for type intersection the intersection of two
sets:<br data-mce-bogus="1"></span></div>
<div><span><br data-mce-bogus="1"></span></div>
<div><span>func intersection<T, U>(a: Set<T>, b:
Set<U>) -> Set<all<T, U>> { ...
}<br data-mce-bogus="1"></span></div>
<div><span><br data-mce-bogus="1"></span></div>
<div><span>(Ceylon's type operators just read better
there...)<br data-mce-bogus="1"></span></div>
<div><span><br data-mce-bogus="1"></span></div>
<div><span>Another example for type unions:<br data-mce-bogus="1"></span></div>
<div><span>Ceylon like Swift makes heavy use of optionals but where
Swift has a generic wrapper Optional<T> Ceylon just makes use
of type unions: in Ceylon T? is syntactic sugar for the type union
T | Null where Null is the type having the singleton value
null.<br data-mce-bogus="1"></span></div>
<div><span><br data-mce-bogus="1"></span></div>
<div><span>FWIW Microsoft's Typescript gained union and
intersection types about (I think) a year ago.<br data-mce-bogus="1"></span></div>
<div><br>
<blockquote type="cite">
<div class="msg-quote" style="word-wrap: break-word;" data-mce-style="word-wrap: break-word;">
<div id="bloop_customfont" style="font-family: 'helvetica' , 'arial'; font-size: 13px; color: rgba(0 , 0 , 0 , 1.0); margin: 0px;" data-mce-style="font-family: 'helvetica' , 'arial'; font-size: 13px; color: rgba(0 , 0 , 0 , 1.0); margin: 0px;">
<br></div>
<div id="bloop_customfont" style="font-family: 'helvetica' , 'arial'; font-size: 13px; color: rgba(0 , 0 , 0 , 1.0); margin: 0px;" data-mce-style="font-family: 'helvetica' , 'arial'; font-size: 13px; color: rgba(0 , 0 , 0 , 1.0); margin: 0px;">
One benefit of `any<>` is the replacement of overloading, at
least for the type part of the function.</div>
</div>
</blockquote>
</div>
<div><span><br data-mce-bogus="1"></span></div>
<div><span>Exactly.</span></div>
<div><br></div>
<span> </span>
<div>
<blockquote type="cite">
<div class="msg-quote" style="word-wrap: break-word;" data-mce-style="word-wrap: break-word;">
<div id="bloop_customfont" style="font-family: 'helvetica' , 'arial'; font-size: 13px; color: rgba(0 , 0 , 0 , 1.0); margin: 0px;" data-mce-style="font-family: 'helvetica' , 'arial'; font-size: 13px; color: rgba(0 , 0 , 0 , 1.0); margin: 0px;">
</div>
`all<>` could be seen as an alternative name for
`type<>`, but to me its not clear what `all<>` can
do, <span style="font-family: 'arial' , sans-serif; white-space: nowrap;" data-mce-style="font-family: 'arial' , sans-serif; white-space: nowrap;">whereas
`type<>` is almost like `protocol<>`.</span></div>
</blockquote>
</div>
<div><span><br data-mce-bogus="1"></span></div>
<div><span>Right, `all<>` is just an alternative name for
`type<>`. There is no change in functionality.</span></div>
<div><span><br data-mce-bogus="1"></span></div>
<div><span>-Thorsten</span></div>
</div>
</div></div></span></blockquote></body></html>