[swift-evolution] Fixing raw enum types

Haravikk swift-evolution at haravikk.me
Tue Jan 17 13:01:11 CST 2017


> On 17 Jan 2017, at 17:54, Anton Zhilin via swift-evolution <swift-evolution at swift.org> wrote:
> enum Something : RawRepresentable
> With additional typealias RawValue, the simplest cases will lose their elegancy.
> 

While I like the idea of RawRepresentable<Int32>, the use of an associatetype seems like the most obvious choice, as it's consistent with other types.
I'm not sure I'd agree that it loses elegance, especially if we can get type inference, for example:

	enum Something : RawRepresentable { case .Foo = 1, .Bar = 2 }

Would be equivalent to:

	enum Something : RawRepresentable {
		typealias RawType = Int
		case .Foo = 1
		case .Bar = 2
	}

Just the same as any other type inference really. We could even have the RawRepresentable conformance inferred (so you don't have to specify it if you set raw values).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170117/2686178f/attachment.html>


More information about the swift-evolution mailing list