[Pitch] strong typedef


(Daryle Walker) #1

I uploaded my proposal for strong type-aliases at <https://gist.github.com/CTMacUser/c493f775075e946efdcfd85d38473291>. My brain is somewhat fried from working for several days writing and rewriting this, so new sets of eyes finding issues is appreciated.

* I originally had “retype” as the name, but it’s strictly a verb while “struct(ure),” “enum(eration),” and “class” are nouns, hence “alter(native).” Maybe there's an even better name out there? The header looks a little funny because the type being altered is after the colon, and not the identifier immediately next to “alter”.
* A lot of the text is a consequence of the restriction/validation dynamic, should that be dropped? Dropped for now? Note that dropping it will require sum alternative types to include all of the cases from their implementation type.
* If a bunch of members are introduced from the implementation type as a set of function overloads or a protocol set, should there be a way for a directly-defined member to shadow over a published member instead of co-existing as overloads? For instance:

alter MyInt16: Int16, Hashable {
publish Equatable
var hashValue: Int {
return 2000 &+ super.hashValue
}
}

If I change the published protocol to Hashable, I’d get an illegal overload error. Should it be changed to let a directly-defined member override a published one? If so, should a plain declaration work, or should “override” be added to the directly defined version (so an unintentional shadowing is flagged as an error)?

* If we keep restrictions, what about protocols that return or otherwise output Self? They could return values that are valid for the implementation type but not the current alternative type. How can I fix this co-variance/contra-variance mismatch? Or is this an argument to drop restricted alternative types?

···


Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com