[swift-evolution] [Pitch] Enum with generic cases
Austin Zheng
austinzheng at gmail.com
Mon Apr 24 18:08:35 CDT 2017
I once put together a sketch for a proposal for GADTs. I wouldn't recommend
it be submitted for review today (or ever, really), but it's there if
anyone is interested.
https://github.com/austinzheng/swift-evolution/blob/az-gadt/proposals/XXXX-enums-as-gadts.md
Best,
Austin
On Mon, Apr 24, 2017 at 3:24 PM, Jaden Geller via swift-evolution <
swift-evolution at swift.org> wrote:
>
> On Apr 24, 2017, at 3:21 PM, Kevin Nattinger <swift at nattinger.net> wrote:
>
>
> On Apr 24, 2017, at 3:16 PM, Jaden Geller <jaden.geller at gmail.com> wrote:
>
>
> On Apr 24, 2017, at 2:38 PM, Kevin Nattinger <swift at nattinger.net> wrote:
>
>
> How can I improve your understanding?
>
>
> Given the enum I was using earlier:
>
> enum Thing {
> case thingOne<T>(T)
> case thingTwo<T>(T)
> }
>
> - Write a function that takes a thingOne<String> or thingTwo<Int> but
> nothing else.
>
>
> This isn’t possible since generic types introduced on cases are erased in
> the type of `Thing`.
>
> We can actually already achieve what you want by moving the generics onto
> the type itself, and this is already possible in Swift! No new features are
> necessary.
>
> ```
> enum Thing<T1, T2> {
> case thingOne(T1)
> case thingTwo(T2)
> }
>
> func test(_ x: Thing<String, Int>) {
> switch x {
> case .thingOne(let s):
> print("The string has value \(s)!")
> case .thingTwo(let i):
> print("The int has value \(i)!")
> }
> }
> ```
>
>
> Yes, that was almost exactly my original example. My understanding of the
> proposal is that it will remove that capability, which I find completely
> unacceptable.
>
>
> Hi Kevin,
>
> If that is what is being proposed, I agree that that is entirely
> unacceptable. I however did not understand the proposal to be removing that
> capability, but instead I understood that it was simply adding another.
> That is, `Thing<T1, T2>` would *still* be accepted. This feature is
> entirely additive.
>
> It would be great if the original proposal author could confirm this.
>
> Thanks,
> Jaden Geller
>
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170424/6d9affe3/attachment-0001.html>
More information about the swift-evolution
mailing list