AC-Boolean-1.1.0: Handle Boolean values generatically.



Type classes (and instances) for things that are like Booleans.

The names of methods in Boolean clash with the standard Prelude, so you probably want to inport the Prelude hiding these three names (since the class methods do the same thing, but with more general type signatures).

Please note the following points:

  • This module imports Control.Monad.Instances, which brings several new Monad instances into scope.
  • Among other things, a monad instance for functions is brought into scope. This, combined with the Boolean instance for monads, causes any function that returns a Boolean to become a Boolean itself. This allows you to write constructions such as (> 5) && (< 9), which has the obvious meaning.
  • Another interesting consequence of the Boolean instance for monads is that Maybe Bool is a Boolean. You can use this to implement 3-value logic ("true", "false" and "other"), with Nothing implementing "other". Any logical operations yield Nothing unless all arguments are Just something. (This is usually the behaviour you want.)



class BoolValue b whereSource

Typeclass for things that have true and false values.



true :: bSource

false :: bSource


lift_bool :: BoolValue b => Bool -> bSource

Convert a Bool value to the appropriate BoolValue.

class Boolean b whereSource

Typeclass for things that support Boolean operators.


  • Normal Bool values (obviously).
  • Any function that returns a Boolean. This instance arrises due to the monad instance for functions.
  • Any monadic action that returns a Boolean. The left action is performed before the right action (which may be significant, depending on the monad).


(&&) :: b -> b -> bSource

Logical-AND of two values.

(||) :: b -> b -> bSource

Logical-OR of two values. (Inclusive-OR.)

not :: b -> bSource

Logical-NOT of two values. (Logical inverse.)

xor :: b -> b -> bSource

Exclusive-OR (XOR). There is a default implementation, but you can override it for efficiency if desired.


Boolean Bool 
(Monad m, Boolean b) => Boolean (m b)