From a7d561a002efa30619c88faa3f929bdc1967c206 Mon Sep 17 00:00:00 2001 From: ross Date: Fri, 14 Jan 2005 00:00:22 +0000 Subject: [PATCH] [project @ 2005-01-14 00:00:22 by ross] make these work with Hugs (pending the possible return of Word) and simplify the #if's a bit. --- Data/IntMap.hs | 58 ++++++++++++++++---------------------------------------- Data/IntSet.hs | 58 ++++++++++++++++---------------------------------------- 2 files changed, 32 insertions(+), 84 deletions(-) diff --git a/Data/IntMap.hs b/Data/IntMap.hs index cd3c2f9..ce9f3eb 100644 --- a/Data/IntMap.hs +++ b/Data/IntMap.hs @@ -146,63 +146,32 @@ import List (nub,sort) import qualified List -} -#ifdef __GLASGOW_HASKELL__ -{-------------------------------------------------------------------- - GHC: use unboxing to get @shiftRL@ inlined. ---------------------------------------------------------------------} #if __GLASGOW_HASKELL__ >= 503 import GHC.Word import GHC.Exts ( Word(..), Int(..), shiftRL# ) -#else +#elif __GLASGOW_HASKELL__ import Word import GlaExts ( Word(..), Int(..), shiftRL# ) +#else +import Data.Word #endif infixl 9 \\{-This comment teaches CPP correct behaviour -} -type Nat = Word - -natFromInt :: Key -> Nat -natFromInt i = fromIntegral i - -intFromNat :: Nat -> Key -intFromNat w = fromIntegral w - -shiftRL :: Nat -> Key -> Nat -shiftRL (W# x) (I# i) - = W# (shiftRL# x i) - -#elif __HUGS__ +#if __HUGS__ {-------------------------------------------------------------------- - Hugs: - * raises errors on boundary values when using 'fromIntegral' - but not with the deprecated 'fromInt/toInt'. - * Older Hugs doesn't define 'Word'. - * Newer Hugs defines 'Word' in the Prelude but no operations. + Hugs: + * Older Hugs doesn't define 'Word'. + * Newer Hugs defines 'Word' in the Prelude but no operations. --------------------------------------------------------------------} -import Data.Word -infixl 9 \\ - type Nat = Word32 -- illegal on 64-bit platforms! - -natFromInt :: Key -> Nat -natFromInt i = fromInt i - -intFromNat :: Nat -> Key -intFromNat w = toInt w - -shiftRL :: Nat -> Key -> Nat -shiftRL x i = shiftR x i - #else {-------------------------------------------------------------------- 'Standard' Haskell * A "Nat" is a natural machine word (an unsigned Int) --------------------------------------------------------------------} -import Data.Word -infixl 9 \\ - type Nat = Word +#endif natFromInt :: Key -> Nat natFromInt i = fromIntegral i @@ -211,11 +180,16 @@ intFromNat :: Nat -> Key intFromNat w = fromIntegral w shiftRL :: Nat -> Key -> Nat -shiftRL w i = shiftR w i - +#if __GLASGOW_HASKELL__ +{-------------------------------------------------------------------- + GHC: use unboxing to get @shiftRL@ inlined. +--------------------------------------------------------------------} +shiftRL (W# x) (I# i) + = W# (shiftRL# x i) +#else +shiftRL x i = shiftR x i #endif - {-------------------------------------------------------------------- Operators --------------------------------------------------------------------} diff --git a/Data/IntSet.hs b/Data/IntSet.hs index 90b9bd9..5023df6 100644 --- a/Data/IntSet.hs +++ b/Data/IntSet.hs @@ -103,64 +103,32 @@ import List (nub,sort) import qualified List -} - -#ifdef __GLASGOW_HASKELL__ -{-------------------------------------------------------------------- - GHC: use unboxing to get @shiftRL@ inlined. ---------------------------------------------------------------------} #if __GLASGOW_HASKELL__ >= 503 import GHC.Word import GHC.Exts ( Word(..), Int(..), shiftRL# ) -#else +#elif __GLASGOW_HASKELL__ import Word import GlaExts ( Word(..), Int(..), shiftRL# ) +#else +import Data.Word #endif infixl 9 \\{-This comment teaches CPP correct behaviour -} -type Nat = Word - -natFromInt :: Int -> Nat -natFromInt i = fromIntegral i - -intFromNat :: Nat -> Int -intFromNat w = fromIntegral w - -shiftRL :: Nat -> Int -> Nat -shiftRL (W# x) (I# i) - = W# (shiftRL# x i) - -#elif __HUGS__ +#if __HUGS__ {-------------------------------------------------------------------- - Hugs: - * raises errors on boundary values when using 'fromIntegral' - but not with the deprecated 'fromInt/toInt'. - * Older Hugs doesn't define 'Word'. - * Newer Hugs defines 'Word' in the Prelude but no operations. + Hugs: + * Older Hugs doesn't define 'Word'. + * Newer Hugs defines 'Word' in the Prelude but no operations. --------------------------------------------------------------------} -import Data.Word -infixl 9 \\ -- comment to fool cpp - type Nat = Word32 -- illegal on 64-bit platforms! - -natFromInt :: Int -> Nat -natFromInt i = fromInt i - -intFromNat :: Nat -> Int -intFromNat w = toInt w - -shiftRL :: Nat -> Int -> Nat -shiftRL x i = shiftR x i - #else {-------------------------------------------------------------------- 'Standard' Haskell * A "Nat" is a natural machine word (an unsigned Int) --------------------------------------------------------------------} -import Data.Word -infixl 9 \\ -- comment to fool cpp - type Nat = Word +#endif natFromInt :: Int -> Nat natFromInt i = fromIntegral i @@ -169,8 +137,14 @@ intFromNat :: Nat -> Int intFromNat w = fromIntegral w shiftRL :: Nat -> Int -> Nat -shiftRL w i = shiftR w i - +#if __GLASGOW_HASKELL__ +{-------------------------------------------------------------------- + GHC: use unboxing to get @shiftRL@ inlined. +--------------------------------------------------------------------} +shiftRL (W# x) (I# i) + = W# (shiftRL# x i) +#else +shiftRL x i = shiftR x i #endif {-------------------------------------------------------------------- -- 1.7.10.4