Hi Brent, I understand that SubC.cc as C does not work, that’s the case in my 
bikeshedding example I noticed that because the enum case is always known at 
compile time, there will be an error with informs you to downgrade SubC to one 
of its super-types case. Plus I forget about the RawRepresentable for enums 
while making this example completely - my bad.

I might not fully understand how sub-typing on value types should work, that’s 
way I’m looking forward to the document Matthew will write one day. :)

Sub-typing enums to remove cases sounds also really interesting to me. :)

Thank you for your feedback.



-- 
Adrian Zubarev
Sent with Airmail

Am 12. Februar 2017 um 09:57:39, Brent Royal-Gordon ([email protected]) 
schrieb:

> On Feb 11, 2017, at 2:25 AM, Adrian Zubarev via swift-evolution 
> <[email protected]> wrote:  
>  
> // Allowed because `C` is open, and open allows sub-typing, conforming  
> // and overriding to the client  
> enum SubC : C {  
> case cc  
> }  

There's a subtle mistake here. For a sum type, subtyping actually means 
*removing* cases, not *adding* cases. (Or it can mean changing some of the 
associated types into their subtypes, but that's a different story.)  

To understand why, think about casting between `C` and `SubC`. Specifically, 
imagine this upcast:  

SubC.cc as C  

What is this supposed to do? There is no `cc` case in `C`, so `SubC.cc` cannot 
be represented as a `C`. That means `SubC` is not a subtype of `C`. In fact, 
`SubC` would be a *supertype* of `C`—you would need to say `SubC.cc as? C`, but 
you could always say `C.c as SubC`.  

(The ultimate expression of this is that `Never`—which can be thought of as the 
subtype of all types—is an empty enum.)  

That's not to say that this is a feature we should add; rather, it's to say 
that the concept of inheritance doesn't really make any sense for `enum`s.  

Just something I noticed when I was reading this thread. I'll have more to say 
on the main topic, hopefully soon.  

--  
Brent Royal-Gordon  
Architechies  

_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to