<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">This is quite forward thinking, but since now is the time for breaking changes, I think it's an idea worth sharing.<div class=""><br class=""></div><div class="">It's recently been accepted that enum cases are values, not types, yet this is a questionable conclusion: their associated values are parameterised, unlike the main value-storage mechanisms which currently exist in the language properties and variables.</div><div class="">However, parameterisation has precedent in Swift, for types. I propose promoting enum cases back to types, and giving them an appropriate parameterisation syntax: Case<Type, Type>.</div><div class=""><br class=""></div><div class="">Suppose, in the future, we add parameters to generic types which may hold a value. By extension, it would make sense to add support for pattern matching, so the following would be possible:</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 13px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal; color: rgb(0, 118, 0);" class=""><font face="Menlo" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">struct</span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class=""> Example<</span><span style="color: rgb(187, 44, 162);" class="">let</span> <span style="font-variant-ligatures: no-common-ligatures; color: rgb(0, 0, 0);" class="">T: <span style="color: rgb(112, 61, 170);" class="">Int</span>> {} </span><span style="font-variant-ligatures: no-common-ligatures;" class="">//Placeholder syntax for a value parameter.</span></font></div><div style="margin: 0px; line-height: normal; min-height: 15px;" class=""><font face="Menlo" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> exampleType: </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Example</span><span style="font-variant-ligatures: no-common-ligatures" class="">.Type = </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Example</span><span style="font-variant-ligatures: no-common-ligatures" class=""><</span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">5</span><span style="font-variant-ligatures: no-common-ligatures" class="">> </span><span style="color: rgb(0, 118, 0);" class="">//No .self needed, as I believe this is soon to be removed.</span></font></div><div style="margin: 0px; line-height: normal; min-height: 15px;" class=""><font face="Menlo" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></font></div><div style="margin: 0px; line-height: normal; color: rgb(79, 129, 135);" class=""><font face="Menlo" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">switch</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">exampleType</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> {</span></font></div><div style="margin: 0px; line-height: normal; color: rgb(79, 129, 135);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""><font face="Menlo" class=""><br class=""></font></span></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">Example</span><span style="font-variant-ligatures: no-common-ligatures" class=""><</span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0</span><span style="font-variant-ligatures: no-common-ligatures" class="">...</span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">10</span><span style="font-variant-ligatures: no-common-ligatures" class="">>: </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(61, 29, 129);" class="">print</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(</span><span style="color: rgb(209, 47, 27); font-variant-ligatures: no-common-ligatures;" class="">"between 0 and 10"</span><span style="font-variant-ligatures: no-common-ligatures;" class="">)</span></font></div><div style="margin: 0px; line-height: normal; color: rgb(209, 47, 27);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""><font face="Menlo" class=""><br class=""></font></span></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> <span style="color: rgb(79, 129, 135);" class="">Example</span><v> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">where</span><span style="font-variant-ligatures: no-common-ligatures" class=""> v > </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">10</span><span style="font-variant-ligatures: no-common-ligatures" class="">: </span><span style="font-variant-ligatures: no-common-ligatures; color: rgb(61, 29, 129);" class="">print</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(</span><span style="color: rgb(209, 47, 27); font-variant-ligatures: no-common-ligatures;" class="">"greater than ten"</span><span style="font-variant-ligatures: no-common-ligatures;" class="">)</span></font></div><div style="margin: 0px; line-height: normal; color: rgb(209, 47, 27);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""><font face="Menlo" class=""><br class=""></font></span></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">let</span><span style="font-variant-ligatures: no-common-ligatures" class=""> <span style="color: rgb(79, 129, 135);" class="">Example</span><v> </span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">where</span><span style="font-variant-ligatures: no-common-ligatures" class=""> v < </span><span style="font-variant-ligatures: no-common-ligatures; color: #272ad8" class="">0</span><span style="font-variant-ligatures: no-common-ligatures;" class="">: </span><span style="font-variant-ligatures: no-common-ligatures;" class="">print(</span><span style="color: rgb(209, 47, 27); font-variant-ligatures: no-common-ligatures;" class="">"negative: </span><span style="font-variant-ligatures: no-common-ligatures;" class="">\</span><span style="color: rgb(209, 47, 27); font-variant-ligatures: no-common-ligatures;" class="">(</span><span style="font-variant-ligatures: no-common-ligatures;" class="">v</span><span style="color: rgb(209, 47, 27); font-variant-ligatures: no-common-ligatures;" class="">)"</span><span style="font-variant-ligatures: no-common-ligatures;" class="">)</span></font></div><div style="margin: 0px; line-height: normal; color: rgb(209, 47, 27);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""><font face="Menlo" class=""><br class=""></font></span></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> <span style="color: rgb(79, 129, 135);" class="">Example</span><</span><span style="color: rgb(187, 44, 162);" class="">let</span> v>: <span style="font-variant-ligatures: no-common-ligatures;" class="">print(</span><span style="color: rgb(209, 47, 27); font-variant-ligatures: no-common-ligatures;" class="">"other: </span><span style="font-variant-ligatures: no-common-ligatures;" class="">\</span><span style="color: rgb(209, 47, 27); font-variant-ligatures: no-common-ligatures;" class="">(</span><span style="font-variant-ligatures: no-common-ligatures;" class="">v</span><span style="color: rgb(209, 47, 27); font-variant-ligatures: no-common-ligatures;" class="">)"</span><span style="font-variant-ligatures: no-common-ligatures;" class="">)</span></font></div><div style="margin: 0px; line-height: normal; color: rgb(209, 47, 27);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""><font face="Menlo" class=""><br class=""></font></span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><font face="Menlo" class="">}</font></span></div></div></div><div style="margin: 0px; font-size: 13px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; font-size: 13px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; font-size: 13px; line-height: normal;" class="">I propose enums could be considered an extension of this idea, and each case is analogous to a nested type with generic parameters. The enum is a specialised construct for this kind of pattern matching; it resembles a metatype of its nested types, hence a variable of type Enum stores a value of Enum.Case.</div><div style="margin: 0px; font-size: 13px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; font-size: 13px; line-height: normal;" class="">The proposed syntax for enums would look like this:</div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: 'SF UI Text';" class=""><br class=""></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: 'SF UI Text';" class=""><br class=""></div><div style="margin: 0px; font-size: 13px; line-height: normal;" class=""><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(187, 44, 162);" class="">enum</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> Optional<T> {</span></font></div><div style="margin: 0px; line-height: normal;" class=""><font face="Menlo" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span class="Apple-tab-span" style="white-space:pre">        </span></span><span style="font-variant-ligatures: no-common-ligatures; color: #bb2ca2" class="">case</span><span style="font-variant-ligatures: no-common-ligatures" class=""> Some</span><<span style="color: rgb(187, 44, 162);" class="">let</span> T>,<span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="color: rgb(0, 118, 0); font-variant-ligatures: no-common-ligatures;" class="">//Placeholder syntax for a value parameter.</span></font></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>None</font></span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><font face="Menlo" class="">}</font></span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><br class=""></span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><br class=""></span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">This is not a major change from the current syntax for enums, and it eliminates the currently exceptional use of round brackets for stored-value parameterisation from the language, in favour of a syntax consistent with that of type parameterisation.</span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div style="margin: 0px; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">This proposal has two major syntax changes:</span></div><div style="margin: 0px; line-height: normal;" class=""><ul class=""><li class="">Returning to using UpperCamelCase for enum cases, and making them analogous to nested types.</li><li class="">Replacement of round brackets, (), in favour of angle brackets, <>, for parameterisation of enum cases.</li><ul class=""><li class="">This could be a simple bracket replacement, which could optionally be revised in the future to match future value parameterisation of types, as shown above with the example <let T> syntax.</li><li class="">Alternatively, a value-parameterisation syntax could be chosen now, used for enums, and later be extended to types.</li></ul></ul></div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">Thanks for reading. Thoughts?</div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class=""><br class=""></div><div style="margin: 0px; line-height: normal;" class="">PS: An alternative value parameterisation I considered when writing this proposal was Type<T = Int> and .Some<=T>, but using ‘let’ seemed more readable, and reflects pattern matching, so I used that for my examples.</div></div></body></html>