<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Mar 2, 2016, at 1:23 PM, Tino Heth via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">I hope that I'll finally have the time to write a pitch for "inheritance for structs" this weekend — this looks like another good use case for a "newtype" feature:<br class=""><br class="">struct Length: Double {<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>static let tolerance: Double = 0.001<br class="">}<br class=""><br class="">override func ==(a: Length, b: Length) -&gt; Bool {<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>return (a - b).abs() &lt; Length.tolerance<br class="">}<br class=""><br class="">Of course, this example leaves many questions, but I hope the principle is clear.<br class=""></div></div></blockquote></div><br class=""><div class="">This is also a place where function partial application might be interesting:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class="">func equalityWithTolerance(tolerance: Double) -&gt; (Double, Double) -&gt; Bool {</div><div class="">&nbsp; return {</div><div class="">&nbsp; &nbsp; var exp0 = 0, exp1 = 0</div><div class="">&nbsp; &nbsp; frexp($0, &amp;exp0)</div><div class="">&nbsp; &nbsp; frexp($1, &amp;exp1)</div><div class="">&nbsp; &nbsp; return abs($0 - $1) &lt; scalb(tolerance, max(exp0, exp1))</div><div class="">&nbsp; }</div><div class="">}</div></blockquote><div class=""><br class=""></div><div class="">If you could locally bind operators, you could then do this:</div><div class=""><br class=""></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class="">func compareLengths(x: Double, y: Double) -&gt; Bool {</div><div class="">&nbsp; let (==) = equalityWithTolerance(0x1p-44)</div><div class="">&nbsp; return x == y // Uses local (==)</div><div class="">}</div><div class=""><br class=""></div></blockquote>-Joe</body></html>