summaryrefslogtreecommitdiff
path: root/libraries/base/Data/Bits.hs
diff options
context:
space:
mode:
authorIan Lynagh <ian@well-typed.com>2012-10-25 17:13:36 +0100
committerIan Lynagh <ian@well-typed.com>2012-10-25 17:13:36 +0100
commita66b6ff039bb38bb978e090cc52f319810884000 (patch)
tree6a1f7414f1a6827e6ee23dc1aee781f88c1a67d6 /libraries/base/Data/Bits.hs
parent6f847e97b37e552232be1e72b7f5ec493120a9d3 (diff)
downloadhaskell-a66b6ff039bb38bb978e090cc52f319810884000.tar.gz
Make sure testBit and bit get inlined; fixes #7292
Diffstat (limited to 'libraries/base/Data/Bits.hs')
-rw-r--r--libraries/base/Data/Bits.hs8
1 files changed, 6 insertions, 2 deletions
diff --git a/libraries/base/Data/Bits.hs b/libraries/base/Data/Bits.hs
index 5b1e1d438c..abbadbd665 100644
--- a/libraries/base/Data/Bits.hs
+++ b/libraries/base/Data/Bits.hs
@@ -252,18 +252,22 @@ class Eq a => Bits a where
class Bits b => FiniteBits b where
finiteBitSize :: b -> Int
+-- The defaults below are written with lambdas so that e.g.
+-- bit = bitDefault
+-- is fully applied, so inlining will happen
+
-- | Default implementation for 'bit'.
--
-- Note that: @bitDefault i = 1 `shiftL` i@
bitDefault :: (Bits a, Num a) => Int -> a
-bitDefault i = 1 `shiftL` i
+bitDefault = \i -> 1 `shiftL` i
{-# INLINE bitDefault #-}
-- | Default implementation for 'testBit'.
--
-- Note that: @testBitDefault x i = (x .&. bit i) /= 0@
testBitDefault :: (Bits a, Num a) => a -> Int -> Bool
-testBitDefault x i = (x .&. bit i) /= 0
+testBitDefault = \x i -> (x .&. bit i) /= 0
{-# INLINE testBitDefault #-}
-- | Default implementation for 'popCount'.