<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 &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt;:</div><br class="Apple-interchange-newline"><div class=""><div class=""><br class="">on Wed Jan 13 2016, Thorsten Seitz via swift-evolution &lt;<a href="http://swift-evolution-m3fhrko0vlzytjvyw6ydsg-at-public.gmane.org" class="">swift-evolution-m3FHrko0VLzYtjvyW6yDsg-AT-public.gmane.org</a>&gt; 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="">&lt;<a href="mailto:dabrahams@apple.com" class="">dabrahams@apple.com</a>&gt;:<br class=""><br class=""><blockquote type="cite" class="">On Jan 7, 2016, at 10:46 AM, Thorsten Seitz<br class="">&lt;<a href="mailto:tseitz42@icloud.com" class="">tseitz42@icloud.com</a>&gt; 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. &nbsp;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. &nbsp;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&lt;Zero, P: Peano&gt; = 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&lt;P: Peano, Zero&gt; = 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&lt;Succ&lt;P1&gt;, Succ&lt;P2&gt;&gt; = Add&lt;Succ&lt;Succ&lt;P1&gt;&gt;,P2&gt;</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&lt;Succ&lt;P1&gt;, Pred&lt;P2&gt;&gt; = Add&lt;P1,P2&gt;</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&lt;Pred&lt;P1&gt;, Succ&lt;P2&gt;&gt; = Add&lt;P1,P2&gt;</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&lt;Pred&lt;P1&gt;, Pred&lt;P2&gt;&gt; = Add&lt;P1,Pred&lt;Pred&lt;P2&gt;&gt;&gt;</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="">&nbsp; &nbsp; &lt;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="">&nbsp; &nbsp; <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>&lt;<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>&gt;, <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>&lt;<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>&gt;, <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>&lt;<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>&gt;&gt;</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="">&nbsp; &nbsp; (lhs: </span>Quantity<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">&lt;</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="">&gt;, rhs: </span>Quantity<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">&lt;</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="">&gt;) -&gt; </span>Quantity<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">&lt;</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="">&gt;</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="">&nbsp; &nbsp; <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>&lt;<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>&gt;(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="">&nbsp; &nbsp; &lt;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&gt;</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="">&nbsp; &nbsp; (lhs: </span>Quantity<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">&lt;</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="">&gt;, rhs: </span>Quantity<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">&lt;</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="">&gt;) -&gt; </span>Quantity<span style="font-variant-ligatures: no-common-ligatures; color: #839496" class="">&lt;</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="">&gt;</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="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #859901" class="">return</span> Quantity&lt;<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>&gt;(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>