<div dir="auto">That pretty much sums it up.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Mar 22, 2020, 17:55 chessai . <<a href="mailto:chessai1996@gmail.com">chessai1996@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Sure, I don't see why not. I think powModNatural is also safe.<br>
<br>
Are your criteria for a function worth re-exporting from Numeric.Natural that<br>
<br>
1. The function does not have an overloaded variant defined in base<br>
(e.g. all the monorphic version of `fromIntegral` in GHC.Natural would<br>
be excluded) and<br>
2. The function is total?<br>
<br>
Thanks<br>
<br>
On Sun, Mar 22, 2020 at 11:40 AM Zemyla <<a href="mailto:zemyla@gmail.com" target="_blank" rel="noreferrer">zemyla@gmail.com</a>> wrote:<br>
><br>
> Functions in GHC.Natural like naturalToWordMaybe and minusNaturalMaybe are extremely useful, especially when trying to write provably total functions, and I wish they were available in a Safe module like Numeric.Natural. I also want a total function that does the following:<br>
><br>
> -- This function turns an Integer n into a pair of<br>
> -- (fromInteger (abs n), fromInteger (signum n)).<br>
> integerToNaturalSign :: Integer -> (Natural, Int)<br>
> #if 0<br>
> -- This is the reference version, except for the fact that numeric literals don't exist yet<br>
> -- when GHC.Natural is being defined, and fromInteger isn't actually total.<br>
> integerToNaturalSign n = case compare n 0 of<br>
>   LT -> (fromInteger (negate n), -1)<br>
>   EQ -> (0, 0)<br>
>   GT -> (fromInteger n, 1)<br>
> #elif !defined(MIN_VERSION_integer_gmp)<br>
> -- This is like the reference version, except using the newtype wrapper and MagicHash.<br>
> integerToNaturalSign n = case compare n (intToInteger# 0#) of<br>
>   LT -> (Natural (negateInteger n), I# (-1#))<br>
>   EQ -> (Natural n, I# 0#)<br>
>   GT -> (Natural n, I# 1#)<br>
> #else<br>
> -- We take advantage of the GMP functions and constructors.<br>
> integerToNaturalSign (Jn# bn) = (bigNatToNatural bn, I# (-1#))<br>
> integerToNaturalSign (S# i#) = case isTrue# (i# <# 0#) of<br>
>   True -> (NatS# (int2Word# (negateInt# i#)), I# (-1#))<br>
>   _    -> (NatS# (int2Word# i#), I# (i# ># 0#))<br>
> integerToNaturalSign (Jp# bn) = (bigNatToNatural bn, I# 1#)<br>
> #endif<br>
> _______________________________________________<br>
> Libraries mailing list<br>
> <a href="mailto:Libraries@haskell.org" target="_blank" rel="noreferrer">Libraries@haskell.org</a><br>
> <a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries" rel="noreferrer noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries</a><br>
</blockquote></div>