[swift-evolution] Fixing raw enum types

Pranshu Goyal pranshu.goyal at novanet.net
Tue Jan 17 00:11:02 CST 2017


Definitely a +1, this clarifies intent, but enums are used a lot in swift
code, and considering this is a source breaking change I'm not sure if many
users of swift are going to be positive about this.

On 17 January 2017 at 02:32, David Waite via swift-evolution <
swift-evolution at swift.org> wrote:

> Or perhaps paint the bikeshed
>
> enum Something<(Int32, Int32)> { … }
>
> -DW
>
> On Jan 16, 2017, at 11:51 AM, Anton Zhilin via swift-evolution <
> swift-evolution at swift.org> wrote:
>
> This idea by Karl made me branch off a new thread.
>
> 2017-01-16 21:28 GMT+03:00 Karl Wagner <razielim at gmail.com>:
>
>
> It would be helpful for synthesised RawRep conformance. The
>> inheritance-like syntax we have now is awful - it makes people think that
>> RawRepresentable is some kind of magic protocol that will allow special
>> compiler jango to happen.
>>
>> You could see why they think that. This looks very much like the enum is
>> going to *be* an Int32:
>>
>> enum Something: Int32 {
>>     case oneThing = 36
>>     case anotherThing = 42
>> }
>>
>> This is also one of the icky parts to allowing tuples of integer/string
>> literals (something people ask for quite a lot). It would look like you’re
>> deriving your enum from a non-nominal type:
>>
>> enum Something: (Int32, Int32) {
>>     case oneThing = (3, 12)
>>     case anotherThing = (5, 9)
>> }
>>
>>
>
> Even if Swift gains newtype, it’s not that case. The enum does not gain
> methods or behavior of the specified type. It’s just a shorthand, hinting
> the compiler to provide correct RawRepresentable conformance.
>
> I suggest to invent a new syntax for this type hinting for
> RawRepresentable. For example, it can be an annotation:
>
> @raw(Int32) enum Something {
>     // ...
> }
>
> Or a contextual keyword:
>
> enum Something : raw(Int32) {
>     // ...
> }
>
> Perhaps, he most uniform and explicit of syntaxes:
>
> enum Something : RawRepresentable {
>     case oneThing = 36
>     case anotherThing = 42
> }
>
> enum AnotherThing : RawRepresentable {
>     typealias RawValue = Int32
>     case oneThing
>     case anotherThing
> }
>
>> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
>
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
>


-- 
*Pranshu Goyal*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170117/d1419b7b/attachment.html>


More information about the swift-evolution mailing list