summaryrefslogtreecommitdiff
path: root/libraries/base/Text
diff options
context:
space:
mode:
authorHerbert Valerio Riedel <hvr@gnu.org>2014-11-22 00:15:42 +0100
committerHerbert Valerio Riedel <hvr@gnu.org>2014-11-22 01:03:55 +0100
commit8a8cdbbfd855015049526c7945cbe9ccbb152f1e (patch)
tree700e0ef50eab611b67d4f64608fd701170b27709 /libraries/base/Text
parent137b33133f49a994e5d147c5b30a8fcfc610eada (diff)
downloadhaskell-8a8cdbbfd855015049526c7945cbe9ccbb152f1e.tar.gz
Implement `Natural` number type (re #9818)
This implements a `Natural` type for representing unsigned arbitrary precision integers. When available, `integer-gmp>=1.0.0`'s `BigNat` type is used as building-block to construct `Natural` as an algebraic data-type. Otherwise, `Natural` falls back being a `newtype`-wrapper around `Integer` (as is done in Edward Kmett's `nats` package). The `GHC.Natural` module exposes an internal GHC-specific API, while `Numeric.Natural` provides the official & portable API. Reviewed By: austin, ekmett Differential Revision: https://phabricator.haskell.org/D473
Diffstat (limited to 'libraries/base/Text')
-rw-r--r--libraries/base/Text/Printf.hs5
1 files changed, 5 insertions, 0 deletions
diff --git a/libraries/base/Text/Printf.hs b/libraries/base/Text/Printf.hs
index 9ad67d0f10..6c911daea7 100644
--- a/libraries/base/Text/Printf.hs
+++ b/libraries/base/Text/Printf.hs
@@ -96,6 +96,7 @@ import Data.Int
import Data.List
import Data.Word
import Numeric
+import Numeric.Natural
import System.IO
-------------------
@@ -368,6 +369,10 @@ instance PrintfArg Integer where
formatArg = formatInteger
parseFormat = parseIntFormat
+instance PrintfArg Natural where
+ formatArg = formatInteger . toInteger
+ parseFormat = parseIntFormat
+
instance PrintfArg Float where
formatArg = formatRealFloat