<html><head><style>body{font-family:Helvetica,Arial;font-size:13px}</style></head><body 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;line-height:auto"><div id="bloop_customfont" style="margin:0px">Well, as to &quot;This type of constraint issomething that the type system cannot and should not support.”” I would point out that it sounds very feasible is the underlying type was “Any” since all that would be needed is a few checks. I would definitely agree that making a new “union” type would be pointless. I’m not so sure about the “should not” in this case, as we already have the type “Any” and “AnyObject” which don’t give the slightest hint as to what they contain.</div><div id="bloop_customfont" style="margin:0px"><br></div><div id="bloop_customfont" style="margin:0px">If it is difficult, then of course the “Any” type is already sufficient. It is weird that it can contain optionals, but the compile warnings seem to make it workable.</div></div> <div id="bloop_sign_1489448666665015040" class="bloop_sign"></div> <br><p class="airmail_on">On March 13, 2017 at 7:44:04 PM, Tony Allevato (<a href="mailto:tony.allevato@gmail.com">tony.allevato@gmail.com</a>) wrote:</p> <blockquote type="cite" class="clean_bq"><span><div><div></div><div>


<title></title>


<div dir="ltr"><br>
<br>
<div class="gmail_quote">
<div dir="ltr">On Mon, Mar 13, 2017 at 4:41 PM Tony Allevato
&lt;<a href="mailto:tony.allevato@gmail.com">tony.allevato@gmail.com</a>&gt;
wrote:<br></div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr" class="gmail_msg">
<div class="gmail_quote gmail_msg">
<div dir="ltr" class="gmail_msg">On Mon, Mar 13, 2017 at 4:41 PM
Tony Allevato &lt;<a href="mailto:tony.allevato@gmail.com" class="gmail_msg" target="_blank">tony.allevato@gmail.com</a>&gt;
wrote:<br class="gmail_msg"></div>
<blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr" class="gmail_msg">This strikes me as fairly
equivalent to &quot;union types&quot;, which are on the frequently rejected
proposals list:</div>
</blockquote>
<div class="gmail_msg"><br class="gmail_msg"></div>
</div>
</div>
<div dir="ltr" class="gmail_msg">
<div class="gmail_quote gmail_msg">
<div class="gmail_msg">(hit Send too soon)</div>
</div>
</div>
</blockquote>
<div><br></div>
<div>(My e-mail client hates me today; apologies for the
spam)</div>
<div><br></div>
<div><a href="https://github.com/apple/swift-evolution/blob/master/commonly_proposed.md">
https://github.com/apple/swift-evolution/blob/master/commonly_proposed.md</a><br>
</div>
<div><br></div>
<div> </div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr" class="gmail_msg">
<div class="gmail_quote gmail_msg">
<div class="gmail_msg"><br class="gmail_msg"></div>
<div class="gmail_msg"> </div>
<blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr" class="gmail_msg">
<div class="gmail_msg"><br class="gmail_msg"></div>
<div class="gmail_msg"><br class="gmail_msg">
<br class="gmail_msg">
<div class="gmail_quote gmail_msg">
<div dir="ltr" class="gmail_msg">On Mon, Mar 13, 2017 at 4:14 PM
Elijah Johnson via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br class="gmail_msg"></div>
<blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word" class="gmail_msg">I don’t know if
this feature has yet existed in any languague, but its pretty
simple.
<div class="gmail_msg"><br class="gmail_msg"></div>
<div class="gmail_msg">Let say you are preparing data for a JSON
encoder. Right now, you would add to an Dictionary or Array like
this one:</div>
<div class="gmail_msg"><br class="gmail_msg"></div>
<div class="gmail_msg">let data = [String:Any]();</div>
<div class="gmail_msg"><br class="gmail_msg"></div>
<div class="gmail_msg">but what one is really saying is that “Any”
is from a number of distinct types:</div>
<div class="gmail_msg"><br class="gmail_msg"></div>
<div class="gmail_msg">group typedef JSONValueType : String,
Double, Int, [String:JSONValueType], [JSONValueType], Bool</div>
<div class="gmail_msg"><br class="gmail_msg"></div>
<div class="gmail_msg">So from the compiler’s point of view, this
group typedef would be just like the “Any” type, only it would
refuse to compile unless the proper type was passed. So the result
would be, as an example, that there could be created an (almost)
fail-safe JSON encoder:</div>
<div class="gmail_msg"><br class="gmail_msg"></div>
<div class="gmail_msg">let data = [String:JSONValueType]();</div>
<div class="gmail_msg">data[“key] = “value”;</div>
<div class="gmail_msg"><br class="gmail_msg"></div>
<div class="gmail_msg">I’m sure this has plenty of uses outside of
JSON encoding and would be pretty simple to do. One problem that it
would solve it the fact that in Swift, everything is included by
Any, including optionals, ex:</div>
<div class="gmail_msg"><br class="gmail_msg"></div>
<div class="gmail_msg">
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">let</span> <span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">b
:</span> <span style="font-variant-ligatures:no-common-ligatures;color:#703daa" class="gmail_msg">String</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">?
=</span> <span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">nil</span><span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">;</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo" class="gmail_msg"><span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">let</span> <span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">a
:</span> <span style="font-variant-ligatures:no-common-ligatures;color:#ba2da2" class="gmail_msg">Any</span> <span style="font-variant-ligatures:no-common-ligatures" class="gmail_msg">= b;
// result is warning: “Expression implicitly coerced from String?
to Any&quot;</span></p>
</div>
<div class="gmail_msg"><br class="gmail_msg"></div>
<div class="gmail_msg">and so there is no way to include value
types and objects without also including optionals, though this
“Any” (like Object and void* in Java/C) syntax makes for poorly
documented code when the type isn’t really “Any”, but a collection
of known types.</div>
<div class="gmail_msg"><br class="gmail_msg"></div>
<div class="gmail_msg">There already exist protocols, but they are
not useful for types that one has not defined (like the basic
system types), or for mixing particular values, structs, and
classes.</div>
</div>
</blockquote>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</blockquote>
<div><br></div>
<div>You can retroactively extend any type to support a protocol,
so that&#39;s one way that you could achieve this. The catch is that
you don&#39;t want arbitrary types outside the set that you bless to be
able to conform to that protocol. For that case, I think being able
to define a &quot;closed&quot; protocol would be nice and achieve what you
want,</div>
<div><br></div>
<div> </div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr" class="gmail_msg">
<div class="gmail_quote gmail_msg">
<blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr" class="gmail_msg">
<div class="gmail_msg">
<div class="gmail_quote gmail_msg">
<blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
_______________________________________________<br class="gmail_msg">
swift-evolution mailing list<br class="gmail_msg">
<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a><br class="gmail_msg">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="gmail_msg">
</blockquote>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</blockquote>
</div>
</div>


</div></div></span></blockquote></body></html>