> Enum cases _feel_ like separately defined, but tightly related structs 
> because each case can have distinct associated values. They have special 
> privileges that a family of structs doesn't have, like `self = .otherCase`. 
> Enums are really awesome.

<musings>

I think this is the primary difference between a “tagged union” and a Swift 
enum - I might have a union of several discrete types in other languages, but 
in swift it is actually an enumeration of cases within a single type. The 
individual cases are not types.

This was actually one of the reasons that drove case labels and static values 
to stylistically change to lowercase in Swift 3 - to avoid building a 
misconception of enum cases being distinct types.

I’ve wanted this feature in the past as well, but wonder if at some point 
encouraging support for a distinct union of types makes more sense than 
expanding enum - say, a closed protocol only allowing implementation by 
specific types declared within its module. 

-DW

_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to