[swift-evolution] Value Subtypes and Generalized Enums, a manifesto

Matthew Johnson matthew at anandabits.com
Thu Feb 16 17:10:11 CST 2017


> On Feb 16, 2017, at 5:00 PM, Karl Wagner <razielim at gmail.com> wrote:
> 
> 
>> On 16 Feb 2017, at 23:44, Matthew Johnson via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> 
>> I have been thinking a lot about enums and value subtyping lately and decided to write down the ideas I’ve been thinking about.  The result is a manifesto-style document that explores a broad landscape of features that could eventually lead to proposals (at the right time, of course).
>> 
>> I’m presenting this document to the list now mostly because I am not sure which of these features (if any) might be relevant to ABI stability, particularly with respect to standard library APIs.  I do not wish to distract the list from the focus on Swift 4, phase 1.  Let’s try not to get distracted by exciting ideas that won’t be in scope until at least phase 2.  Feel free to send feedback off list if you’re interested in discussing ideas that may not be relevant to Swift evolution at this time.
>> 
>> Because this document covers a pretty broad range of topics it might be a good idea to start a new thread before jumping in to discussion about a specific aspect of it.  Please consider doing that if it is relevant before responding directly to this thread.
>> 
>> As this is a relatively large document I am only providing a link: https://gist.github.com/anandabits/5b7f8e3836387e893e3a1197a4bf144d <https://gist.github.com/anandabits/5b7f8e3836387e893e3a1197a4bf144d>
>> 
>> To whet your appetite, the topics covered include:
>> 
>> * Definition of value subtyping
>>   * Transitivity of value subtypes
>>   * Generic supertype constraints
>> * Axiomatic value subtype relationships
>> * Enums: Value Subtype Relationships by definition
>>   * Nominal case types
>>   * Nominal unions
>>   * Generic enums and Optional
>>        * Cases with unbound generic arguments
>>   * Structural Unions
>>   * Enum subtypes
>>   * Inline enum subtypes
>>   * Inline generic enum subtypes
>>   * Conditional cases (and GADTs)
>>   * Inline case types
>>   * Nominal cases with inline types
>>   * Case type implementation sharing
>>        * Shared stored properties
>>            * Subenum stored properties
>>        * Shared methods and computed properties
>> * User-defined case patterns
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>> https://lists.swift.org/mailman/listinfo/swift-evolution
> 
> 
> 
> 
> enum IntOrString: Int | String {
>   case Int
>   case String
> }
> 
> func takesAnonymousUnion(intOrString: Int | String) {}
> 
> Haven’t been through it all, just pointing out that “Structural unions” and anonymous unions have been suggested and rejected before.

Thanks for taking a look at the document Karl.

I understand and have followed the previous discussions regarding structural unions and alluded to them in the manifesto.  I am not proposing anything directly in this document.  I am only exploring ideas and observing how they logically follow from one another.

My hope is that demonstrating how structural unions fit within the larger landscape of value subtyping will provide some context for possibly revisiting the structural union discussion in the future.  Specifically, if we introduce nominal case types and nominal unions there would be a new basis and context for revisiting the discussion of structural unions.  It certainly won’t happen prior to that.  In any case, I think it’s safe to say this is a topic that is definitely *not* in scope for Swift 4, phase 1.  :)

> 
> - Karl

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170216/5c86c980/attachment.html>


More information about the swift-evolution mailing list