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

Modulebase-compat-0.14.1Haskell2010

Data.Bool.Compat

  • 1 type
  • 6 values
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
datadata Bool
#
Instances25Bounded, 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
  • 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
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

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