Repository : ssh://darcs.haskell.org//srv/darcs/packages/integer-simple

On branch  : master

http://hackage.haskell.org/trac/ghc/changeset/1f3ef8a1671cbc1a4e3641b193d5625e90fe9b66

>---------------------------------------------------------------

commit 1f3ef8a1671cbc1a4e3641b193d5625e90fe9b66
Author: Ian Lynagh <[email protected]>
Date:   Sat Sep 17 18:22:22 2011 +0100

    Define mkInteger
    
    Now used by GHC to generate Integer literals.

>---------------------------------------------------------------

 GHC/Integer.hs      |    2 +-
 GHC/Integer/Type.hs |   10 ++++++++++
 2 files changed, 11 insertions(+), 1 deletions(-)

diff --git a/GHC/Integer.hs b/GHC/Integer.hs
index 66e35c9..c9b50a7 100644
--- a/GHC/Integer.hs
+++ b/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/GHC/Integer/Type.hs b/GHC/Integer/Type.hs
index 7d1a90e..f5cdea3 100644
--- a/GHC/Integer/Type.hs
+++ b/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
 



_______________________________________________
Cvs-libraries mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/cvs-libraries

Reply via email to