<div dir="ltr">I should clarify. I mean that they're like types in that they have a unique scoped name with fields. A union with cases with associated values is a sum types of product types. Obviously, they can't be used like "real" types as formal parameters, etc.<div><br></div><div>I don't see them as values or initializers but very constrained types. For instance, in C you could have something like:</div><div><br></div><div><div>struct Foo { </div><div> int tag; </div><div> </div><div> union { </div><div> struct Bar { </div><div> int x; </div><div> int y; </div><div> } bar; </div><div> </div><div> struct Baz { </div><div> double a; </div><div> double b; </div><div> } baz; </div><div> } data; </div><div>}; </div><div><br></div><div>which would be equivalent to Swift's:<br><br>enum Foo {</div><div> case Bar(x: Int, y: Int)</div><div> case Baz(a: Double, b: Double)</div><div>}</div><div><br></div><div>Bar and Baz in the C code above are actual types just unusable outside of the sum type (tagged union). If that's not similar to Swift, please correct me.</div><div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 26, 2016 at 2:02 PM, Dave Abrahams via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><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"><br>
on Sun Jan 24 2016, Thorsten Seitz <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br>
<br>
> Yes, I think they are a lot like sum (or union) types. In Ceylon enums<br>
> actually are modeled as union types (there is no specific enum<br>
> syntax).<br>
<br>
Enums in Swift are exactly that; Ceylon chose the name "union;" we chose<br>
"enum." But Trent is saying that enum *cases* are like types.<br>
<br>
> -Thorsten<br>
><br>
>> Am 23.01.2016 um 19:57 schrieb Trent Nadeau via swift-evolution<br>
>> <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>>:<br>
<span class="">>><br>
>> While enum cases may not be types from a compiler perspective, I think they are from a user's level.<br>
>><br>
>> Consider:<br>
>><br>
>> enum MyError: ErrorType {<br>
>> case FileError(fileName: String)<br>
>> case SocketError(ipAddr: String, port: Int16)<br>
>> }<br>
>><br>
>> From a compiler perspective, it's a tagged union (one type), but for<br>
>> a user this is a set of disjoint types that happen to share the same<br>
>> space and have exhaustiveness checking, etc. It's a much more<br>
>> efficient and convenient version of multiple structs or tuples.<br>
>><br>
</span><span class="">>> On Sat, Jan 23, 2016 at 1:49 PM, Joe Groff<br>
>> <<a href="mailto:jgroff@apple.com">jgroff@apple.com</a><br>
</span><span class="">>> <mailto:<a href="mailto:jgroff@apple.com">jgroff@apple.com</a>>> wrote:<br>
>><br>
>> > On Jan 23, 2016, at 10:24 AM, Trent Nadeau<br>
>> > <<a href="mailto:tanadeau@gmail.com">tanadeau@gmail.com</a><br>
</span><span class="">>> > <mailto:<a href="mailto:tanadeau@gmail.com">tanadeau@gmail.com</a>>> wrote:<br>
>> ><br>
>> > I think it makes sense for enum cases to be UpperCamelCase as they<br>
>> > can be thought of as scoped types (singleton types in the case of<br>
>> > cases with no associated types).<br>
>><br>
>> They aren't, though. I don't see much value in setting false expectations.<br>
>><br>
>> -Joe<br>
>><br>
>><br>
>><br>
>><br>
>> --<br>
</span>>> Trent Nadeau<br>
<div class=""><div class="h5">>> _______________________________________________<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>
><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>
<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></div></div>