<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">James, that works for degrees to radians, but I'm afraid that one protocol per unit simply can't scale if you want to multiply/divide quantities with different units. Just look at the&nbsp;<a href="https://upload.wikimedia.org/math/d/c/1/dc1af6ed32aa3e906230cc15ea08a2a4.png" class="">different things can make up a tesla</a>. The combination of units is factorial and defining like 24 protocols each with multiplication and division operation to every other defined protocol doesn't make sense. I'd rather use "untyped" quantities if I had to do the same thing in Swift right now.<div class=""><br class=""></div><div class="">(By the way: Degree(360) - 30 should probably be Degree(360) - Degree(30), no? I'm not sure whether 30 is expressed in degrees or radians :-) )</div><div class=""><br class=""></div><div class="">The important parts in the outlined vision are that:</div><div class=""><br class=""></div><div class=""><ol class="MailOutline"><li class="">the unit information is available as type information to the compiler; it checks that additions and subtractions use the same units and uses the correct derived type when you multiply/divide quantities with units;</li><li class="">you can easily add new "fundamental" units that would be very hard or impossible to derive from other units (meters, seconds, kilograms, radians, etc);</li><li class="">you can easily derive units from fundamental units (N = kg * m^1 * s^-2).</li></ol><div class=""><br class=""></div><div class="">Right now, we can do #1. If this is what we're going for, then newtype isn't very important because it doesn't contribute that much to anything here (though if we decide that we don't need that much power, it would be a decent crutch).</div><div class=""><div class="">
<br class="Apple-interchange-newline"><span style="color: rgb(0, 0, 0); font-family: 'Lucida Grande'; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none;" class="">Félix</span>
</div>
<br class=""><div><blockquote type="cite" class=""><div class="">Le 7 janv. 2016 à 07:06:01, James Campbell &lt;<a href="mailto:james@supmenow.com" class="">james@supmenow.com</a>&gt; a écrit :</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">So this is how this feature could be achieved right now with minimal changes to the language.<div class=""><br class=""></div><div class="">- We expose some kind of protocol that allows you to Box up types, we could call this `Box` or something else like `Unit`. (I have a working implementation in the current language with a bit of boilerplate). This protocol handles the default implementation of converting from literals and to floats etc.</div><div class="">- For each type-safe unit for a calculation - you define a protocol extending this `Box` type which defines the associated type of the value that unit holds. For example for Degree and Radian I declared a `AngleType` which set the associated type to be a double.&nbsp;</div><div class="">- For each unit type, you declare a struct that inherits from that protocol you defined. So I have two structs `Degree` and `Radian` which implement the `AngleType` protocol.</div><div class="">- You implement the functions for figuring out if your units are equal and all other operators they may need i.e `Degree(360) - 30`.</div><div class=""><br class=""></div><div class="">Future improvements with language updates:</div><div class=""><br class=""></div><div class="">- `AngleType` protocol may not be needed if swift introduces generic protocols.</div><div class="">- Boilerplate in your type safe unit types may be reduced if swift introduces memberwise initialization.</div><div class="">- The current implementation of this system in Swift will be greatly simplified once the refactoring of Swift's Number types has been completed. We currently use a bunch of work arounds with the compiler.</div><div class="">- We could introduce custom user literals to create these types if swift supports this in the future (As Felix states).</div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Thu, Jan 7, 2016 at 7:06 AM, Félix Cloutier <span dir="ltr" class="">&lt;<a href="mailto:felixcca@yahoo.ca" target="_blank" class="">felixcca@yahoo.ca</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="">I'd like to hijack this thread to talk about what the TI Voyage 200 could do as far as "type-safe calculations" go.<div class=""><br class=""></div><div class="">The calculator supports symbolic equations (for instance, `a * 1000 / 2` results in `500a` when a isn't known). The interesting part is that you could append units to numbers. For instance, you can write `500_m`, and this means 500 meters. Numbers with a type can only be added/subtracted with numbers of the same type, but they can be multiplied or divided by pretty much anything. For instance, `500_m - 2_s` (500 meters minus 2 seconds) is an error, but `500_m / 2_s` is `250 (_m/_s)` (or _m * _s^-1).</div><div class=""><br class=""></div><div class="">I found this *extremely* useful for engineering calculations. For instance, when you multiply quantities that should end up in Teslas, you know that you've done something wrong if the unit displayed after the number doesn't look like `V * s * m^-2`. It was also a lifesaver that you could do something like `6_ft` and end up with 1.8288_m (because _ft is defined as 0.3048_m).</div><div class=""><br class=""></div><div class="">I have no idea how you'd implement that with Swift though. I'm not a very powerful template wizard, but I have no idea how you'd do it with C++ either.</div><div class=""><br class=""></div><div class="">Of course, it might be a few years before you're allowed to use the Swift compiler during your physics exams, and I don't think that real-world programs often need that much unit safety with numbers. But when I read "epic typesafe calculations", that's what I think about.</div><div class=""><div class="">
<br class=""><span style="font-family: 'Lucida Grande'; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; float: none; display: inline !important;" class="">Félix</span>
</div>

<br class=""><div class=""><blockquote type="cite" class=""><div class=""><div class="h5"><div class="">Le 7 janv. 2016 à 01:42:07, Thorsten Seitz via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; a écrit :</div><br class=""></div></div><div class=""><div class=""><div class=""><div class="h5"><div class="">I think the name should be changed to NumberBox or something similar. A box is something very generic and should not have number related associated types.<br class=""></div><div class=""><br class=""></div><div class="">-Thorsten<br class=""></div><div class=""><br class="">Am 06. Januar 2016 um 18:15 schrieb James Campbell &lt;<a href="mailto:james@supmenow.com" target="_blank" class="">james@supmenow.com</a>&gt;:<br class=""><br class=""><div class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class="">I've managed to implement this already in the language with a few ugly corners due to the lack of generic protocols.<div class=""><br class=""></div><div class="">I created a protocol based on Box (<a href="https://github.com/robrix/Box/" target="_blank" class="">https://github.com/robrix/Box/</a>) which works really well. I have extended this to handle certain special protocols like Equatable so you can do SpecialType == SpecialType, and even literalConversion.</div><div class=""><br class=""></div><div class="">There is however a lot of boilerplate:</div><div class=""><br class=""></div><div class="">- You have to declare all of your Convertible protocols for converting from one type to another</div><div class="">- You have to define an empty init so the protocol extensions have something to chain to.</div><div class="">- You need to write the value property with type.</div><div class=""><br class=""></div><div class="">Due to the lack of protocol generics, you also need to have a protocol for every type you wish to box which sets the associated type. Of course I could have done this with classes but I wanted to keep this as a value type :).</div><div class=""><br class=""></div><div class="">With member-wise initializations and generic protocols this could be achievable just by adding a Box protocol to the standard library.</div><div class=""><br class=""></div><div class="">Here is my implementation of Box as a protocol:</div><div class=""><br class=""></div><div class=""><p class=""><b class=""><span class="">protocol</span><span class=""> Box: </span><span class="">CustomStringConvertible</span><span class="">, </span><span class="">CustomDebugStringConvertible</span><span class=""> {</span></b></p><p class=""><span class=""><b class="">&nbsp;&nbsp; &nbsp;</b></span></p><p class=""><b class=""><span class="">&nbsp; &nbsp; </span><span class="">typealias</span><span class=""> FloatLiteralType = Double</span></b></p><p class=""><b class=""><span class="">&nbsp; &nbsp; </span><span class="">typealias</span><span class=""> IntegerLiteralType = Int</span></b></p><p class=""><b class=""><span class="">&nbsp; &nbsp; </span><span class="">typealias</span><span class=""> BoxType = Any</span></b></p><p class=""><span class=""><b class="">&nbsp;&nbsp; &nbsp;</b></span></p><p class=""><b class=""><span class="">&nbsp; &nbsp; </span><span class="">var</span><span class=""> value: </span><span class="">BoxType</span><span class=""> { </span><span class="">get</span><span class=""> </span><span class="">set</span><span class=""> }</span></b></p><p class=""><span class=""><b class="">&nbsp;&nbsp; &nbsp;</b></span></p><p class=""><b class=""><span class="">&nbsp; &nbsp; </span><span class="">init</span><span class="">()</span></b></p><p class=""><b class=""><span class="">&nbsp; &nbsp; </span><span class="">init</span><span class="">(</span><span class="">_</span><span class=""> value: </span><span class="">BoxType</span><span class="">)</span></b></p><p class=""><span class=""><b class="">}</b></span></p><p class=""><b class=""><span class=""></span><br class=""></b></p><p class=""><b class=""><span class="">extension</span><span class=""> </span><span class="">Box</span><span class=""> </span><span class="">where</span><span class=""> BoxType: CustomStringConvertible {</span></b></p><p class=""><span class=""><b class="">&nbsp;&nbsp; &nbsp;</b></span></p><p class=""><b class=""><span class="">&nbsp; &nbsp; </span><span class="">var</span><span class=""> description: </span><span class="">String</span><span class=""> {</span></b></p><p class=""><b class=""><span class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="">return</span><span class=""> </span><span class="">self</span><span class="">.</span><span class="">value</span><span class="">.</span><span class="">description</span></b></p><p class=""><span class=""><b class="">&nbsp; &nbsp; }</b></span></p><p class=""><span class=""><b class="">&nbsp;&nbsp; &nbsp;</b></span></p><p class=""><b class=""><span class="">&nbsp; &nbsp; </span><span class="">var</span><span class=""> debugDescription: </span><span class="">String</span><span class=""> {</span></b></p><p class=""><b class=""><span class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="">return</span><span class=""> </span><span class="">"</span><span class="">\</span><span class="">(</span><span class="">self</span><span class="">.</span><span class="">value</span><span class="">.</span><span class="">description</span><span class="">)</span><span class="">㎭</span><span class="">"</span></b></p><p class=""><span class=""><b class="">&nbsp; &nbsp; }</b></span></p><p class=""><span class=""><b class="">}</b></span></p><p class=""><b class=""><span class=""></span><br class=""></b></p><p class=""><span class=""><b class="">//MARK: FloatingPointBox</b></span></p><p class=""><b class=""><span class=""></span><br class=""></b></p><p class=""><b class=""><span class="">protocol</span><span class=""> FloatingPointBox: </span><span class="">Box</span><span class="">, </span><span class="">FloatLiteralConvertible</span><span class="">, </span><span class="">IntegerLiteralConvertible</span><span class=""> {</span></b></p><p class=""><span class=""><b class="">&nbsp;&nbsp; &nbsp;</b></span></p><p class=""><b class=""><span class="">&nbsp; &nbsp; </span><span class="">typealias</span><span class=""> BoxType = Double</span></b></p><p class=""><b class=""><span class="">&nbsp; &nbsp; </span><span class="">typealias</span><span class=""> FloatLiteralConvertible = Double</span></b></p><p class=""><b class=""><span class="">&nbsp; &nbsp; </span><span class="">typealias</span><span class=""> IntegerLiteralConvertible = Int</span></b></p><p class=""><span class=""><b class="">}</b></span></p><p class=""><b class=""><span class=""></span><br class=""></b></p><p class=""><b class=""><span class="">extension</span><span class=""> </span><span class="">Box</span><span class=""> </span><span class="">where</span><span class=""> </span><span class="">Self</span><span class="">.BoxType == Double {</span></b></p><p class=""><span class=""><b class="">&nbsp;&nbsp; &nbsp;</b></span></p><p class=""><b class=""><span class="">&nbsp; &nbsp; </span><span class="">init</span><span class="">(</span><span class="">_</span><span class=""> value: </span><span class="">Double</span><span class="">) {</span></b></p><p class=""><span class=""><b class="">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</b></span></p><p class=""><b class=""><span class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="">self</span><span class="">.</span><span class="">init</span><span class="">()</span></b></p><p class=""><b class=""><span class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="">self</span><span class="">.</span><span class="">value</span><span class=""> = value</span></b></p><p class=""><span class=""><b class="">&nbsp; &nbsp; }</b></span></p><p class=""><span class=""><b class="">&nbsp;&nbsp; &nbsp;</b></span></p><p class=""><b class=""><span class="">&nbsp; &nbsp; </span><span class="">init</span><span class="">(</span><span class="">_</span><span class=""> value: </span><span class="">Int</span><span class="">) {</span></b></p><p class=""><span class=""><b class="">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;</b></span></p><p class=""><b class=""><span class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="">self</span><span class="">.</span><span class="">init</span><span class="">()</span></b></p><p class=""><b class=""><span class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="">self</span><span class="">.</span><span class="">value</span><span class=""> = </span><span class="">Double</span><span class="">(value)</span></b></p><p class=""><span class=""><b class="">&nbsp; &nbsp; }</b></span></p><p class=""><span class=""><b class="">}</b></span></p><p class=""><b class=""><span class=""></span><br class=""></b></p><p class=""><b class=""><span class="">extension</span><span class=""> </span><span class="">FloatLiteralType</span><span class=""> {</span></b></p><p class=""><span class=""><b class="">&nbsp;&nbsp; &nbsp;</b></span></p><p class=""><b class=""><span class="">&nbsp; &nbsp; </span><span class="">init</span><span class="">&lt;T: </span><span class="">Box</span><span class=""> </span><span class="">where</span><span class=""> </span><span class="">T</span><span class="">.</span><span class="">BoxType</span><span class=""> == </span><span class="">Double</span><span class=""> &gt;(</span><span class="">_</span><span class=""> box: </span><span class="">T</span><span class="">) {</span></b></p><p class=""><b class=""><span class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="">self</span><span class="">.</span><span class="">init</span><span class="">(box.</span><span class="">value</span><span class="">)</span></b></p><p class=""><span class=""><b class="">&nbsp; &nbsp; }</b></span></p><p class=""><span class=""><b class="">&nbsp;&nbsp; &nbsp;</b></span></p><p class=""><b class=""><span class="">&nbsp; &nbsp; </span><span class="">init</span><span class="">&lt;T: </span><span class="">Box</span><span class=""> </span><span class="">where</span><span class=""> </span><span class="">T</span><span class="">.</span><span class="">BoxType</span><span class=""> == </span><span class="">Int</span><span class=""> &gt;(</span><span class="">_</span><span class=""> box: </span><span class="">T</span><span class="">) {</span></b></p><p class=""><b class=""><span class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="">self</span><span class="">.</span><span class="">init</span><span class="">(box.</span><span class="">value</span><span class="">)</span></b></p><p class=""><span class=""><b class="">&nbsp; &nbsp; }</b></span></p><p class=""><span class=""><b class="">}</b></span></p><p class=""><b class=""><span class=""></span><br class=""></b></p><p class=""><b class=""><span class="">extension</span><span class=""> </span><span class="">CGFloat</span><span class=""> {</span></b></p><p class=""><span class=""><b class="">&nbsp;&nbsp; &nbsp;</b></span></p><p class=""><b class=""><span class="">&nbsp; &nbsp; </span><span class="">init</span><span class="">&lt;T: </span><span class="">Box</span><span class=""> </span><span class="">where</span><span class=""> </span><span class="">T</span><span class="">.</span><span class="">BoxType</span><span class=""> == </span><span class="">Double</span><span class=""> &gt;(</span><span class="">_</span><span class=""> box: </span><span class="">T</span><span class="">) {</span></b></p><p class=""><b class=""><span class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="">self</span><span class="">.</span><span class="">init</span><span class="">(box.</span><span class="">value</span><span class="">)</span></b></p><p class=""><span class=""><b class="">&nbsp; &nbsp; }</b></span></p><p class=""><span class=""><b class="">&nbsp;&nbsp; &nbsp;</b></span></p><p class=""><b class=""><span class="">&nbsp; &nbsp; </span><span class="">init</span><span class="">&lt;T: </span><span class="">Box</span><span class=""> </span><span class="">where</span><span class=""> </span><span class="">T</span><span class="">.</span><span class="">BoxType</span><span class=""> == </span><span class="">Int</span><span class=""> &gt;(</span><span class="">_</span><span class=""> box: </span><span class="">T</span><span class="">) {</span></b></p><p class=""><b class=""><span class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="">self</span><span class="">.</span><span class="">init</span><span class="">(box.</span><span class="">value</span><span class="">)</span></b></p><p class=""><span class=""><b class="">&nbsp; &nbsp; }</b></span></p><p class=""><span class=""><b class="">}</b></span></p><p class=""><b class=""><span class=""></span><br class=""></b></p><p class=""><span class=""><b class="">//Adding FloatLiteralConvertible, IntegerLiteralConvertible</b></span></p><p class=""><b class=""><span class=""></span><br class=""></b></p><p class=""><b class=""><span class="">extension</span><span class=""> </span><span class="">FloatingPointBox</span><span class=""> </span><span class="">where</span><span class=""> </span><span class="">Self</span><span class="">.BoxType == Double, </span><span class="">Self</span><span class="">.FloatLiteralConvertible == Double {</span></b></p><p class=""><span class=""><b class="">&nbsp;&nbsp; &nbsp;</b></span></p><p class=""><b class=""><span class="">&nbsp; &nbsp; </span><span class="">init</span><span class="">(floatLiteral value: </span><span class="">Double</span><span class="">) {</span></b></p><p class=""><b class=""><span class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="">self</span><span class="">.</span><span class="">init</span><span class="">(value)</span></b></p><p class=""><span class=""><b class="">&nbsp; &nbsp; }</b></span></p><p class=""><span class=""><b class="">&nbsp;&nbsp; &nbsp;</b></span></p><p class=""><b class=""><span class="">&nbsp; &nbsp; </span><span class="">init</span><span class="">(integerLiteral value: </span><span class="">Int</span><span class="">) {</span></b></p><p class=""><b class=""><span class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="">self</span><span class="">.</span><span class="">init</span><span class="">(value)</span></b></p><p class=""><span class=""><b class="">&nbsp; &nbsp; }</b></span></p><p class=""><span class=""><b class="">&nbsp;&nbsp; &nbsp;</b></span></p><p class=""><b class=""><span class="">&nbsp; &nbsp; </span><span class="">init</span><span class="">&lt;T: </span><span class="">IntegerType</span><span class="">&gt;(</span><span class="">_</span><span class=""> value: </span><span class="">T</span><span class="">) {</span></b></p><p class=""><b class=""><span class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="">self</span><span class="">.</span><span class="">init</span><span class="">(value)</span></b></p><p class=""><span class=""><b class="">&nbsp; &nbsp; }</b></span></p><p class=""><span class=""><b class="">}</b></span></p></div><div class=""><br class=""></div><div class="">Here is my example of using the Box protocol:</div><div class=""><p class=""><b class=""><span class="">struct</span><span class=""> Degree: </span><span class="">FloatingPointBox</span><span class=""> {</span></b></p><p class=""><span class=""><b class="">&nbsp;&nbsp; &nbsp;</b></span></p><p class=""><b class=""><span class="">&nbsp; &nbsp; </span><span class="">var</span><span class=""> value: </span><span class="">Double</span><span class=""> = </span><span class="">0</span></b></p><p class=""><span class=""><b class="">&nbsp;&nbsp; &nbsp;</b></span></p><p class=""><b class=""><span class="">&nbsp; &nbsp; </span><span class="">init</span><span class="">()</span></b></p><p class=""><span class=""><b class="">&nbsp; &nbsp; {</b></span></p><p class=""><span class=""><b class="">&nbsp; &nbsp; }</b></span></p><p class=""><span class=""><b class="">}</b></span></p><p class=""><b class=""><span class=""></span><br class=""></b></p><p class=""><b class=""><span class="">protocol</span><span class=""> DegreeConvertiable {</span></b></p><p class=""><span class=""><b class="">&nbsp;&nbsp; &nbsp;</b></span></p><p class=""><b class=""><span class="">&nbsp; &nbsp; </span><span class="">init</span><span class="">(degreeLiteral value: </span><span class="">Degree</span><span class="">)</span></b></p><p class=""><span class=""><b class="">}</b></span></p><p class=""><b class=""><span class=""></span><br class=""></b></p><p class=""><b class=""><span class="">extension</span><span class=""> </span><span class="">Degree</span><span class="">: </span><span class="">RadianConvertiable</span><span class=""> {</span></b></p><p class=""><span class=""><b class="">&nbsp;&nbsp; &nbsp;</b></span></p><p class=""><b class=""><span class="">&nbsp; &nbsp; </span><span class="">init</span><span class="">(radianLiteral value: </span><span class="">Radian</span><span class="">) {</span></b></p><p class=""><b class=""><span class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="">self</span><span class="">.</span><span class="">value</span><span class=""> = </span><span class="">Double</span><span class="">(value) * </span><span class="">180.0</span><span class=""> / </span><span class="">M_PI</span></b></p><p class=""><span class=""><b class="">&nbsp; &nbsp; }</b></span></p><p class=""><span class=""><b class="">&nbsp;&nbsp; &nbsp;</b></span></p><p class=""><b class=""><span class="">&nbsp; &nbsp; </span><span class="">init</span><span class="">(</span><span class="">_</span><span class=""> value: </span><span class="">Radian</span><span class="">) {</span></b></p><p class=""><b class=""><span class="">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="">self</span><span class="">.</span><span class="">init</span><span class="">(radianLiteral: value)</span></b></p><p class=""><span class=""><b class="">&nbsp; &nbsp; }</b></span></p><p class=""><span class=""><b class="">}</b></span></p></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Tue, Jan 5, 2016 at 5:24 PM, Matthew Johnson via swift-evolution <span dir="ltr" class="">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 0.8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br class=""> &gt; On Jan 5, 2016, at 11:16 AM, Thorsten Seitz via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""> &gt;<br class=""> &gt;<br class=""> &gt;&gt; Am 05.01.2016 um 17:11 schrieb Grzegorz Adam Hankiewicz via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;:<br class=""> &gt;&gt;<br class=""> &gt;&gt; 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.<br class=""> &gt;<br class=""> &gt; 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.<br class=""> <br class=""> </span>This is how my forwarding proposal works.&nbsp; The newtype syntax I suggested as a possible extension looks like this:<br class=""> <br class=""> newtype Euro = Double forwarding Addable, Subtractable<br class=""> <br class=""> The keyword could be different, but I think `forwarding` is not bad.&nbsp; When I complete the second draft I think it will make even more sense.&nbsp; The forwarding facility has features to handle non-trivial cases (Self and associated type requirements, etc).<br class=""><div class=""><div class=""><br class=""> &gt;<br class=""> &gt; Throwing some syntax into the discussion:<br class=""> &gt;<br class=""> &gt; newtype Euro = Double : Addable, Subtractable<br class=""> &gt;<br class=""> &gt; 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.<br class=""> &gt; The implementation of Euro then borrows the implementation of Double for these protocols.<br class=""> &gt;<br class=""> &gt; -Thorsten<br class=""> &gt; _______________________________________________<br class=""> &gt; swift-evolution mailing list<br class=""> &gt; <a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a><br class=""> &gt; <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""> <br class=""> _______________________________________________<br class=""> swift-evolution mailing list<br class=""> <a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a><br class=""> <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></div></blockquote></div><br class=""><br clear="all" class=""><div class=""><br class=""></div>-- <br class=""><div class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div dir="ltr" class=""><div class=""><span style="font-size:16px;line-height:19.2px" class=""></span><span style="font-size:12.8px" class="">&nbsp;Wizard</span><br class=""></div><div class=""><a href="mailto:james@supmenow.com" target="_blank" class="">james@supmenow.com</a><br class=""></div><div class=""><a href="tel:%2B44%207523%20279%20698" value="+447523279698" target="_blank" class="">+44 7523 279 698</a></div></div></div></div></div></div></div></div></blockquote></div></div>
</div></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=iRI3beHTe3UxYAHTlV3lA38zIPfHMhyuRzgTmGKV6k6HNcWkb74NUSDxUueppvCu9gpojaO9hZVqMXWA70bVvWq4J1cDLLsnYCBRPcUGX7vfztZpLXDs1P5H2vE26cBhlOl4jucx-2BKWb7f86owE-2FdQfvirepNc1UTNMZyHIL34yiksqtvFmL-2FGRj3aQHa6jALWWzQiX5Kmj-2B-2FAvgvnj-2FMA-3D-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important" class="">
</div><span class="">
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></span></div></blockquote></div><br class=""></div></div></blockquote></div><br class=""><br clear="all" class=""><div class=""><br class=""></div>-- <br class=""><div class="gmail_signature"><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div dir="ltr" class=""><div class=""><span style="font-size:16px;line-height:19.2px" class=""></span><span style="font-size:12.8px" class="">&nbsp;Wizard</span><br class=""></div><div class=""><a href="mailto:james@supmenow.com" target="_blank" class="">james@supmenow.com</a></div><div class="">+44 7523 279 698</div></div></div></div></div></div>
</div>
</div></blockquote></div><br class=""></div></div></body></html>