| Copyright | (c) 2016 Stephen Diehl (c) 2016-2018 Serokell (c) 2018-2023 Kowainik |
|---|---|
| License | MIT |
| Maintainer | Kowainik <xrom.xkov@gmail.com> |
| Stability | Stable |
| Portability | Portable |
| Safe Haskell | Safe |
| Language | Haskell2010 |
Relude.Bool.Reexport
Contents
- Data.Bool reexports
- Control.Monad reexports
Description
Reexports functions to work with Bool type.
Data.Bool reexports
Instances
| NFData Bool | |||||
Defined in Control.DeepSeq | |||||
| Bits Bool | Interpret @since base-4.7.0.0 | ||||
Defined in GHC.Internal.Bits Methods (.&.) :: Bool -> Bool -> Bool # (.|.) :: Bool -> Bool -> Bool # complement :: Bool -> Bool # shift :: Bool -> Int -> Bool # rotate :: Bool -> Int -> Bool # setBit :: Bool -> Int -> Bool # clearBit :: Bool -> Int -> Bool # complementBit :: Bool -> Int -> Bool # testBit :: Bool -> Int -> Bool # bitSizeMaybe :: Bool -> Maybe Int # shiftL :: Bool -> Int -> Bool # unsafeShiftL :: Bool -> Int -> Bool # shiftR :: Bool -> Int -> Bool # unsafeShiftR :: Bool -> Int -> Bool # rotateL :: Bool -> Int -> Bool # | |||||
| FiniteBits Bool | @since base-4.7.0.0 | ||||
Defined in GHC.Internal.Bits Methods finiteBitSize :: Bool -> Int # countLeadingZeros :: Bool -> Int # countTrailingZeros :: Bool -> Int # | |||||
| Data Bool | @since base-4.0.0.0 | ||||
Defined in GHC.Internal.Data.Data Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Bool -> c Bool # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Bool # dataTypeOf :: Bool -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Bool) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Bool) # gmapT :: (forall b. Data b => b -> b) -> Bool -> Bool # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Bool -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Bool -> r # gmapQ :: (forall d. Data d => d -> u) -> Bool -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Bool -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Bool -> m Bool # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Bool -> m Bool # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Bool -> m Bool # | |||||
| Bounded Bool | @since base-2.01 | ||||
| Enum Bool | @since base-2.01 | ||||
| Generic Bool | |||||
Defined in GHC.Internal.Generics | |||||
| SingKind Bool | @since base-4.9.0.0 | ||||
Defined in GHC.Internal.Generics Associated Types
| |||||
| Read Bool | @since base-2.01 | ||||
| Show Bool | @since base-2.01 | ||||
| Eq Bool | |||||
| Ord Bool | |||||
| Hashable Bool | |||||
Defined in Data.Hashable.Class | |||||
| SingI 'False | @since base-4.9.0.0 | ||||
Defined in GHC.Internal.Generics | |||||
| SingI 'True | @since base-4.9.0.0 | ||||
Defined in GHC.Internal.Generics | |||||
| Lift Bool | |||||
| type DemoteRep Bool | |||||
Defined in GHC.Internal.Generics | |||||
| type Rep Bool | @since base-4.6.0.0 | ||||
| data Sing (a :: Bool) | |||||
Case analysis for the Bool type. evaluates to bool f t pf
when p is False, and evaluates to t when p is True.
This is equivalent to if p then t else f; that is, one can
think of it as an if-then-else construct with its arguments
reordered.
@since base-4.7.0.0
Examples
Basic usage:
>>>bool "foo" "bar" True"bar">>>bool "foo" "bar" False"foo"
Confirm that and bool f t pif p then t else f are
equivalent:
>>>let p = True; f = "bar"; t = "foo">>>bool f t p == if p then t else fTrue>>>let p = False>>>bool f t p == if p then t else fTrue
Control.Monad reexports
guard :: Alternative f => Bool -> f () #
Conditional failure of Alternative computations. Defined by
guard True =pure() guard False =empty
Examples
Common uses of guard include conditionally signalling an error in
an error monad and conditionally rejecting the current choice in an
Alternative-based parser.
As an example of signalling an error in the error monad Maybe,
consider a safe division function safeDiv x y that returns
Nothing when the denominator y is zero and otherwise. For example:Just (x `div`
y)
>>>safeDiv 4 0Nothing
>>>safeDiv 4 2Just 2
A definition of safeDiv using guards, but not guard:
safeDiv :: Int -> Int -> Maybe Int
safeDiv x y | y /= 0 = Just (x `div` y)
| otherwise = Nothing
A definition of safeDiv using guard and Monad do-notation:
safeDiv :: Int -> Int -> Maybe Int safeDiv x y = do guard (y /= 0) return (x `div` y)
when :: Applicative f => Bool -> f () -> f () #
Conditional execution of Applicative expressions. For example,
Examples
when debug (putStrLn "Debugging")
will output the string Debugging if the Boolean value debug
is True, and otherwise do nothing.
>>>putStr "pi:" >> when False (print 3.14159)pi:
unless :: Applicative f => Bool -> f () -> f () #
The reverse of when.
Examples
>>>do x <- getLineunless (x == "hi") (putStrLn "hi!") comingupwithexamplesisdifficult hi!
>>>unless (pi > exp 1) NothingJust ()