<div dir="ltr">On Sun, Jan 29, 2017 at 2:03 PM, David Sweeris <span dir="ltr">&lt;<a href="mailto:davesweeris@mac.com" target="_blank">davesweeris@mac.com</a>&gt;</span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="auto"><span class="gmail-"><div><br></div><div>On Jan 29, 2017, at 10:36, Xiaodi Wu &lt;<a href="mailto:xiaodi.wu@gmail.com" target="_blank">xiaodi.wu@gmail.com</a>&gt; wrote:<br><br></div><blockquote type="cite">Hmm, interesting. I might be tempted to use a 40-bit type for large arrays, but the performance hit for any useful computation over a large array would probably tilt heavily in favor of plain 64-bit integers. What&#39;s your use case for such a 40-bit type? And is it common enough to justify such a facility in the stdlib vs. providing the tools to build it yourself?<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
</blockquote></div>
</blockquote><div><br></div></span>I can think of two use-cases. One — saving memory for large #s of allocations — you already mentioned. The other is for easing interactions with on-disk data. For example, if you&#39;re working with some format that has 24-bit ints, you could use &quot;CompoundWhateverItWasCalled&lt;<wbr>Int8,Int16&gt;&quot;. It doesn&#39;t make much difference when you&#39;re loading the data, but when you&#39;re writing it back out, you wouldn&#39;t have to worry about trimming that last byte or what to do if the value won&#39;t fit in 24 bits. I mean, obviously you&#39;d still have to handle it, but the overflow would happen in the calculation that causes it rather then while you&#39;re busy doing something else.<br><div><br></div><div>In terms of justification, I think probably all I can offer is that I <i>think</i> it wouldn&#39;t be materially harder or less efficient to implement this than it would be to write a &quot;DoubleWidth&lt;T&gt;&quot; type... It&#39;s extra functionality for free, at least in terms of effort. It would increase the API surface, but not by much. Assuming that &quot;DoubleWidth&quot; could just be a typealias, that is. If I&#39;m wrong about it being &quot;that easy&quot;, then I don&#39;t think it&#39;d be worth it. As you noted, it is somewhat niche.</div></div></blockquote><div><br></div><div>Unless I&#39;m mistaken, DoubleWidth would be implemented using doubleWidthMultiply and doubleWidthDivide facilities provided in these new integer protocols. As the protocol documentation says, DoubleWidth is really intended for wider types, not arbitrarily sized narrower ones. There&#39;s no obvious way I can see to implement the same thing for two types of unequal bit width, short of determining dynamically, at each operation, which of your two types has the larger bit width and truncating bits accordingly. So if you want a 24-bit Int, it&#39;s unclear to me why you&#39;d choose what&#39;s effectively DoubleWidth&lt;Int16&gt; minus 8 bits rather than Int32 minus 8 bits.</div><div><br></div></div></div></div>