<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="">Am 20.01.2016 um 18:16 schrieb Dave Abrahams via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>>:</div><br class="Apple-interchange-newline"><div class=""><div class=""><br class="">on Wed Jan 13 2016, Thorsten Seitz via swift-evolution <<a href="http://swift-evolution-m3fhrko0vlzytjvyw6ydsg-at-public.gmane.org" class="">swift-evolution-m3FHrko0VLzYtjvyW6yDsg-AT-public.gmane.org</a>> wrote:<br class=""><br class=""><blockquote type="cite" class=""><blockquote type="cite" class="">Am 13.01.2016 um 00:06 schrieb Dave Abrahams<br class=""><<a href="mailto:dabrahams@apple.com" class="">dabrahams@apple.com</a>>:<br class=""><br class=""><blockquote type="cite" class="">On Jan 7, 2016, at 10:46 AM, Thorsten Seitz<br class=""><<a href="mailto:tseitz42@icloud.com" class="">tseitz42@icloud.com</a>> wrote:<br class=""></blockquote></blockquote><br class=""><blockquote type="cite" class=""><blockquote type="cite" class=""><br class="">Really great to hear that you are planning for Swift to be able to<br class="">do these kinds of things!<br class=""><br class="">I tried to see how far I could get (working from memory of a<br class="">Haskell library; Boost.Units seems quite similar at first glance),<br class="">but failed of course because of the missing parameterized recursive<br class="">typealiases:<br class=""></blockquote><br class="">Sadly, the lack of the ability to define a pretty shorthand for<br class="">quantities is not what stands in the way, fundamentally.<br class=""></blockquote><br class="">I'm afraid I don't get your meaning here. Would you mind to explain a bit more?<br class="">Thanks!<br class=""></blockquote><br class="">Typealiases are just about creating new names for existing types. The<br class="">inability to even form the correct type when an an acceleration is<br class="">multiplied by a time is the more fundamental issue. You need to add<br class="">corresponding powers of the fundamental dimensions.<br class=""></div></div></blockquote><div><br class=""></div>Ah, thanks for explaining what you meant!</div><div>Actually that’s what the generic recursive typealiases Add and Sub I defined in my example are for: they effectively provide addition and subtraction for Peano numbers implemented in the type system (that’s the way it works in Haskell).</div><div><br class=""></div><div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">typealias</span> Add<Zero, P: Peano> = P</div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">typealias</span> Add<P: Peano, Zero> = P</div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">typealias</span> Add<Succ<P1>, Succ<P2>> = Add<Succ<Succ<P1>>,P2></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">typealias</span> Add<Succ<P1>, Pred<P2>> = Add<P1,P2></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">typealias</span> Add<Pred<P1>, Succ<P2>> = Add<P1,P2></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">typealias</span> Add<Pred<P1>, Pred<P2>> = Add<P1,Pred<Pred<P2>>></div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(133, 153, 1);" class="">public<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class=""> </span>func<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class=""> *</span></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class=""> <L1,T1,M1,L2,T2,M2,L,T,M <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">where</span></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">L</span> == <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Add</span><<span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">L1</span>,<span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">L2</span>>, <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">T</span> == <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Add</span><<span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">T1</span>,<span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">T2</span>>, <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">M</span> == <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Add</span><<span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">M1</span>,<span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">M2</span>>></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(181, 137, 1);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #839496" class=""> (lhs: </span>Quantity<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class=""><</span>L1<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">,</span>T1<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">,</span>M1<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">>, rhs: </span>Quantity<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class=""><</span>L2<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">,</span>T2<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">,</span>M2<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">>) -> </span>Quantity<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class=""><</span>L<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">,</span>T<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">,</span>M<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">></span></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class="">{</div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">return</span> <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">Quantity</span><<span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">L</span>,<span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">T</span>,<span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">M</span>>(lhs.<span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">value</span> * rhs.<span style="font-variant-ligatures: no-common-ligatures; color: #d33682" class="">value</span>)</div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class="">}</div></div><div class=""><br class=""></div></div><div>Having integers as generic parameters with the possibility of adding them is much nicer, though, as the Peano numbers are no longer needed and everything is much easier to understand. The adaption of my example to that feature was in my other mail, e.g.</div><div><br class=""></div><div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(133, 153, 1);" class="">public<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class=""> </span>func<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class=""> *</span></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class=""> <L1,T1,M1,L2,T2,M2,L,T,M <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">where</span> <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">L</span> == <span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">L1</span>+L2, T == T1+T2, M == M1+M2></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(181, 137, 1);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #839496" class=""> (lhs: </span>Quantity<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class=""><</span>L1<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">,</span>T1<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">,</span>M1<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">>, rhs: </span>Quantity<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class=""><</span>L2<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">,</span>T2<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">,</span>M2<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">>) -> </span>Quantity<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class=""><</span>L<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">,</span>T<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">,</span>M<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">></span></div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class="">{</div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class=""> <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">return</span> Quantity<<span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">L</span>,<span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">T</span>,<span style="font-variant-ligatures: no-common-ligatures; color: #b58901" class="">M</span>>(lhs.value * rhs.value)</div><div style="margin: 0px; font-size: 13px; line-height: normal; font-family: Menlo; color: rgb(131, 148, 150);" class="">}</div><div class=""><br class=""></div></div><div><br class=""></div><div>-Thorsten</div></body></html>