Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added boolA and boolC functions for arrows and categories.

  • Loading branch information...
commit 2d13e6f09d804c2b0dd6922c8f24f88870a2ef1a 1 parent 8da0da6
@tomlokhorst authored
Showing with 21 additions and 6 deletions.
  1. +1 −0  bool-extras.cabal
  2. +20 −6 src/Data/Bool/Extras.hs
View
1  bool-extras.cabal
@@ -18,6 +18,7 @@ description: The `bool' function allows folding over boolean values.
license: BSD3
license-file: LICENSE
author: Erik Hesselink,
+ Jeroen Leeuwestein,
Tom Lokhorst,
Sebastiaan Visser
maintainer: Tom Lokhorst <tom@lokhorst.eu>
View
26 src/Data/Bool/Extras.hs
@@ -15,23 +15,37 @@ module Data.Bool.Extras
import Data.Bool
import Data.Monoid
-
--- Straightforward implementation (without the weird catamorphism stuff):
--- bool x _ True = x
--- bool _ y False = y
+import Control.Arrow
+import Control.Category (Category)
+import qualified Control.Category as Cat
-- | Defines the fold over a boolean data type.
-- Comparable to the `maybe' or `either' functions.
bool :: a -> a -> Bool -> a
-bool = flip (curry cata)
+bool x _ True = x
+bool _ y False = y
-- | Boolean operation for monoids.
-- Behaves like `id` when applied to `True`,
--- returns `mempty` for when applied to `False`
+-- returns `mempty` for when applied to `False`.
boolM :: (Monoid a) => a -> Bool -> a
boolM x True = x
boolM _ False = mempty
+-- | Boolean operation for arrows.
+-- Behaves like `id` when applied to `True`,
+-- return `returnA` when applied to `False`.
+boolA :: Arrow a => a b b -> Bool -> a b b
+boolA a True = a
+boolA _ False = returnA
+
+-- | Boolean operation for categories.
+-- Behaves like `id` when applied to `True`,
+-- return `Cat.id` when applied to `False`.
+boolC :: Category cat => cat b b -> Bool -> cat b b
+boolC c True = c
+boolC _ False = Cat.id
+
-- | Algebra for Bool data type.
type BoolAlgebra r = (r, r)
Please sign in to comment.
Something went wrong with that request. Please try again.