Commit 9c464f89 authored by mjo's avatar mjo Committed by Austin Seipp

Add doctest examples for Data.Bool.

Summary:
Add examples for `Data.Bool`, and rework the existing documentation of
the `bool` function slightly: the `a`,`b` in its explanation were changed
to `x`,`y` to avoid ambiguity with the type variable 'a'.

The examples have been tested, and two trailing spaces were removed.

Reviewers: austin

Reviewed By: austin

Subscribers: thomie, carter, ezyang, simonmar

Differential Revision: https://phabricator.haskell.org/D360
parent 52116731
......@@ -6,7 +6,7 @@
-- Module : Data.Bool
-- Copyright : (c) The University of Glasgow 2001
-- License : BSD-style (see the file libraries/base/LICENSE)
--
--
-- Maintainer : libraries@haskell.org
-- Stability : experimental
-- Portability : portable
......@@ -18,7 +18,7 @@
module Data.Bool (
-- * Booleans
Bool(..),
-- ** Operations
-- ** Operations
(&&),
(||),
not,
......@@ -28,11 +28,34 @@ module Data.Bool (
import GHC.Base
-- | Case analysis for the 'Bool' type.
-- @bool a b p@ evaluates to @a@ when @p@ is @False@, and evaluates to @b@
-- when @p@ is @True@.
-- | Case analysis for the 'Bool' type. @bool x y p@ evaluates to @x@
-- when @p@ is @False@, and evaluates to @y@ when @p@ is @True@.
--
-- This is equivalent to @if p then y else x@; that is, one can
-- think of it as an if-then-else construct with its arguments
-- reordered.
--
-- /Since: 4.7.0.0/
--
-- __Examples__:
--
-- Basic usage:
--
-- >>> bool "foo" "bar" True
-- "bar"
-- >>> bool "foo" "bar" False
-- "foo"
--
-- Confirm that @bool x y p@ and @if p then y else x@ are
-- equivalent:
--
-- >>> let p = True; x = "bar"; y = "foo"
-- >>> bool x y p == if p then y else x
-- True
-- >>> let p = False
-- >>> bool x y p == if p then y else x
-- True
--
-- /Since: 4.7.0.0/
bool :: a -> a -> Bool -> a
bool f _ False = f
bool _ t True = t
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment