enum Something: RawRepresentable<Int32> {
}
Generics?
On Mon, Jan 16, 2017 at 1:51 PM Anton Zhilin via swift-evolution <
[email protected]> wrote:
> This idea by Karl made me branch off a new thread.
>
> 2017-01-16 21:28 GMT+03:00 Karl Wagner <[email protected]>:
>
> 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
> [email protected]
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution