summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomLokhorst <>2009-06-15 21:58:34 (GMT)
committerLuite Stegeman <luite@luite.com>2009-06-15 21:58:34 (GMT)
commitddee92e603c663d48103192aede97060795cafbe (patch)
tree5b0cac5b6fc2f9338806a312d32f6d6d3245d8c7
parentb42168b73eacfec6ebd68489e4837af3b725b403 (diff)
version 0.3.00.3.0
-rw-r--r--bool-extras.cabal5
-rw-r--r--src/Data/Bool/Extras.hs21
2 files changed, 18 insertions, 8 deletions
diff --git a/bool-extras.cabal b/bool-extras.cabal
index 72acadf..06b1a9e 100644
--- a/bool-extras.cabal
+++ b/bool-extras.cabal
@@ -1,5 +1,5 @@
name: bool-extras
-version: 0.2.0
+version: 0.3.0
synopsis: A fold function for Bool
description: The `bool' function allows folding over boolean values.
.
@@ -26,6 +26,7 @@ author: Erik Hesselink,
Tom Lokhorst,
Sebastiaan Visser
maintainer: Tom Lokhorst <tom@lokhorst.eu>
+homepage: http://tom.lokhorst.eu/bool-extras
stability: Stable
category: Data
build-type: Simple
@@ -33,5 +34,5 @@ cabal-version: >= 1.6
extra-source-files: examples/*.hs
hs-source-dirs: src
exposed-modules: Data.Bool.Extras
-build-depends: base
+build-depends: base >= 3 && < 5
diff --git a/src/Data/Bool/Extras.hs b/src/Data/Bool/Extras.hs
index a006f14..c625874 100644
--- a/src/Data/Bool/Extras.hs
+++ b/src/Data/Bool/Extras.hs
@@ -9,6 +9,7 @@ module Data.Bool.Extras
-- * Other functions
, mwhen
+ , mwhenM
, whenA
, whenC
, whenM
@@ -33,6 +34,7 @@ import Data.Monoid
--
-- Comparable to the `maybe' or `either' functions for their respective data
-- types.
+{-# INLINE bool #-}
bool :: a -> a -> Bool -> a
bool x _ False = x
bool _ y True = y
@@ -47,30 +49,37 @@ bool _ y True = y
mwhen :: (Monoid a) => a -> Bool -> a
mwhen = bool mempty
+-- | Boolean operation for monads, with a monoid default.
+--
+-- Return its first argument when applied to `True',
+-- returns `return mempty' when applied to `False'.
+mwhenM :: (Monad m, Monoid a) => m a -> Bool -> m a
+mwhenM = bool (return mempty)
+
-- | Boolean operation for arrows.
--
-- Returns its first argument when applied to `True',
-- returns `returnA' when applied to `False'.
-whenA :: Arrow a => a b b -> Bool -> a b b
+whenA :: (Arrow a) => a b b -> Bool -> a b b
whenA = bool returnA
-- | Boolean operation for categories.
--
-- Returns its first argument when applied to `True',
-- returns @Control.Category.@`Cat.id' when applied to `False'.
-whenC :: Category cat => cat b b -> Bool -> cat b b
+whenC :: (Category cat) => cat a a -> Bool -> cat a a
whenC = bool Cat.id
-- | Boolean operation for monads.
--
-- Returns its first argument when applied to `True',
--- returns @Control.Category.@`Cat.id' when applied to `False'.
+-- returns `return' when applied to `False'.
--
-- @Control.Monad.@`when' can be expressed in terms of `whenM', like so:
--
-- > when :: Monad m => Bool -> m () -> m ()
-- > when b m = (const m `whenM` b) ()
-whenM :: Monad m => (b -> m b) -> Bool -> (b -> m b)
+whenM :: (Monad m) => (a -> m a) -> Bool -> (a -> m a)
whenM = bool return
-- Alternative implementation using Kleisli arrows:
-- whenM m = runKleisli . whenC (Kleisli m)
@@ -78,10 +87,10 @@ whenM = bool return
{-
-- Functions that are also possible, but we haven't found an explicit need for
-whenP :: MonadPlus m => a -> Bool -> m a
+whenP :: (MonadPlus m) => a -> Bool -> m a
whenP = bool mzero . return
-(<?>) :: Applicative f => (a -> f a) -> Bool -> (a -> f a)
+(<?>) :: (Applicative f) => (a -> f a) -> Bool -> (a -> f a)
(<?>) = bool pure
-}