{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE Trustworthy #-}

-----------------------------------------------------------------------------
-- |
-- Module      :  Data.Bits
-- Copyright   :  (c) The University of Glasgow 2001
-- License     :  BSD-style (see the file libraries/base/LICENSE)
--
-- Maintainer  :  libraries@haskell.org
-- Stability   :  experimental
-- Portability :  portable
--
-- This module defines bitwise operations for signed and unsigned
-- integers.  Instances of the class 'Bits' for the 'Int' and
-- 'Integer' types are available from this module, and instances for
-- explicitly sized integral types are available from the
-- "Data.Int" and "Data.Word" modules.
--
-----------------------------------------------------------------------------

module Data.Bits (
  -- * Type classes
  Bits(
    (.&.), (.|.), xor,
    complement,
    shift,
    rotate,
    zeroBits,
    bit,
    setBit,
    clearBit,
    complementBit,
    testBit,
    bitSizeMaybe,
    bitSize,
    isSigned,
    shiftL, shiftR,
    unsafeShiftL, unsafeShiftR,
    rotateL, rotateR,
    popCount
  ),
  FiniteBits(
    finiteBitSize,
    countLeadingZeros,
    countTrailingZeros
  ),
  -- * Extra functions
  bitDefault,
  testBitDefault,
  popCountDefault,
  toIntegralSized,
  oneBits,
  (.^.),
  (.>>.), (.<<.), (!>>.), (!<<.),
  -- * Newtypes
  And(..), Ior(..), Xor(..), Iff(..)
 ) where

import GHC.Base
import GHC.Bits
import GHC.Enum
import qualified GHC.List as List
import GHC.Read
import GHC.Show

-- $setup
-- >>> import Prelude
-- >>> import Data.Word

-- | A more concise version of @complement zeroBits@.
--
-- >>> complement (zeroBits :: Word) == (oneBits :: Word)
-- True
--
-- >>> complement (oneBits :: Word) == (zeroBits :: Word)
-- True
--
-- = Note
--
-- The constraint on 'oneBits' is arguably too strong. However, as some types
-- (such as 'Natural') have undefined 'complement', this is the only safe
-- choice.
--
-- @since 4.16
oneBits :: (FiniteBits a) => a
oneBits :: forall a. FiniteBits a => a
oneBits = a -> a
forall a. Bits a => a -> a
complement a
forall a. Bits a => a
zeroBits
{-# INLINE oneBits #-}

-- | Infix version of 'xor'.
--
-- @since 4.17
(.^.) :: (Bits a) => a -> a -> a
.^. :: forall a. Bits a => a -> a -> a
(.^.) = a -> a -> a
forall a. Bits a => a -> a -> a
xor

infixl 6 .^.

-- | Infix version of 'shiftR'.
--
-- @since 4.17
(.>>.) :: (Bits a) => a -> Int -> a
.>>. :: forall a. Bits a => a -> Int -> a
(.>>.) = a -> Int -> a
forall a. Bits a => a -> Int -> a
shiftR

infixl 8 .>>.

-- | Infix version of 'shiftL'.
--
-- @since 4.17
(.<<.) :: (Bits a) => a -> Int -> a
.<<. :: forall a. Bits a => a -> Int -> a
(.<<.) = a -> Int -> a
forall a. Bits a => a -> Int -> a
shiftL

infixl 8 .<<.

-- | Infix version of 'unsafeShiftR'.
--
-- @since 4.17
(!>>.) :: (Bits a) => a -> Int -> a
!>>. :: forall a. Bits a => a -> Int -> a
(!>>.) = a -> Int -> a
forall a. Bits a => a -> Int -> a
unsafeShiftR

infixl 8 !>>.

-- | Infix version of 'unsafeShiftL'.
--
-- @since 4.17
(!<<.) :: (Bits a) => a -> Int -> a
!<<. :: forall a. Bits a => a -> Int -> a
(!<<.) = a -> Int -> a
forall a. Bits a => a -> Int -> a
unsafeShiftL

infixl 8 !<<.

-- | Monoid under bitwise AND.
--
-- >>> getAnd (And 0xab <> And 0x12) :: Word8
-- 2
--
-- @since 4.16
newtype And a = And { forall a. And a -> a
getAnd :: a }
  deriving newtype (
                    And a
And a -> And a -> Bounded (And a)
forall a. a -> a -> Bounded a
forall a. Bounded a => And a
$cminBound :: forall a. Bounded a => And a
minBound :: And a
$cmaxBound :: forall a. Bounded a => And a
maxBound :: And a
Bounded, -- ^ @since 4.16
                    Int -> And a
And a -> Int
And a -> [And a]
And a -> And a
And a -> And a -> [And a]
And a -> And a -> And a -> [And a]
(And a -> And a)
-> (And a -> And a)
-> (Int -> And a)
-> (And a -> Int)
-> (And a -> [And a])
-> (And a -> And a -> [And a])
-> (And a -> And a -> [And a])
-> (And a -> And a -> And a -> [And a])
-> Enum (And a)
forall a. Enum a => Int -> And a
forall a. Enum a => And a -> Int
forall a. Enum a => And a -> [And a]
forall a. Enum a => And a -> And a
forall a. Enum a => And a -> And a -> [And a]
forall a. Enum a => And a -> And a -> And a -> [And a]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: forall a. Enum a => And a -> And a
succ :: And a -> And a
$cpred :: forall a. Enum a => And a -> And a
pred :: And a -> And a
$ctoEnum :: forall a. Enum a => Int -> And a
toEnum :: Int -> And a
$cfromEnum :: forall a. Enum a => And a -> Int
fromEnum :: And a -> Int
$cenumFrom :: forall a. Enum a => And a -> [And a]
enumFrom :: And a -> [And a]
$cenumFromThen :: forall a. Enum a => And a -> And a -> [And a]
enumFromThen :: And a -> And a -> [And a]
$cenumFromTo :: forall a. Enum a => And a -> And a -> [And a]
enumFromTo :: And a -> And a -> [And a]
$cenumFromThenTo :: forall a. Enum a => And a -> And a -> And a -> [And a]
enumFromThenTo :: And a -> And a -> And a -> [And a]
Enum, -- ^ @since 4.16
                    Eq (And a)
And a
Eq (And a)
-> (And a -> And a -> And a)
-> (And a -> And a -> And a)
-> (And a -> And a -> And a)
-> (And a -> And a)
-> (And a -> Int -> And a)
-> (And a -> Int -> And a)
-> And a
-> (Int -> And a)
-> (And a -> Int -> And a)
-> (And a -> Int -> And a)
-> (And a -> Int -> And a)
-> (And a -> Int -> Bool)
-> (And a -> Maybe Int)
-> (And a -> Int)
-> (And a -> Bool)
-> (And a -> Int -> And a)
-> (And a -> Int -> And a)
-> (And a -> Int -> And a)
-> (And a -> Int -> And a)
-> (And a -> Int -> And a)
-> (And a -> Int -> And a)
-> (And a -> Int)
-> Bits (And a)
Int -> And a
And a -> Bool
And a -> Int
And a -> Maybe Int
And a -> And a
And a -> Int -> Bool
And a -> Int -> And a
And a -> And a -> And a
forall a.
Eq a
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> a
-> (Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> Bool)
-> (a -> Maybe Int)
-> (a -> Int)
-> (a -> Bool)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int)
-> Bits a
forall {a}. Bits a => Eq (And a)
forall a. Bits a => And a
forall a. Bits a => Int -> And a
forall a. Bits a => And a -> Bool
forall a. Bits a => And a -> Int
forall a. Bits a => And a -> Maybe Int
forall a. Bits a => And a -> And a
forall a. Bits a => And a -> Int -> Bool
forall a. Bits a => And a -> Int -> And a
forall a. Bits a => And a -> And a -> And a
$c.&. :: forall a. Bits a => And a -> And a -> And a
.&. :: And a -> And a -> And a
$c.|. :: forall a. Bits a => And a -> And a -> And a
.|. :: And a -> And a -> And a
$cxor :: forall a. Bits a => And a -> And a -> And a
xor :: And a -> And a -> And a
$ccomplement :: forall a. Bits a => And a -> And a
complement :: And a -> And a
$cshift :: forall a. Bits a => And a -> Int -> And a
shift :: And a -> Int -> And a
$crotate :: forall a. Bits a => And a -> Int -> And a
rotate :: And a -> Int -> And a
$czeroBits :: forall a. Bits a => And a
zeroBits :: And a
$cbit :: forall a. Bits a => Int -> And a
bit :: Int -> And a
$csetBit :: forall a. Bits a => And a -> Int -> And a
setBit :: And a -> Int -> And a
$cclearBit :: forall a. Bits a => And a -> Int -> And a
clearBit :: And a -> Int -> And a
$ccomplementBit :: forall a. Bits a => And a -> Int -> And a
complementBit :: And a -> Int -> And a
$ctestBit :: forall a. Bits a => And a -> Int -> Bool
testBit :: And a -> Int -> Bool
$cbitSizeMaybe :: forall a. Bits a => And a -> Maybe Int
bitSizeMaybe :: And a -> Maybe Int
$cbitSize :: forall a. Bits a => And a -> Int
bitSize :: And a -> Int
$cisSigned :: forall a. Bits a => And a -> Bool
isSigned :: And a -> Bool
$cshiftL :: forall a. Bits a => And a -> Int -> And a
shiftL :: And a -> Int -> And a
$cunsafeShiftL :: forall a. Bits a => And a -> Int -> And a
unsafeShiftL :: And a -> Int -> And a
$cshiftR :: forall a. Bits a => And a -> Int -> And a
shiftR :: And a -> Int -> And a
$cunsafeShiftR :: forall a. Bits a => And a -> Int -> And a
unsafeShiftR :: And a -> Int -> And a
$crotateL :: forall a. Bits a => And a -> Int -> And a
rotateL :: And a -> Int -> And a
$crotateR :: forall a. Bits a => And a -> Int -> And a
rotateR :: And a -> Int -> And a
$cpopCount :: forall a. Bits a => And a -> Int
popCount :: And a -> Int
Bits, -- ^ @since 4.16
                    Bits (And a)
Bits (And a)
-> (And a -> Int)
-> (And a -> Int)
-> (And a -> Int)
-> FiniteBits (And a)
And a -> Int
forall b.
Bits b -> (b -> Int) -> (b -> Int) -> (b -> Int) -> FiniteBits b
forall {a}. FiniteBits a => Bits (And a)
forall a. FiniteBits a => And a -> Int
$cfiniteBitSize :: forall a. FiniteBits a => And a -> Int
finiteBitSize :: And a -> Int
$ccountLeadingZeros :: forall a. FiniteBits a => And a -> Int
countLeadingZeros :: And a -> Int
$ccountTrailingZeros :: forall a. FiniteBits a => And a -> Int
countTrailingZeros :: And a -> Int
FiniteBits, -- ^ @since 4.16
                    And a -> And a -> Bool
(And a -> And a -> Bool) -> (And a -> And a -> Bool) -> Eq (And a)
forall a. Eq a => And a -> And a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => And a -> And a -> Bool
== :: And a -> And a -> Bool
$c/= :: forall a. Eq a => And a -> And a -> Bool
/= :: And a -> And a -> Bool
Eq -- ^ @since 4.16
                    )
  deriving stock (
                  Int -> And a -> ShowS
[And a] -> ShowS
And a -> String
(Int -> And a -> ShowS)
-> (And a -> String) -> ([And a] -> ShowS) -> Show (And a)
forall a. Show a => Int -> And a -> ShowS
forall a. Show a => [And a] -> ShowS
forall a. Show a => And a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> And a -> ShowS
showsPrec :: Int -> And a -> ShowS
$cshow :: forall a. Show a => And a -> String
show :: And a -> String
$cshowList :: forall a. Show a => [And a] -> ShowS
showList :: [And a] -> ShowS
Show, -- ^ @since 4.16
                  ReadPrec [And a]
ReadPrec (And a)
Int -> ReadS (And a)
ReadS [And a]
(Int -> ReadS (And a))
-> ReadS [And a]
-> ReadPrec (And a)
-> ReadPrec [And a]
-> Read (And a)
forall a. Read a => ReadPrec [And a]
forall a. Read a => ReadPrec (And a)
forall a. Read a => Int -> ReadS (And a)
forall a. Read a => ReadS [And a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: forall a. Read a => Int -> ReadS (And a)
readsPrec :: Int -> ReadS (And a)
$creadList :: forall a. Read a => ReadS [And a]
readList :: ReadS [And a]
$creadPrec :: forall a. Read a => ReadPrec (And a)
readPrec :: ReadPrec (And a)
$creadListPrec :: forall a. Read a => ReadPrec [And a]
readListPrec :: ReadPrec [And a]
Read -- ^ @since 4.16
                 )

-- | @since 4.16
instance (Bits a) => Semigroup (And a) where
  And a
x <> :: And a -> And a -> And a
<> And a
y = a -> And a
forall a. a -> And a
And (a
x a -> a -> a
forall a. Bits a => a -> a -> a
.&. a
y)

-- | This constraint is arguably too strong. However,
-- as some types (such as 'Natural') have undefined 'complement', this is the
-- only safe choice.
--
-- @since 4.16
instance (FiniteBits a) => Monoid (And a) where
  mempty :: And a
mempty = a -> And a
forall a. a -> And a
And a
forall a. FiniteBits a => a
oneBits
  -- By default, we would get a lazy right fold. This forces the use of a strict
  -- left fold instead.
  mconcat :: [And a] -> And a
mconcat = (And a -> And a -> And a) -> And a -> [And a] -> And a
forall a b. (b -> a -> b) -> b -> [a] -> b
List.foldl' And a -> And a -> And a
forall a. Semigroup a => a -> a -> a
(<>) And a
forall a. Monoid a => a
mempty
  {-# INLINE mconcat #-}

-- | Monoid under bitwise inclusive OR.
--
-- >>> getIor (Ior 0xab <> Ior 0x12) :: Word8
-- 187
--
-- @since 4.16
newtype Ior a = Ior { forall a. Ior a -> a
getIor :: a }
  deriving newtype (
                    Ior a
Ior a -> Ior a -> Bounded (Ior a)
forall a. a -> a -> Bounded a
forall a. Bounded a => Ior a
$cminBound :: forall a. Bounded a => Ior a
minBound :: Ior a
$cmaxBound :: forall a. Bounded a => Ior a
maxBound :: Ior a
Bounded, -- ^ @since 4.16
                    Int -> Ior a
Ior a -> Int
Ior a -> [Ior a]
Ior a -> Ior a
Ior a -> Ior a -> [Ior a]
Ior a -> Ior a -> Ior a -> [Ior a]
(Ior a -> Ior a)
-> (Ior a -> Ior a)
-> (Int -> Ior a)
-> (Ior a -> Int)
-> (Ior a -> [Ior a])
-> (Ior a -> Ior a -> [Ior a])
-> (Ior a -> Ior a -> [Ior a])
-> (Ior a -> Ior a -> Ior a -> [Ior a])
-> Enum (Ior a)
forall a. Enum a => Int -> Ior a
forall a. Enum a => Ior a -> Int
forall a. Enum a => Ior a -> [Ior a]
forall a. Enum a => Ior a -> Ior a
forall a. Enum a => Ior a -> Ior a -> [Ior a]
forall a. Enum a => Ior a -> Ior a -> Ior a -> [Ior a]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: forall a. Enum a => Ior a -> Ior a
succ :: Ior a -> Ior a
$cpred :: forall a. Enum a => Ior a -> Ior a
pred :: Ior a -> Ior a
$ctoEnum :: forall a. Enum a => Int -> Ior a
toEnum :: Int -> Ior a
$cfromEnum :: forall a. Enum a => Ior a -> Int
fromEnum :: Ior a -> Int
$cenumFrom :: forall a. Enum a => Ior a -> [Ior a]
enumFrom :: Ior a -> [Ior a]
$cenumFromThen :: forall a. Enum a => Ior a -> Ior a -> [Ior a]
enumFromThen :: Ior a -> Ior a -> [Ior a]
$cenumFromTo :: forall a. Enum a => Ior a -> Ior a -> [Ior a]
enumFromTo :: Ior a -> Ior a -> [Ior a]
$cenumFromThenTo :: forall a. Enum a => Ior a -> Ior a -> Ior a -> [Ior a]
enumFromThenTo :: Ior a -> Ior a -> Ior a -> [Ior a]
Enum, -- ^ @since 4.16
                    Eq (Ior a)
Ior a
Eq (Ior a)
-> (Ior a -> Ior a -> Ior a)
-> (Ior a -> Ior a -> Ior a)
-> (Ior a -> Ior a -> Ior a)
-> (Ior a -> Ior a)
-> (Ior a -> Int -> Ior a)
-> (Ior a -> Int -> Ior a)
-> Ior a
-> (Int -> Ior a)
-> (Ior a -> Int -> Ior a)
-> (Ior a -> Int -> Ior a)
-> (Ior a -> Int -> Ior a)
-> (Ior a -> Int -> Bool)
-> (Ior a -> Maybe Int)
-> (Ior a -> Int)
-> (Ior a -> Bool)
-> (Ior a -> Int -> Ior a)
-> (Ior a -> Int -> Ior a)
-> (Ior a -> Int -> Ior a)
-> (Ior a -> Int -> Ior a)
-> (Ior a -> Int -> Ior a)
-> (Ior a -> Int -> Ior a)
-> (Ior a -> Int)
-> Bits (Ior a)
Int -> Ior a
Ior a -> Bool
Ior a -> Int
Ior a -> Maybe Int
Ior a -> Ior a
Ior a -> Int -> Bool
Ior a -> Int -> Ior a
Ior a -> Ior a -> Ior a
forall a.
Eq a
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> a
-> (Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> Bool)
-> (a -> Maybe Int)
-> (a -> Int)
-> (a -> Bool)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int)
-> Bits a
forall {a}. Bits a => Eq (Ior a)
forall a. Bits a => Ior a
forall a. Bits a => Int -> Ior a
forall a. Bits a => Ior a -> Bool
forall a. Bits a => Ior a -> Int
forall a. Bits a => Ior a -> Maybe Int
forall a. Bits a => Ior a -> Ior a
forall a. Bits a => Ior a -> Int -> Bool
forall a. Bits a => Ior a -> Int -> Ior a
forall a. Bits a => Ior a -> Ior a -> Ior a
$c.&. :: forall a. Bits a => Ior a -> Ior a -> Ior a
.&. :: Ior a -> Ior a -> Ior a
$c.|. :: forall a. Bits a => Ior a -> Ior a -> Ior a
.|. :: Ior a -> Ior a -> Ior a
$cxor :: forall a. Bits a => Ior a -> Ior a -> Ior a
xor :: Ior a -> Ior a -> Ior a
$ccomplement :: forall a. Bits a => Ior a -> Ior a
complement :: Ior a -> Ior a
$cshift :: forall a. Bits a => Ior a -> Int -> Ior a
shift :: Ior a -> Int -> Ior a
$crotate :: forall a. Bits a => Ior a -> Int -> Ior a
rotate :: Ior a -> Int -> Ior a
$czeroBits :: forall a. Bits a => Ior a
zeroBits :: Ior a
$cbit :: forall a. Bits a => Int -> Ior a
bit :: Int -> Ior a
$csetBit :: forall a. Bits a => Ior a -> Int -> Ior a
setBit :: Ior a -> Int -> Ior a
$cclearBit :: forall a. Bits a => Ior a -> Int -> Ior a
clearBit :: Ior a -> Int -> Ior a
$ccomplementBit :: forall a. Bits a => Ior a -> Int -> Ior a
complementBit :: Ior a -> Int -> Ior a
$ctestBit :: forall a. Bits a => Ior a -> Int -> Bool
testBit :: Ior a -> Int -> Bool
$cbitSizeMaybe :: forall a. Bits a => Ior a -> Maybe Int
bitSizeMaybe :: Ior a -> Maybe Int
$cbitSize :: forall a. Bits a => Ior a -> Int
bitSize :: Ior a -> Int
$cisSigned :: forall a. Bits a => Ior a -> Bool
isSigned :: Ior a -> Bool
$cshiftL :: forall a. Bits a => Ior a -> Int -> Ior a
shiftL :: Ior a -> Int -> Ior a
$cunsafeShiftL :: forall a. Bits a => Ior a -> Int -> Ior a
unsafeShiftL :: Ior a -> Int -> Ior a
$cshiftR :: forall a. Bits a => Ior a -> Int -> Ior a
shiftR :: Ior a -> Int -> Ior a
$cunsafeShiftR :: forall a. Bits a => Ior a -> Int -> Ior a
unsafeShiftR :: Ior a -> Int -> Ior a
$crotateL :: forall a. Bits a => Ior a -> Int -> Ior a
rotateL :: Ior a -> Int -> Ior a
$crotateR :: forall a. Bits a => Ior a -> Int -> Ior a
rotateR :: Ior a -> Int -> Ior a
$cpopCount :: forall a. Bits a => Ior a -> Int
popCount :: Ior a -> Int
Bits, -- ^ @since 4.16
                    Bits (Ior a)
Bits (Ior a)
-> (Ior a -> Int)
-> (Ior a -> Int)
-> (Ior a -> Int)
-> FiniteBits (Ior a)
Ior a -> Int
forall b.
Bits b -> (b -> Int) -> (b -> Int) -> (b -> Int) -> FiniteBits b
forall {a}. FiniteBits a => Bits (Ior a)
forall a. FiniteBits a => Ior a -> Int
$cfiniteBitSize :: forall a. FiniteBits a => Ior a -> Int
finiteBitSize :: Ior a -> Int
$ccountLeadingZeros :: forall a. FiniteBits a => Ior a -> Int
countLeadingZeros :: Ior a -> Int
$ccountTrailingZeros :: forall a. FiniteBits a => Ior a -> Int
countTrailingZeros :: Ior a -> Int
FiniteBits, -- ^ @since 4.16
                    Ior a -> Ior a -> Bool
(Ior a -> Ior a -> Bool) -> (Ior a -> Ior a -> Bool) -> Eq (Ior a)
forall a. Eq a => Ior a -> Ior a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => Ior a -> Ior a -> Bool
== :: Ior a -> Ior a -> Bool
$c/= :: forall a. Eq a => Ior a -> Ior a -> Bool
/= :: Ior a -> Ior a -> Bool
Eq -- ^ @since 4.16
                    )
  deriving stock (
                  Int -> Ior a -> ShowS
[Ior a] -> ShowS
Ior a -> String
(Int -> Ior a -> ShowS)
-> (Ior a -> String) -> ([Ior a] -> ShowS) -> Show (Ior a)
forall a. Show a => Int -> Ior a -> ShowS
forall a. Show a => [Ior a] -> ShowS
forall a. Show a => Ior a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> Ior a -> ShowS
showsPrec :: Int -> Ior a -> ShowS
$cshow :: forall a. Show a => Ior a -> String
show :: Ior a -> String
$cshowList :: forall a. Show a => [Ior a] -> ShowS
showList :: [Ior a] -> ShowS
Show, -- ^ @since 4.16
                  ReadPrec [Ior a]
ReadPrec (Ior a)
Int -> ReadS (Ior a)
ReadS [Ior a]
(Int -> ReadS (Ior a))
-> ReadS [Ior a]
-> ReadPrec (Ior a)
-> ReadPrec [Ior a]
-> Read (Ior a)
forall a. Read a => ReadPrec [Ior a]
forall a. Read a => ReadPrec (Ior a)
forall a. Read a => Int -> ReadS (Ior a)
forall a. Read a => ReadS [Ior a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: forall a. Read a => Int -> ReadS (Ior a)
readsPrec :: Int -> ReadS (Ior a)
$creadList :: forall a. Read a => ReadS [Ior a]
readList :: ReadS [Ior a]
$creadPrec :: forall a. Read a => ReadPrec (Ior a)
readPrec :: ReadPrec (Ior a)
$creadListPrec :: forall a. Read a => ReadPrec [Ior a]
readListPrec :: ReadPrec [Ior a]
Read -- ^ @since 4.16
                 )

-- | @since 4.16
instance (Bits a) => Semigroup (Ior a) where
  Ior a
x <> :: Ior a -> Ior a -> Ior a
<> Ior a
y = a -> Ior a
forall a. a -> Ior a
Ior (a
x a -> a -> a
forall a. Bits a => a -> a -> a
.|. a
y)

-- | @since 4.16
instance (Bits a) => Monoid (Ior a) where
  mempty :: Ior a
mempty = a -> Ior a
forall a. a -> Ior a
Ior a
forall a. Bits a => a
zeroBits
  -- By default, we would get a lazy right fold. This forces the use of a strict
  -- left fold instead.
  mconcat :: [Ior a] -> Ior a
mconcat = (Ior a -> Ior a -> Ior a) -> Ior a -> [Ior a] -> Ior a
forall a b. (b -> a -> b) -> b -> [a] -> b
List.foldl' Ior a -> Ior a -> Ior a
forall a. Semigroup a => a -> a -> a
(<>) Ior a
forall a. Monoid a => a
mempty
  {-# INLINE mconcat #-}

-- | Monoid under bitwise XOR.
--
-- >>> getXor (Xor 0xab <> Xor 0x12) :: Word8
-- 185
--
-- @since 4.16
newtype Xor a = Xor { forall a. Xor a -> a
getXor :: a }
  deriving newtype (
                    Xor a
Xor a -> Xor a -> Bounded (Xor a)
forall a. a -> a -> Bounded a
forall a. Bounded a => Xor a
$cminBound :: forall a. Bounded a => Xor a
minBound :: Xor a
$cmaxBound :: forall a. Bounded a => Xor a
maxBound :: Xor a
Bounded, -- ^ @since 4.16
                    Int -> Xor a
Xor a -> Int
Xor a -> [Xor a]
Xor a -> Xor a
Xor a -> Xor a -> [Xor a]
Xor a -> Xor a -> Xor a -> [Xor a]
(Xor a -> Xor a)
-> (Xor a -> Xor a)
-> (Int -> Xor a)
-> (Xor a -> Int)
-> (Xor a -> [Xor a])
-> (Xor a -> Xor a -> [Xor a])
-> (Xor a -> Xor a -> [Xor a])
-> (Xor a -> Xor a -> Xor a -> [Xor a])
-> Enum (Xor a)
forall a. Enum a => Int -> Xor a
forall a. Enum a => Xor a -> Int
forall a. Enum a => Xor a -> [Xor a]
forall a. Enum a => Xor a -> Xor a
forall a. Enum a => Xor a -> Xor a -> [Xor a]
forall a. Enum a => Xor a -> Xor a -> Xor a -> [Xor a]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: forall a. Enum a => Xor a -> Xor a
succ :: Xor a -> Xor a
$cpred :: forall a. Enum a => Xor a -> Xor a
pred :: Xor a -> Xor a
$ctoEnum :: forall a. Enum a => Int -> Xor a
toEnum :: Int -> Xor a
$cfromEnum :: forall a. Enum a => Xor a -> Int
fromEnum :: Xor a -> Int
$cenumFrom :: forall a. Enum a => Xor a -> [Xor a]
enumFrom :: Xor a -> [Xor a]
$cenumFromThen :: forall a. Enum a => Xor a -> Xor a -> [Xor a]
enumFromThen :: Xor a -> Xor a -> [Xor a]
$cenumFromTo :: forall a. Enum a => Xor a -> Xor a -> [Xor a]
enumFromTo :: Xor a -> Xor a -> [Xor a]
$cenumFromThenTo :: forall a. Enum a => Xor a -> Xor a -> Xor a -> [Xor a]
enumFromThenTo :: Xor a -> Xor a -> Xor a -> [Xor a]
Enum, -- ^ @since 4.16
                    Eq (Xor a)
Xor a
Eq (Xor a)
-> (Xor a -> Xor a -> Xor a)
-> (Xor a -> Xor a -> Xor a)
-> (Xor a -> Xor a -> Xor a)
-> (Xor a -> Xor a)
-> (Xor a -> Int -> Xor a)
-> (Xor a -> Int -> Xor a)
-> Xor a
-> (Int -> Xor a)
-> (Xor a -> Int -> Xor a)
-> (Xor a -> Int -> Xor a)
-> (Xor a -> Int -> Xor a)
-> (Xor a -> Int -> Bool)
-> (Xor a -> Maybe Int)
-> (Xor a -> Int)
-> (Xor a -> Bool)
-> (Xor a -> Int -> Xor a)
-> (Xor a -> Int -> Xor a)
-> (Xor a -> Int -> Xor a)
-> (Xor a -> Int -> Xor a)
-> (Xor a -> Int -> Xor a)
-> (Xor a -> Int -> Xor a)
-> (Xor a -> Int)
-> Bits (Xor a)
Int -> Xor a
Xor a -> Bool
Xor a -> Int
Xor a -> Maybe Int
Xor a -> Xor a
Xor a -> Int -> Bool
Xor a -> Int -> Xor a
Xor a -> Xor a -> Xor a
forall a.
Eq a
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> a
-> (Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> Bool)
-> (a -> Maybe Int)
-> (a -> Int)
-> (a -> Bool)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int)
-> Bits a
forall {a}. Bits a => Eq (Xor a)
forall a. Bits a => Xor a
forall a. Bits a => Int -> Xor a
forall a. Bits a => Xor a -> Bool
forall a. Bits a => Xor a -> Int
forall a. Bits a => Xor a -> Maybe Int
forall a. Bits a => Xor a -> Xor a
forall a. Bits a => Xor a -> Int -> Bool
forall a. Bits a => Xor a -> Int -> Xor a
forall a. Bits a => Xor a -> Xor a -> Xor a
$c.&. :: forall a. Bits a => Xor a -> Xor a -> Xor a
.&. :: Xor a -> Xor a -> Xor a
$c.|. :: forall a. Bits a => Xor a -> Xor a -> Xor a
.|. :: Xor a -> Xor a -> Xor a
$cxor :: forall a. Bits a => Xor a -> Xor a -> Xor a
xor :: Xor a -> Xor a -> Xor a
$ccomplement :: forall a. Bits a => Xor a -> Xor a
complement :: Xor a -> Xor a
$cshift :: forall a. Bits a => Xor a -> Int -> Xor a
shift :: Xor a -> Int -> Xor a
$crotate :: forall a. Bits a => Xor a -> Int -> Xor a
rotate :: Xor a -> Int -> Xor a
$czeroBits :: forall a. Bits a => Xor a
zeroBits :: Xor a
$cbit :: forall a. Bits a => Int -> Xor a
bit :: Int -> Xor a
$csetBit :: forall a. Bits a => Xor a -> Int -> Xor a
setBit :: Xor a -> Int -> Xor a
$cclearBit :: forall a. Bits a => Xor a -> Int -> Xor a
clearBit :: Xor a -> Int -> Xor a
$ccomplementBit :: forall a. Bits a => Xor a -> Int -> Xor a
complementBit :: Xor a -> Int -> Xor a
$ctestBit :: forall a. Bits a => Xor a -> Int -> Bool
testBit :: Xor a -> Int -> Bool
$cbitSizeMaybe :: forall a. Bits a => Xor a -> Maybe Int
bitSizeMaybe :: Xor a -> Maybe Int
$cbitSize :: forall a. Bits a => Xor a -> Int
bitSize :: Xor a -> Int
$cisSigned :: forall a. Bits a => Xor a -> Bool
isSigned :: Xor a -> Bool
$cshiftL :: forall a. Bits a => Xor a -> Int -> Xor a
shiftL :: Xor a -> Int -> Xor a
$cunsafeShiftL :: forall a. Bits a => Xor a -> Int -> Xor a
unsafeShiftL :: Xor a -> Int -> Xor a
$cshiftR :: forall a. Bits a => Xor a -> Int -> Xor a
shiftR :: Xor a -> Int -> Xor a
$cunsafeShiftR :: forall a. Bits a => Xor a -> Int -> Xor a
unsafeShiftR :: Xor a -> Int -> Xor a
$crotateL :: forall a. Bits a => Xor a -> Int -> Xor a
rotateL :: Xor a -> Int -> Xor a
$crotateR :: forall a. Bits a => Xor a -> Int -> Xor a
rotateR :: Xor a -> Int -> Xor a
$cpopCount :: forall a. Bits a => Xor a -> Int
popCount :: Xor a -> Int
Bits, -- ^ @since 4.16
                    Bits (Xor a)
Bits (Xor a)
-> (Xor a -> Int)
-> (Xor a -> Int)
-> (Xor a -> Int)
-> FiniteBits (Xor a)
Xor a -> Int
forall b.
Bits b -> (b -> Int) -> (b -> Int) -> (b -> Int) -> FiniteBits b
forall {a}. FiniteBits a => Bits (Xor a)
forall a. FiniteBits a => Xor a -> Int
$cfiniteBitSize :: forall a. FiniteBits a => Xor a -> Int
finiteBitSize :: Xor a -> Int
$ccountLeadingZeros :: forall a. FiniteBits a => Xor a -> Int
countLeadingZeros :: Xor a -> Int
$ccountTrailingZeros :: forall a. FiniteBits a => Xor a -> Int
countTrailingZeros :: Xor a -> Int
FiniteBits, -- ^ @since 4.16
                    Xor a -> Xor a -> Bool
(Xor a -> Xor a -> Bool) -> (Xor a -> Xor a -> Bool) -> Eq (Xor a)
forall a. Eq a => Xor a -> Xor a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => Xor a -> Xor a -> Bool
== :: Xor a -> Xor a -> Bool
$c/= :: forall a. Eq a => Xor a -> Xor a -> Bool
/= :: Xor a -> Xor a -> Bool
Eq -- ^ @since 4.16
                    )
  deriving stock (
                  Int -> Xor a -> ShowS
[Xor a] -> ShowS
Xor a -> String
(Int -> Xor a -> ShowS)
-> (Xor a -> String) -> ([Xor a] -> ShowS) -> Show (Xor a)
forall a. Show a => Int -> Xor a -> ShowS
forall a. Show a => [Xor a] -> ShowS
forall a. Show a => Xor a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> Xor a -> ShowS
showsPrec :: Int -> Xor a -> ShowS
$cshow :: forall a. Show a => Xor a -> String
show :: Xor a -> String
$cshowList :: forall a. Show a => [Xor a] -> ShowS
showList :: [Xor a] -> ShowS
Show, -- ^ @since 4.16
                  ReadPrec [Xor a]
ReadPrec (Xor a)
Int -> ReadS (Xor a)
ReadS [Xor a]
(Int -> ReadS (Xor a))
-> ReadS [Xor a]
-> ReadPrec (Xor a)
-> ReadPrec [Xor a]
-> Read (Xor a)
forall a. Read a => ReadPrec [Xor a]
forall a. Read a => ReadPrec (Xor a)
forall a. Read a => Int -> ReadS (Xor a)
forall a. Read a => ReadS [Xor a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: forall a. Read a => Int -> ReadS (Xor a)
readsPrec :: Int -> ReadS (Xor a)
$creadList :: forall a. Read a => ReadS [Xor a]
readList :: ReadS [Xor a]
$creadPrec :: forall a. Read a => ReadPrec (Xor a)
readPrec :: ReadPrec (Xor a)
$creadListPrec :: forall a. Read a => ReadPrec [Xor a]
readListPrec :: ReadPrec [Xor a]
Read -- ^ @since 4.16
                 )

-- | @since 4.16
instance (Bits a) => Semigroup (Xor a) where
  Xor a
x <> :: Xor a -> Xor a -> Xor a
<> Xor a
y = a -> Xor a
forall a. a -> Xor a
Xor (a
x a -> a -> a
forall a. Bits a => a -> a -> a
`xor` a
y)

-- | @since 4.16
instance (Bits a) => Monoid (Xor a) where
  mempty :: Xor a
mempty = a -> Xor a
forall a. a -> Xor a
Xor a
forall a. Bits a => a
zeroBits
  -- By default, we would get a lazy right fold. This forces the use of a strict
  -- left fold instead.
  mconcat :: [Xor a] -> Xor a
mconcat = (Xor a -> Xor a -> Xor a) -> Xor a -> [Xor a] -> Xor a
forall a b. (b -> a -> b) -> b -> [a] -> b
List.foldl' Xor a -> Xor a -> Xor a
forall a. Semigroup a => a -> a -> a
(<>) Xor a
forall a. Monoid a => a
mempty
  {-# INLINE mconcat #-}

-- | Monoid under bitwise \'equality\'; defined as @1@ if the corresponding
-- bits match, and @0@ otherwise.
--
-- >>> getIff (Iff 0xab <> Iff 0x12) :: Word8
-- 70
--
-- @since 4.16
newtype Iff a = Iff { forall a. Iff a -> a
getIff :: a }
  deriving newtype (
                    Iff a
Iff a -> Iff a -> Bounded (Iff a)
forall a. a -> a -> Bounded a
forall a. Bounded a => Iff a
$cminBound :: forall a. Bounded a => Iff a
minBound :: Iff a
$cmaxBound :: forall a. Bounded a => Iff a
maxBound :: Iff a
Bounded, -- ^ @since 4.16
                    Int -> Iff a
Iff a -> Int
Iff a -> [Iff a]
Iff a -> Iff a
Iff a -> Iff a -> [Iff a]
Iff a -> Iff a -> Iff a -> [Iff a]
(Iff a -> Iff a)
-> (Iff a -> Iff a)
-> (Int -> Iff a)
-> (Iff a -> Int)
-> (Iff a -> [Iff a])
-> (Iff a -> Iff a -> [Iff a])
-> (Iff a -> Iff a -> [Iff a])
-> (Iff a -> Iff a -> Iff a -> [Iff a])
-> Enum (Iff a)
forall a. Enum a => Int -> Iff a
forall a. Enum a => Iff a -> Int
forall a. Enum a => Iff a -> [Iff a]
forall a. Enum a => Iff a -> Iff a
forall a. Enum a => Iff a -> Iff a -> [Iff a]
forall a. Enum a => Iff a -> Iff a -> Iff a -> [Iff a]
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: forall a. Enum a => Iff a -> Iff a
succ :: Iff a -> Iff a
$cpred :: forall a. Enum a => Iff a -> Iff a
pred :: Iff a -> Iff a
$ctoEnum :: forall a. Enum a => Int -> Iff a
toEnum :: Int -> Iff a
$cfromEnum :: forall a. Enum a => Iff a -> Int
fromEnum :: Iff a -> Int
$cenumFrom :: forall a. Enum a => Iff a -> [Iff a]
enumFrom :: Iff a -> [Iff a]
$cenumFromThen :: forall a. Enum a => Iff a -> Iff a -> [Iff a]
enumFromThen :: Iff a -> Iff a -> [Iff a]
$cenumFromTo :: forall a. Enum a => Iff a -> Iff a -> [Iff a]
enumFromTo :: Iff a -> Iff a -> [Iff a]
$cenumFromThenTo :: forall a. Enum a => Iff a -> Iff a -> Iff a -> [Iff a]
enumFromThenTo :: Iff a -> Iff a -> Iff a -> [Iff a]
Enum, -- ^ @since 4.16
                    Eq (Iff a)
Iff a
Eq (Iff a)
-> (Iff a -> Iff a -> Iff a)
-> (Iff a -> Iff a -> Iff a)
-> (Iff a -> Iff a -> Iff a)
-> (Iff a -> Iff a)
-> (Iff a -> Int -> Iff a)
-> (Iff a -> Int -> Iff a)
-> Iff a
-> (Int -> Iff a)
-> (Iff a -> Int -> Iff a)
-> (Iff a -> Int -> Iff a)
-> (Iff a -> Int -> Iff a)
-> (Iff a -> Int -> Bool)
-> (Iff a -> Maybe Int)
-> (Iff a -> Int)
-> (Iff a -> Bool)
-> (Iff a -> Int -> Iff a)
-> (Iff a -> Int -> Iff a)
-> (Iff a -> Int -> Iff a)
-> (Iff a -> Int -> Iff a)
-> (Iff a -> Int -> Iff a)
-> (Iff a -> Int -> Iff a)
-> (Iff a -> Int)
-> Bits (Iff a)
Int -> Iff a
Iff a -> Bool
Iff a -> Int
Iff a -> Maybe Int
Iff a -> Iff a
Iff a -> Int -> Bool
Iff a -> Int -> Iff a
Iff a -> Iff a -> Iff a
forall a.
Eq a
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> a
-> (Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> Bool)
-> (a -> Maybe Int)
-> (a -> Int)
-> (a -> Bool)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int -> a)
-> (a -> Int)
-> Bits a
forall {a}. Bits a => Eq (Iff a)
forall a. Bits a => Iff a
forall a. Bits a => Int -> Iff a
forall a. Bits a => Iff a -> Bool
forall a. Bits a => Iff a -> Int
forall a. Bits a => Iff a -> Maybe Int
forall a. Bits a => Iff a -> Iff a
forall a. Bits a => Iff a -> Int -> Bool
forall a. Bits a => Iff a -> Int -> Iff a
forall a. Bits a => Iff a -> Iff a -> Iff a
$c.&. :: forall a. Bits a => Iff a -> Iff a -> Iff a
.&. :: Iff a -> Iff a -> Iff a
$c.|. :: forall a. Bits a => Iff a -> Iff a -> Iff a
.|. :: Iff a -> Iff a -> Iff a
$cxor :: forall a. Bits a => Iff a -> Iff a -> Iff a
xor :: Iff a -> Iff a -> Iff a
$ccomplement :: forall a. Bits a => Iff a -> Iff a
complement :: Iff a -> Iff a
$cshift :: forall a. Bits a => Iff a -> Int -> Iff a
shift :: Iff a -> Int -> Iff a
$crotate :: forall a. Bits a => Iff a -> Int -> Iff a
rotate :: Iff a -> Int -> Iff a
$czeroBits :: forall a. Bits a => Iff a
zeroBits :: Iff a
$cbit :: forall a. Bits a => Int -> Iff a
bit :: Int -> Iff a
$csetBit :: forall a. Bits a => Iff a -> Int -> Iff a
setBit :: Iff a -> Int -> Iff a
$cclearBit :: forall a. Bits a => Iff a -> Int -> Iff a
clearBit :: Iff a -> Int -> Iff a
$ccomplementBit :: forall a. Bits a => Iff a -> Int -> Iff a
complementBit :: Iff a -> Int -> Iff a
$ctestBit :: forall a. Bits a => Iff a -> Int -> Bool
testBit :: Iff a -> Int -> Bool
$cbitSizeMaybe :: forall a. Bits a => Iff a -> Maybe Int
bitSizeMaybe :: Iff a -> Maybe Int
$cbitSize :: forall a. Bits a => Iff a -> Int
bitSize :: Iff a -> Int
$cisSigned :: forall a. Bits a => Iff a -> Bool
isSigned :: Iff a -> Bool
$cshiftL :: forall a. Bits a => Iff a -> Int -> Iff a
shiftL :: Iff a -> Int -> Iff a
$cunsafeShiftL :: forall a. Bits a => Iff a -> Int -> Iff a
unsafeShiftL :: Iff a -> Int -> Iff a
$cshiftR :: forall a. Bits a => Iff a -> Int -> Iff a
shiftR :: Iff a -> Int -> Iff a
$cunsafeShiftR :: forall a. Bits a => Iff a -> Int -> Iff a
unsafeShiftR :: Iff a -> Int -> Iff a
$crotateL :: forall a. Bits a => Iff a -> Int -> Iff a
rotateL :: Iff a -> Int -> Iff a
$crotateR :: forall a. Bits a => Iff a -> Int -> Iff a
rotateR :: Iff a -> Int -> Iff a
$cpopCount :: forall a. Bits a => Iff a -> Int
popCount :: Iff a -> Int
Bits, -- ^ @since 4.16
                    Bits (Iff a)
Bits (Iff a)
-> (Iff a -> Int)
-> (Iff a -> Int)
-> (Iff a -> Int)
-> FiniteBits (Iff a)
Iff a -> Int
forall b.
Bits b -> (b -> Int) -> (b -> Int) -> (b -> Int) -> FiniteBits b
forall {a}. FiniteBits a => Bits (Iff a)
forall a. FiniteBits a => Iff a -> Int
$cfiniteBitSize :: forall a. FiniteBits a => Iff a -> Int
finiteBitSize :: Iff a -> Int
$ccountLeadingZeros :: forall a. FiniteBits a => Iff a -> Int
countLeadingZeros :: Iff a -> Int
$ccountTrailingZeros :: forall a. FiniteBits a => Iff a -> Int
countTrailingZeros :: Iff a -> Int
FiniteBits, -- ^ @since 4.16
                    Iff a -> Iff a -> Bool
(Iff a -> Iff a -> Bool) -> (Iff a -> Iff a -> Bool) -> Eq (Iff a)
forall a. Eq a => Iff a -> Iff a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => Iff a -> Iff a -> Bool
== :: Iff a -> Iff a -> Bool
$c/= :: forall a. Eq a => Iff a -> Iff a -> Bool
/= :: Iff a -> Iff a -> Bool
Eq -- ^ @since 4.16
                    )
  deriving stock (
                  Int -> Iff a -> ShowS
[Iff a] -> ShowS
Iff a -> String
(Int -> Iff a -> ShowS)
-> (Iff a -> String) -> ([Iff a] -> ShowS) -> Show (Iff a)
forall a. Show a => Int -> Iff a -> ShowS
forall a. Show a => [Iff a] -> ShowS
forall a. Show a => Iff a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> Iff a -> ShowS
showsPrec :: Int -> Iff a -> ShowS
$cshow :: forall a. Show a => Iff a -> String
show :: Iff a -> String
$cshowList :: forall a. Show a => [Iff a] -> ShowS
showList :: [Iff a] -> ShowS
Show, -- ^ @since 4.16
                  ReadPrec [Iff a]
ReadPrec (Iff a)
Int -> ReadS (Iff a)
ReadS [Iff a]
(Int -> ReadS (Iff a))
-> ReadS [Iff a]
-> ReadPrec (Iff a)
-> ReadPrec [Iff a]
-> Read (Iff a)
forall a. Read a => ReadPrec [Iff a]
forall a. Read a => ReadPrec (Iff a)
forall a. Read a => Int -> ReadS (Iff a)
forall a. Read a => ReadS [Iff a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: forall a. Read a => Int -> ReadS (Iff a)
readsPrec :: Int -> ReadS (Iff a)
$creadList :: forall a. Read a => ReadS [Iff a]
readList :: ReadS [Iff a]
$creadPrec :: forall a. Read a => ReadPrec (Iff a)
readPrec :: ReadPrec (Iff a)
$creadListPrec :: forall a. Read a => ReadPrec [Iff a]
readListPrec :: ReadPrec [Iff a]
Read -- ^ @since 4.16
                 )

-- | This constraint is arguably
-- too strong. However, as some types (such as 'Natural') have undefined
-- 'complement', this is the only safe choice.
--
-- @since 4.16
instance (FiniteBits a) => Semigroup (Iff a) where
  Iff a
x <> :: Iff a -> Iff a -> Iff a
<> Iff a
y = a -> Iff a
forall a. a -> Iff a
Iff (a -> Iff a) -> (a -> a) -> a -> Iff a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> a
forall a. Bits a => a -> a
complement (a -> Iff a) -> a -> Iff a
forall a b. (a -> b) -> a -> b
$ (a
x a -> a -> a
forall a. Bits a => a -> a -> a
`xor` a
y)

-- | This constraint is arguably
-- too strong. However, as some types (such as 'Natural') have undefined
-- 'complement', this is the only safe choice.
--
-- @since 4.16
instance (FiniteBits a) => Monoid (Iff a) where
  mempty :: Iff a
mempty = a -> Iff a
forall a. a -> Iff a
Iff a
forall a. FiniteBits a => a
oneBits
  -- By default, we would get a lazy right fold. This forces the use of a strict
  -- left fold instead.
  mconcat :: [Iff a] -> Iff a
mconcat = (Iff a -> Iff a -> Iff a) -> Iff a -> [Iff a] -> Iff a
forall a b. (b -> a -> b) -> b -> [a] -> b
List.foldl' Iff a -> Iff a -> Iff a
forall a. Semigroup a => a -> a -> a
(<>) Iff a
forall a. Monoid a => a
mempty
  {-# INLINE mconcat #-}