ContentsIndex
Boolean.Boolean
Description
This module provides a data constructor which lifts any type into a boolean algebra and some operations on said lifted type.
Synopsis
data Boolean a
= BoolNot (Boolean a)
| BoolAnd [Boolean a]
| BoolOr [Boolean a]
| BoolJust a
simplifyBoolean :: Bool -> Boolean a -> Boolean a
showBoolean :: (a -> String) -> Boolean a -> String
evaluate :: BooleanAlgebra r => (a -> r) -> Boolean a -> r
evaluateM :: (Monad m, BooleanAlgebra r) => (a -> m r) -> Boolean a -> m r
parseBoolean' :: Parser s -> Parser t -> Parser f -> Parser a -> Parser (Boolean a)
dropBoolean :: BooleanAlgebra a => Boolean a -> a
Documentation
data Boolean a
Constructors
BoolNot (Boolean a)
BoolAnd [Boolean a]
BoolOr [Boolean a]
BoolJust a
Instances
Functor Boolean
Monad Boolean
MonadPlus Boolean
SemiBooleanAlgebra (Boolean a)
BooleanAlgebra (Boolean a)
(Eq a, ??? a) => Eq (Boolean a)
(Ord a, ??? a) => Ord (Boolean a)
(Show a, ??? a) => Show (Boolean a)
(Read a, ??? a) => Read (Boolean a)
simplifyBoolean :: Bool -> Boolean a -> Boolean a

very safe simplification routine. This will never duplicate terms or change the order terms occur in the formula, so is safe to use even when bottom is present.

what it does is:

  • removes double negatives
  • evaluates constant terms
  • removes manifest tautologies
  • flattens and of and, or of or
  • flattens single element terms

if the first argument is true, it also uses de morgan's laws to ensure BoolNot may only occur as the parent of a BoolJust. This may allow additional flattening and simplification, but may increase the number of negations performed and change the ratio between ands and ors done. It does not affect term order either way.

showBoolean :: (a -> String) -> Boolean a -> String
evaluate :: BooleanAlgebra r => (a -> r) -> Boolean a -> r
evalute Boolean given a function to evaluate its primitives
evaluateM :: (Monad m, BooleanAlgebra r) => (a -> m r) -> Boolean a -> m r
evalute Boolean given a monadic function to evaluate its primitives
parseBoolean'
:: Parser sparser for whitespace
-> Parser tparser for true
-> Parser fparser for false
-> Parser aparser for a
-> Parser (Boolean a)parser for Boolean a

A parsec routine to parse a 'Boolean a' given a parser for a. The format is the same as produced by showBoolean:

 a ; b  - a or b
 a b    - a and b
 !a     - not a
 ( a )  - a

The parser passed as an argument should eat all whitespace after it matches and ensure its syntax does not conflict with the Boolean syntax.

dropBoolean :: BooleanAlgebra a => Boolean a -> a
perform the Boolean actions on the underlying type, flattening out the Boolean wrapper. This is useful for things like wrapping an expensive to compute predicate for the purposes of optimization.
Produced by Haddock version 0.6