[swift-evolution] Fixing raw enum types

Joe Groff jgroff at apple.com
Tue Jan 17 13:26:21 CST 2017


> On Jan 17, 2017, at 9:54 AM, Anton Zhilin via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Some criticism for all the mentioned variants:
> 
> enum Something : raw(Int32)
> Requires adding a new contextual keyword.
> 
> enum Something : RawRepresentable
> With additional typealias RawValue, the simplest cases will lose their elegancy.
> 
> enum Something : RawRepresentable<Int32>
> +1. But we don’t have generic protocols right now :(
> 
I think this would be the right direction to go if we wanted to de-magic the existing RawRepresentable behavior. At this point, It would be reasonable to support this via where clauses on associated types:

enum Something: RawRepresentable where RawValue == Int32 { ... }

though that's pretty verbose. In the fullness of time, a generic typealias to a generalized existential could help with that, though:

typealias RawRepresentableOf<T> = RawRepresentable where RawValue == T

At that point, the compiler-built becomes closer to just a "regular" default implementation. There's still the privileged sugar for matching cases to raw values.

-Joe

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170117/26bfc8d1/attachment.html>


More information about the swift-evolution mailing list