HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulerelude-1.2.0.0Haskell2010

Relude.Bool.Reexport

SPDX-License-Identifier : MIT Maintainer : Kowainik xrom.xkov@gmail.com Stability : Stable Portability : Portable

Reexports functions to work with Bool type.

  • 1 type
  • 8 values
  • Packagerelude-1.2.0.0
  • Exports9
  • LanguageHaskell2010
  • LicenceMIT
  • SourceReexport.hs

Data.Bool reexports

6 declarations
datadata Bool
#
Instances27Bounded, Enum, Eq, Data, Ord, Read, …
  • Bounded BoolDefined in ghc-internal-9.1003.0 · GHC.Internal.Enum
  • Enum BoolDefined in ghc-internal-9.1003.0 · GHC.Internal.Enum
  • Eq BoolDefined in ghc-prim-0.12.0 · GHC.Classes
  • Data BoolDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Data
  • Ord BoolDefined in ghc-prim-0.12.0 · GHC.Classes
  • Read BoolDefined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • Show BoolDefined in ghc-internal-9.1003.0 · GHC.Internal.Show
  • Ix BoolDefined in ghc-internal-9.1003.0 · GHC.Internal.Ix
  • Generic BoolDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Bits BoolDefined in ghc-internal-9.1003.0 · GHC.Internal.Bits

    Interpret Bool as 1-bit bit-field

  • FiniteBits BoolDefined in ghc-internal-9.1003.0 · GHC.Internal.Bits
  • Storable BoolDefined in ghc-internal-9.1003.0 · GHC.Internal.Foreign.Storable
  • SingKind BoolDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • NFData BoolDefined in deepseq-1.5.0.0 · Control.DeepSeq
  • Pretty BoolDefined in pretty-1.1.3.6 · Text.PrettyPrint.Annotated.HughesPJClass
  • Pretty BoolDefined in pretty-1.1.3.6 · Text.PrettyPrint.HughesPJClass
  • Binary BoolDefined in binary-0.8.9.3 · Data.Binary.Class
  • Hashable BoolDefined in hashable-1.4.7.0 · Data.Hashable.Class
  • Lift BoolDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.Syntax
  • SingI 'FalseDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • SingI 'TrueDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • IArray UArray BoolDefined in array-0.5.8.0 · Data.Array.Base
  • MArray IOUArray Bool IODefined in array-0.5.8.0 · Data.Array.IO.Internals
  • MArray (STUArray s) Bool (ST s)Defined in array-0.5.8.0 · Data.Array.Base
  • type Rep Bool = D1 ('MetaData "Bool" "GHC.Types" "ghc-prim" 'False) (C1 ('MetaCons "False" 'PrefixI 'False) U1 :+: C1 ('MetaCons "True" 'PrefixI 'False) U1)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • type DemoteRep Bool = BoolDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • data Sing
    • STrue :: R:SingBoola 'True
    • SFalse :: R:SingBoola 'False
    Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
valuebool :: a -> a -> Bool -> a
#

Case analysis for the Bool type. bool f t p evaluates to f 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.

Examples

Basic usage:

Example2 expressions
bool "foo" "bar" True"bar"bool "foo" "bar" False"foo"

Confirm that bool f t p and if p then t else f are equivalent:

Example4 expressions
let p = True; f = "bar"; t = "foo"bool f t p == if p then t else fTruelet p = Falsebool f t p == if p then t else fTrue
valueotherwise :: Bool
#

otherwise is defined as the value True. It helps to make guards more readable. eg.

 f x | x < 0     = ...
     | otherwise = ...
value(&&) :: Bool -> Bool -> Bool
#

Boolean "and", lazy in the second argument

value(||) :: Bool -> Bool -> Bool
#

Boolean "or", lazy in the second argument

Control.Monad reexports

3 declarations
valueguard :: 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 Just (x `div` y) otherwise. For example:

Example1 expression
safeDiv 4 0Nothing
Example1 expression
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)
valuewhen :: 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.

Example1 expression
putStr "pi:" >> when False (print 3.14159)pi:
valueunless :: Applicative f => Bool -> f () -> f ()
#

The reverse of when.

Examples
Example1 expression
do x <- getLine       unless (x == "hi") (putStrLn "hi!")comingupwithexamplesisdifficulthi!
Example1 expression
unless (pi > exp 1) NothingJust ()