[swift-evolution] Support for newtype feature/typesafe calculations

Matthew Johnson matthew at anandabits.com
Tue Jan 5 11:24:18 CST 2016

> On Jan 5, 2016, at 11:16 AM, Thorsten Seitz via swift-evolution <swift-evolution at swift.org> wrote:
>> Am 05.01.2016 um 17:11 schrieb Grzegorz Adam Hankiewicz via swift-evolution <swift-evolution at swift.org>:
>> The ideal would be for the compiler to pretend Euros or RefTablePk are different types, yet use their parent type at the binary level. This needs a specific syntax to teach the compiler which existing methods/operations are allowed on the new fake types and which aren’t. These new distinct types would *borrow* previous implementations.
> What about citing the relevant protocols in the newtype definition? This should include the ability to use my own protocols to which I have made the underlying type conform to by an extension.

This is how my forwarding proposal works.  The newtype syntax I suggested as a possible extension looks like this:

newtype Euro = Double forwarding Addable, Subtractable

The keyword could be different, but I think `forwarding` is not bad.  When I complete the second draft I think it will make even more sense.  The forwarding facility has features to handle non-trivial cases (Self and associated type requirements, etc).

> Throwing some syntax into the discussion:
> newtype Euro = Double : Addable, Subtractable
> where I have defined the protocols Addable and Subtractable somewhere and made Double conform to them if all this is not provided by the standard library.
> The implementation of Euro then borrows the implementation of Double for these protocols.
> -Thorsten 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

More information about the swift-evolution mailing list