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 aBoolean
to become aBoolean
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 thatMaybe
Bool
is aBoolean
. You can use this to implement 3-value logic ("true", "false" and "other"), withNothing
implementing "other". Any logical operations yieldNothing
unless all arguments areJust
something. (This is usually the behaviour you want.)
Documentation
Typeclass for things that have true and false values.
Instances:
Typeclass for things that support Boolean operators.
Instances:
Logical-AND of two values.
Logical-OR of two values. (Inclusive-OR.)
Logical-NOT of two values. (Logical inverse.)
Exclusive-OR (XOR). There is a default implementation, but you can override it for efficiency if desired.