<div dir="ltr">Interesting could you upload :) would be good to consolidate all the approaches we have right now so we can come up with the best one:<div><br></div><div>So far we have:</div><div><br></div><div>- Box/Unit Type Protocol (My Solution)</div><div>- Math Group Protocol (Tino Heth)</div><div>- Computed typealias (John Randolph)</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 7, 2016 at 2:55 PM, John Randolph via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><div><div style="word-wrap:break-word"><span class=""><br><div><blockquote type="cite"><div>On Jan 7, 2016, at 4:06 AM, James Campbell via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div><br><div><div dir="ltr" style="font-family:MyriadSet-Text;font-size:12.75px;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">So this is how this feature could be achieved right now with minimal changes to the language.<div><br></div><div>- 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>- 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. </div><div>- 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>- 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></div></blockquote><br></div></span><div>I took a different approach to this, which was to just typealias Angle to Double,  keep all Angle values as radians (since the stdlib trig functions take radians), and add some computed setters and getters to let me access an Angle in radians, degrees, or grads.</div><span class=""><div><br></div><div>I would like to see Angle, along with several other basic geometric concepts, promoted to the Swift standard library. </div><div><br></div><div>-jcr</div></span></div></div></div><br>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=xV0JY-2FdZMnUMvSFtZnLiBPRTDDOSQf3-2FpH33HYOlBxFUeA1qfgrAvnZzNdBt3k7Z8JorPwUolivYPI01b8tLIb8dbX2fq47jEUdQJ8-2F16Op3-2B3A4OxWdHQPVbVvunVDHvCai-2BPjCTuooMQZ9uPeMQkdUfwLJb6NLtEfqic6DvyLjg9CVksJmixykYOHyCGxtWNqM7YuSP8Pnj849-2BP5Nnu5EbuIabX3IX6-2BeO7AFMAE-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">
</div>
<br>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div><span style="font-size:16px;line-height:19.2px"></span><span style="font-size:12.8px"> Wizard</span><br></div><div><a href="mailto:james@supmenow.com" target="_blank">james@supmenow.com</a></div><div>+44 7523 279 698</div></div></div></div></div></div>
</div>