[swift-evolution] [Proposal] Enum subsets

T.J. Usiyan griotspeak at gmail.com
Sat Jun 4 15:26:31 CDT 2016


It could be a more general solution. I am unclear about what 'subtype
relationships' means here though.

Are you talking a about what you allude to here?
https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20151130/000525.html


The benefit of explicitly narrowing, in my opinion, is that there is no
unnecessary cost to figuring out lookup. (Please correct me if I am
mistaken.) Implicit promotions introduce uncertainty with regard to what a
value is being treated as in any given moment. This uncertainty is worth it
in many cases but I will suggest that it is not worth it when trying to
deal with a narrower set of cases from an already established set. For
example, in the graph/lattice situation, conversions must be written
because there is no reasonable conversion that can be assumed. In this
proposal, the conversion is obvious and trivial because the relationship is
completely clear.

All of that said, I *am* unclear about what subtype relationships means so
it may very well be a better solution. It certainly sounds like a more
general solution but I am not convinced that that is an advantage when
trying to deal with a strict subset.

TJ
On Sat, Jun 4, 2016 at 1:25 AM, Chris Lattner <clattner at apple.com> wrote:

>
> On Jun 3, 2016, at 2:35 PM, T.J. Usiyan via swift-evolution <
> swift-evolution at swift.org> wrote:
>
> Since this seems to have some interest, I've made a gist.
>
> https://gist.github.com/griotspeak/963bc87a0c244c120264b11fb022d78c
>
>
> We have frequently discussed introducing subtype relationships between
> structs and enums, in an effort to allow limited implicit promotions (e.g.
> from small integers to wider integers).  Wouldn’t that be a more general
> solution to this same problem?
>
> -Chris
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160604/d4a42c48/attachment.html>


More information about the swift-evolution mailing list