<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div></div><div>That Ceylon example is exactly what I've been thinking of, too.</div><div><br></div><div>I understand that Swift's enums work differently, though. But I do like Ceylon's union types (them being able to represent enums being just a minor part).</div><div><br></div><div>-Thorsten&nbsp;</div><div><br>Am 27.01.2016 um 03:09 schrieb Trent Nadeau via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt;:<br><br></div><blockquote type="cite"><div><div dir="ltr"><div>I think I understand where you're coming from now in that you can think of:<br></div><div><br></div><div><font face="monospace, monospace">enum Foo {<br></font></div><div><div><font face="monospace, monospace">&nbsp; &nbsp; case Bar(x: Int, y: Int)</font></div><div><font face="monospace, monospace">&nbsp; &nbsp; case Baz(a: Double, b: Double)</font></div></div><div><font face="monospace, monospace">}</font></div><div><br></div><div>as:</div><div><br></div><div><font face="monospace, monospace">struct Foo {</font></div><div><font face="monospace, monospace">&nbsp; &nbsp; let Bar:&nbsp;(x: Int, y: Int)</font></div><div><font face="monospace, monospace">&nbsp; &nbsp; let Baz: (a: Double, b: Double)</font></div><div><font face="monospace, monospace">}</font></div><div><br></div><div>with special handling for storage and pattern matching.</div><div><br></div><div>I was thinking of it more in terms of mapping to:<br><br><div><font face="monospace, monospace">struct Foo {</font></div><div><font face="monospace, monospace">&nbsp; &nbsp; typealias Bar =&nbsp;</font><span style="font-family:monospace,monospace">(x: Int, y: Int)</span></div><div><font face="monospace, monospace">&nbsp; &nbsp; typealias&nbsp;</font><span style="font-family:monospace,monospace">Baz = (a: Double, b: Double)</span></div><div><span style="font-family:monospace,monospace"><br></span></div><div><span style="font-family:monospace,monospace">&nbsp; &nbsp; let storage: MagicStorageOfMaxSize</span></div><div><font face="monospace, monospace">}</font></div></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">with special handling for type use and pattern matching.</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">The former is probably closer to the implementation and is easier to explain. If that's the case, I'm +1 on changing the case naming convention. The initial capital letter probably put "type" in my head in the first place along with ways of using enums from other languages like Ceylon:<br><br></font><pre class="" style="word-wrap:break-word;color:rgb(231,233,219);font-family:'andale mono','lucida console',monospace;margin-top:0px;margin-bottom:0px;padding:10px;border:0px;font-size:14.5px;vertical-align:baseline;font-stretch:normal;line-height:1.5;background-color:rgb(47,30,46)"><code class="" style="font-family:Inconsolata,Monaco,Courier,monospace;margin:0px;padding:0px;border:0px;vertical-align:baseline;font-stretch:normal;line-height:1.5"><span class="" style="margin:0px;padding:0px;border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;color:rgb(6,182,239)">abstract</span> <span class="" style="margin:0px;padding:0px;border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;color:rgb(184,186,175)">class</span> <span class="" style="margin:0px;padding:0px;border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;color:rgb(254,196,24)">Node</span>() <span class="" style="margin:0px;padding:0px;border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;color:rgb(184,186,175)">of</span> <span class="" style="margin:0px;padding:0px;border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;color:rgb(254,196,24)">Leaf</span> | <span class="" style="margin:0px;padding:0px;border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;color:rgb(254,196,24)">Branch</span> {}

<span class="" style="margin:0px;padding:0px;border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;color:rgb(184,186,175)">class</span> <span class="" style="margin:0px;padding:0px;border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;color:rgb(254,196,24)">Leaf</span>(<span class="" style="margin:0px;padding:0px;border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;color:rgb(6,182,239)">shared</span> <span class="" style="margin:0px;padding:0px;border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;color:rgb(254,196,24)">Object</span> <span class="" style="margin:0px;padding:0px;border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;color:rgb(239,97,85)">element</span>) 
        <span class="" style="margin:0px;padding:0px;border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;color:rgb(184,186,175)">extends</span> <span class="" style="margin:0px;padding:0px;border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;color:rgb(254,196,24)">Node</span>() {}

<span class="" style="margin:0px;padding:0px;border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;color:rgb(184,186,175)">class</span> <span class="" style="margin:0px;padding:0px;border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;color:rgb(254,196,24)">Branch</span>(<span class="" style="margin:0px;padding:0px;border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;color:rgb(6,182,239)">shared</span> <span class="" style="margin:0px;padding:0px;border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;color:rgb(254,196,24)">Node</span> <span class="" style="margin:0px;padding:0px;border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;color:rgb(239,97,85)">left</span>, <span class="" style="margin:0px;padding:0px;border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;color:rgb(6,182,239)">shared</span> <span class="" style="margin:0px;padding:0px;border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;color:rgb(254,196,24)">Node</span> <span class="" style="margin:0px;padding:0px;border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;color:rgb(239,97,85)">right</span>) 
        <span class="" style="margin:0px;padding:0px;border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;color:rgb(184,186,175)">extends</span> <span class="" style="margin:0px;padding:0px;border:0px;font-weight:inherit;font-style:inherit;font-family:inherit;vertical-align:baseline;color:rgb(254,196,24)">Node</span>() {}</code></pre></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 26, 2016 at 7:49 PM, Dave Abrahams via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
on Tue Jan 26 2016, Trent Nadeau &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br>
<br>
&gt; I should clarify. I mean that they're like types in that they have a<br>
&gt; unique scoped name with fields.<br>
<br>
</span>struct X {<br>
&nbsp; static var y: Int = 3<br>
}<br>
<br>
X.y has a unique scoped name.&nbsp; What's all this about fields?&nbsp; I don't<br>
understand that part.<br>
<span class=""><br>
&gt; A union with cases with associated values is a sum types of product<br>
&gt; types. Obviously, they can't be used like "real" types as formal<br>
&gt; parameters, etc.<br>
&gt;<br>
&gt; I don't see them as values or initializers but very constrained types. For<br>
&gt; instance, in C you could have something like:<br>
&gt;<br>
&gt; struct Foo {<br>
&gt;<br>
&gt;&nbsp; &nbsp; &nbsp;int tag;<br>
&gt;<br>
&gt;&nbsp; &nbsp; &nbsp;union {<br>
&gt;<br>
&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;struct Bar {<br>
&gt;<br>
&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int x;<br>
&gt;<br>
&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int y;<br>
&gt;<br>
&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} bar;<br>
&gt;<br>
&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;struct Baz {<br>
&gt;<br>
&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;double a;<br>
&gt;<br>
&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;double b;<br>
&gt;<br>
&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} baz;<br>
&gt;<br>
&gt;&nbsp; &nbsp; &nbsp;} data;<br>
&gt;<br>
&gt; };<br>
&gt;<br>
&gt; which would be equivalent to Swift's:<br>
&gt;<br>
&gt; enum Foo {<br>
&gt;&nbsp; &nbsp; &nbsp;case Bar(x: Int, y: Int)<br>
&gt;&nbsp; &nbsp; &nbsp;case Baz(a: Double, b: Double)<br>
&gt; }<br>
&gt;<br>
&gt; Bar and Baz in the C code above are actual types just unusable outside of<br>
&gt; the sum type (tagged union).<br>
<br>
</span>The fact that an anonymous union in C hides the types declared within is<br>
just a quirk of that language.&nbsp; You didn't even need to name Bar and Baz<br>
in the `C' code.&nbsp; The Bar and Baz in your swift code are more similar to<br>
bar and baz (lowercase) as they are required in order to access members<br>
of the sum.<br>
<br>
FWIW, there's a strong proposal out there (which I support) to give<br>
enums optional properties, e.g.<br>
<br>
&nbsp; &nbsp; &nbsp; if let (x,y) = someFoo.Bar { ... }<br>
&nbsp; &nbsp; &nbsp; else if let (a,b) = someFoo.Baz { ... }<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
<br>
&gt; If that's not similar to Swift, please correct me.<br>
<br>
&gt;<br>
&gt; On Tue, Jan 26, 2016 at 2:02 PM, Dave Abrahams via swift-evolution &lt;<br>
&gt; <a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br>
&gt;<br>
&gt;&gt;<br>
&gt;&gt; on Sun Jan 24 2016, Thorsten Seitz<br>
&gt;&gt; &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; &gt; Yes, I think they are a lot like sum (or union) types. In Ceylon enums<br>
&gt;&gt; &gt; actually are modeled as union types (there is no specific enum<br>
&gt;&gt; &gt; syntax).<br>
&gt;&gt;<br>
&gt;&gt; Enums in Swift are exactly that; Ceylon chose the name "union;" we chose<br>
&gt;&gt; "enum."&nbsp; But Trent is saying that enum *cases* are like types.<br>
&gt;&gt;<br>
&gt;&gt; &gt; -Thorsten<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; Am 23.01.2016 um 19:57 schrieb Trent Nadeau via swift-evolution<br>
&gt;&gt; &gt;&gt; &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt;:<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; While enum cases may not be types from a compiler perspective, I think<br>
&gt;&gt; they are from a user's level.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; Consider:<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; enum MyError: ErrorType {<br>
&gt;&gt; &gt;&gt;&nbsp; &nbsp; &nbsp;case FileError(fileName: String)<br>
&gt;&gt; &gt;&gt;&nbsp; &nbsp; &nbsp;case SocketError(ipAddr: String, port: Int16)<br>
&gt;&gt; &gt;&gt; }<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; From a compiler perspective, it's a tagged union (one type), but for<br>
&gt;&gt; &gt;&gt; a user this is a set of disjoint types that happen to share the same<br>
&gt;&gt; &gt;&gt; space and have exhaustiveness checking, etc. It's a much more<br>
&gt;&gt; &gt;&gt; efficient and convenient version of multiple structs or tuples.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; On Sat, Jan 23, 2016 at 1:49 PM, Joe Groff<br>
&gt;&gt; &gt;&gt; &lt;<a href="mailto:jgroff@apple.com">jgroff@apple.com</a><br>
&gt;&gt; &gt;&gt; &lt;mailto:<a href="mailto:jgroff@apple.com">jgroff@apple.com</a>&gt;&gt; wrote:<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; &gt; On Jan 23, 2016, at 10:24 AM, Trent Nadeau<br>
&gt;&gt; &gt;&gt; &gt; &lt;<a href="mailto:tanadeau@gmail.com">tanadeau@gmail.com</a><br>
&gt;&gt; &gt;&gt; &gt; &lt;mailto:<a href="mailto:tanadeau@gmail.com">tanadeau@gmail.com</a>&gt;&gt; wrote:<br>
&gt;&gt; &gt;&gt; &gt;<br>
&gt;&gt; &gt;&gt; &gt; I think it makes sense for enum cases to be UpperCamelCase as they<br>
&gt;&gt; &gt;&gt; &gt; can be thought of as scoped types (singleton types in the case of<br>
&gt;&gt; &gt;&gt; &gt; cases with no associated types).<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; They aren't, though. I don't see much value in setting false<br>
&gt;&gt; expectations.<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; -Joe<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt;<br>
&gt;&gt; &gt;&gt; --<br>
&gt;&gt; &gt;&gt; Trent Nadeau<br>
&gt;&gt; &gt;&gt; _______________________________________________<br>
&gt;&gt; &gt;&gt; swift-evolution mailing list<br>
&gt;&gt; &gt;&gt; <a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
&gt;&gt; &gt;&gt; <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; _______________________________________________<br>
&gt;&gt; &gt; swift-evolution mailing list<br>
&gt;&gt; &gt; <a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
&gt;&gt; &gt; <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
&gt;&gt;<br>
&gt;&gt; --<br>
&gt;&gt; -Dave<br>
&gt;&gt;<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; swift-evolution mailing list<br>
&gt;&gt; <a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
&gt;&gt; <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
&gt;&gt;<br>
<br>
--<br>
-Dave<br>
<br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">Trent Nadeau</div>
</div>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></body></html>