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

Thorsten Seitz tseitz42 at icloud.com
Tue Jan 5 11:16:12 CST 2016


> 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.

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 


More information about the swift-evolution mailing list