diff options
| author | Ian Lynagh <igloo@earth.li> | 2011-09-17 18:22:22 +0100 |
|---|---|---|
| committer | Ian Lynagh <igloo@earth.li> | 2011-09-17 18:22:22 +0100 |
| commit | f9dad24ec251c6a422c901c93b9a63f7aa343bb2 (patch) | |
| tree | 9baefb5c7db315c487fe63b112b04d479b89e751 | |
| parent | cd4d0fbf2e70bb699126848503482790c9570881 (diff) | |
| download | haskell-f9dad24ec251c6a422c901c93b9a63f7aa343bb2.tar.gz | |
Define mkInteger
Now used by GHC to generate Integer literals.
| -rw-r--r-- | libraries/integer-simple/GHC/Integer.hs | 2 | ||||
| -rw-r--r-- | libraries/integer-simple/GHC/Integer/Type.hs | 10 |
2 files changed, 11 insertions, 1 deletions
diff --git a/libraries/integer-simple/GHC/Integer.hs b/libraries/integer-simple/GHC/Integer.hs index 66e35c965f..c9b50a7cf5 100644 --- a/libraries/integer-simple/GHC/Integer.hs +++ b/libraries/integer-simple/GHC/Integer.hs @@ -18,7 +18,7 @@ #include "MachDeps.h" module GHC.Integer ( - Integer, + Integer, mkInteger, smallInteger, wordToInteger, integerToWord, integerToInt, #if WORD_SIZE_IN_BITS < 64 integerToWord64, word64ToInteger, diff --git a/libraries/integer-simple/GHC/Integer/Type.hs b/libraries/integer-simple/GHC/Integer/Type.hs index 7d1a90edca..f5cdea3fd5 100644 --- a/libraries/integer-simple/GHC/Integer/Type.hs +++ b/libraries/integer-simple/GHC/Integer/Type.hs @@ -51,6 +51,16 @@ type Digit = Word# -- XXX Could move [] above us data List a = Nil | Cons a (List a) +mkInteger :: Bool -- non-negative? + -> [Int] -- absolute value in 31 bit chunks, least significant first + -- ideally these would be Words rather than Ints, but + -- we don't have Word available at the moment. + -> Integer +mkInteger nonNegative is = let abs = f is + in if nonNegative then abs else negateInteger abs + where f [] = S# 0# + f (I# i : is') = S# i `orInteger` shiftLInteger (f is') 31# + errorInteger :: Integer errorInteger = Positive errorPositive |
