Swift: enum cases should be types

Originator:rix.rob
Number:rdar://17515370 Date Originated:30-Jun-2014 09:56 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode6-Beta2 (6A216f)
Classification:Serious Bug Reproducible:Always
 
Summary:
Enumerations’ cases can specify the structure of data (the fields of the tuple they’re associated with, if any) and functionality (the cases interior to switch/case statements in functions taking the enumeration); i.e. they define limitations on what can be an element of that case and provide a hook for behaviour. This is pretty much what types are.

But since they’re not types, just tagged unions, they’re a weaker, runtime standin for an actual type and you can‘t do pattern matching against them in the type system, only in switch/case. Likewise, you can’t do type checking in switch/case, only in the type system; they ought to be one and the same.

If they were, I would be able to define my program parametrically bringing the full force of the language to bear on things like unwrapping cyclic graphs. Since they’re not, I have a small number of much less convenient options available to me, which typically run into other problems (like the lack of type-parameterized protocols).


Steps to Reproduce:
N/A


Expected Results:
N/A


Actual Results:
N/A


Regression:
N/A


Notes:
N/A

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!