<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 7, 2016, at 4:06 AM, James Campbell via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" style="font-family: MyriadSet-Text; font-size: 12.75px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" 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. </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></div></blockquote><br class=""></div><div>I took a different approach to this, which was to typealias Angle to Double, keep all Angles 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><div><br class=""></div><div>I would like to see Angle, along with several other basic geometric concepts, promoted to the Swift standard library. </div><div><br class=""></div><div>-jcr</div><div><br class=""></div></body></html>