diff options
author | Ian Lynagh <ian@well-typed.com> | 2012-09-23 21:45:11 +0100 |
---|---|---|
committer | Ian Lynagh <ian@well-typed.com> | 2012-09-23 21:45:11 +0100 |
commit | ca64cee6f870d2c51c558d8e7203345dfd5c7954 (patch) | |
tree | 60f2af16151a9cf533a038721965e51aa8cb9328 | |
parent | 4bda9677db3fe22615b2c6e39b54a0f491dccd87 (diff) | |
download | haskell-ca64cee6f870d2c51c558d8e7203345dfd5c7954.tar.gz |
Use finiteBitSize rather than bitSize when it is available
-rw-r--r-- | compiler/utils/Serialized.hs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/compiler/utils/Serialized.hs b/compiler/utils/Serialized.hs index 26cca6c386..902d2feea0 100644 --- a/compiler/utils/Serialized.hs +++ b/compiler/utils/Serialized.hs @@ -95,16 +95,26 @@ deserializeConstr bytes k = deserializeWord8 bytes $ \constr_ix bytes -> x -> error $ "deserializeConstr: unrecognised serialized constructor type " ++ show x ++ " in context " ++ show bytes +#if __GLASGOW_HASKELL__ < 707 serializeFixedWidthNum :: forall a. (Num a, Integral a, Bits a) => a -> [Word8] -> [Word8] serializeFixedWidthNum what = go (bitSize what) what +#else +serializeFixedWidthNum :: forall a. (Num a, Integral a, FiniteBits a) => a -> [Word8] -> [Word8] +serializeFixedWidthNum what = go (finiteBitSize what) what +#endif where go :: Int -> a -> [Word8] -> [Word8] go size current rest | size <= 0 = rest | otherwise = fromIntegral (current .&. 255) : go (size - 8) (current `shiftR` 8) rest +#if __GLASGOW_HASKELL__ < 707 deserializeFixedWidthNum :: forall a b. (Num a, Integral a, Bits a) => [Word8] -> (a -> [Word8] -> b) -> b deserializeFixedWidthNum bytes k = go (bitSize (undefined :: a)) bytes k +#else +deserializeFixedWidthNum :: forall a b. (Num a, Integral a, FiniteBits a) => [Word8] -> (a -> [Word8] -> b) -> b +deserializeFixedWidthNum bytes k = go (finiteBitSize (undefined :: a)) bytes k +#endif where go :: Int -> [Word8] -> (a -> [Word8] -> b) -> b go size bytes k |