<div dir="auto">Awsome: it’d be good to provide the explicitly word32 and word64 flavors too for multi platform portability. </div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Sep 16, 2020 at 4:59 AM Sylvain Henry <<a href="mailto:sylvain@haskus.fr">sylvain@haskus.fr</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br><br>  <br><br>    <br><br>  <br><br>  <div><br><br>    <p>We can easily add this function to ghc-bignum.</p><br><br>    <p>I've opened <a href="https://gitlab.haskell.org/ghc/ghc/-/issues/18697" target="_blank">https://gitlab.haskell.org/ghc/ghc/-/issues/18697</a> to<br><br>      track this.</p></div><div><br><br>    <p>Sylvain<br><br><br>    </p><br><br>    <div>On 16/09/2020 04:19, Keith wrote:<br><br><br>    </div><br><br>    <blockquote type="cite"><br><br>      <br><br>      The short of it is,<br><br><br>      <br><br><br>      clampNaturalToWord :: Natural → Word<br><br><br>      clampNaturalToWord n = case n of<br><br><br>      NatS# w -> W# w<br><br><br>      _ -> maxBound<br><br><br>      <br><br><br>      results in much better space and time use than naturalToWord,<br><br>      which always takes the least significant Word of the Natural.<br><br><br>      <br><br><br>      <br><br><br>      Because naturalToWord takes the least significant Word, you always<br><br>      have to check for size before conversion. Even though you do<br><br>      check, GHC has to assume that, after conversion, the big Natural<br><br>      could have resulted in a small Word and will uselessly duplicate<br><br>      all branches for both cases.<br><br><br>      <br><br><br>      Is there anything wrong with clamping by default in this case?<br><br><br>      <br><br><br>      --Keith<br><br><br>      <br><br><br>      Sent from my phone with K-9 Mail.<br><br>      <br><br><br>      <fieldset></fieldset><br><br>      <pre>_______________________________________________<br><br>Libraries mailing list<br><br><a href="mailto:Libraries@haskell.org" target="_blank">Libraries@haskell.org</a><br><br><a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br><br></pre><br><br>    </blockquote><br><br>  </div><br><br><br><br>_______________________________________________<br><br>Libraries mailing list<br><br><a href="mailto:Libraries@haskell.org" target="_blank">Libraries@haskell.org</a><br><br><a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br><br></blockquote></div></div>