diff options
author | Koz Ross <koz.ross@retro-freedom.nz> | 2021-04-11 13:06:32 +1200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-05-19 23:31:51 -0400 |
commit | baa969c39b511cad42ac4f806205fffffe201f5b (patch) | |
tree | 0129d378cfbef540e5580a88b7670c5b83a5b440 /libraries/base | |
parent | 60f088b3c24253375e4ddf3ad72fea3c47f3a1b7 (diff) | |
download | haskell-baa969c39b511cad42ac4f806205fffffe201f5b.tar.gz |
Implement bitwise infix ops
Diffstat (limited to 'libraries/base')
-rw-r--r-- | libraries/base/Data/Bits.hs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/libraries/base/Data/Bits.hs b/libraries/base/Data/Bits.hs index 92e94dfd39..9600bb1654 100644 --- a/libraries/base/Data/Bits.hs +++ b/libraries/base/Data/Bits.hs @@ -53,6 +53,8 @@ module Data.Bits ( popCountDefault, toIntegralSized, oneBits, + (.^.), + (.>>.), (.<<.), (!>>.), (!<<.), -- * Newtypes And(..), Ior(..), Xor(..), Iff(..) ) where @@ -87,6 +89,46 @@ oneBits :: (FiniteBits a) => a oneBits = complement zeroBits {-# INLINE oneBits #-} +-- | Infix version of 'xor'. +-- +-- @since 4.17 +(.^.) :: (Bits a) => a -> a -> a +(.^.) = xor + +infixl 6 .^. + +-- | Infix version of 'shiftR'. +-- +-- @since 4.17 +(.>>.) :: (Bits a) => a -> Int -> a +(.>>.) = shiftR + +infixl 8 .>>. + +-- | Infix version of 'shiftL'. +-- +-- @since 4.17 +(.<<.) :: (Bits a) => a -> Int -> a +(.<<.) = shiftL + +infixl 8 .<<. + +-- | Infix version of 'unsafeShiftR'. +-- +-- @since 4.17 +(!>>.) :: (Bits a) => a -> Int -> a +(!>>.) = unsafeShiftR + +infixl 8 !>>. + +-- | Infix version of 'unsafeShiftL'. +-- +-- @since 4.17 +(!<<.) :: (Bits a) => a -> Int -> a +(!<<.) = unsafeShiftL + +infixl 8 !<<. + -- | Monoid under bitwise AND. -- -- >>> getAnd (And 0xab <> And 0x12) :: Word8 |