[swift-evolution] Epic: Typesafe calculations

David Waite david at alkaline-solutions.com
Thu Jan 21 17:51:07 CST 2016


So if I understand you correctly, coercion (not conversion/representable form) relationships between types, giving you the ability to have one type's instance implicitly coerced into an instance of another type for the purposes of matching the signature needed by a particular method/property/initializer

So not an Employee-is-a-Person relationship, but more of an Int8-is-fully-representable-as-a-Int relationship. In this world, [Int] cannot now hold Int8s, but attempting to append an Int8 to such an array will cause an Int to automatically be created. 

Also, not implying code sharing, or declaration in at least the initial definition of the subtype - I could define a Maybe enum that was True,False, or Possibly cases, and a Bool argument could be an acceptable substitute.

One question - could you define then all T to be a subtype/be coerced into Optional<T> using language syntax? All Array<T> to Array<supertype T>

-DW

Sent with my Thumbs

> On Jan 21, 2016, at 2:41 PM, Dave Abrahams <dabrahams at apple.com> wrote:
> 
> 
> on Thu Jan 21 2016, David Waite <david-AT-alkaline-solutions.com> wrote:
> 
>>> On Jan 21, 2016, at 1:22 PM, Dave Abrahams via swift-evolution <swift-evolution at swift.org> wrote:
>>> 
>>> Yes, struct subtyping has come up several times.  There are several
>>> things I'd like to do with it in the standard library.
>> What do people mean when they say struct subclassing? Code reuse,
>> polymorphism, or something else?
> 
> By struct subtyping I mean:
> 
> A way to define a partial ordering of relationships between value types,
> with implicit conversions from subtype to supertype, and overload
> resolution based on a corresponding partial ordering of function/method
> overloads (much as it works for generics today).
> 
> -Dave
> 



More information about the swift-evolution mailing list