<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 <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> 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) -> Bool {<br class=""><span class="Apple-tab-span" style="white-space:pre">        </span>return (a - b).abs() < 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) -> (Double, Double) -> Bool {</div><div class=""> return {</div><div class=""> var exp0 = 0, exp1 = 0</div><div class=""> frexp($0, &exp0)</div><div class=""> frexp($1, &exp1)</div><div class=""> return abs($0 - $1) < scalb(tolerance, max(exp0, exp1))</div><div class=""> }</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) -> Bool {</div><div class=""> let (==) = equalityWithTolerance(0x1p-44)</div><div class=""> return x == y // Uses local (==)</div><div class="">}</div><div class=""><br class=""></div></blockquote>-Joe</body></html>