Boolean-0.0.1: Generalized booleans

Stabilityexperimental
Maintainerconal@conal.net

Data.Boolean

Description

Some classes for generalized boolean operations.

In this design, for if-then-else, equality and inequality tests, the boolean type depends functionally on the value type. This dependency allows the boolean type to be inferred in a conditional expression.

I also tried using a unary type constructor class. The class doesn't work for regular booleans, so generality is lost. Also, we'd probably have to wire class constraints in like: (==*) :: Eq a => f Bool -> f a -> f a -> f a, which disallows situations needing additional constraints, e.g., Show.

Synopsis

Documentation

class Boolean b whereSource

Generalized boolean class

Methods

true :: bSource

false :: bSource

notB :: b -> bSource

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

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

class Boolean bool => IfB bool a | a -> bool whereSource

Types with conditionals

Methods

ifB :: bool -> a -> a -> aSource

boolean :: IfB bool a => a -> a -> bool -> aSource

Expression-lifted conditional with condition last

cond :: (Applicative f, IfB bool a) => f bool -> f a -> f a -> f aSource

Point-wise conditional

crop :: (Applicative f, Monoid (f a), IfB bool a) => f bool -> f a -> f aSource

Crop a function, filling in mempty where the test yeis false.

class Boolean bool => EqB bool a | a -> bool whereSource

Types with equality. Minimum definition: '(==*)'.

Methods

(==*) :: a -> a -> boolSource

(/=*) :: a -> a -> boolSource

class Boolean bool => OrdB bool a | a -> bool whereSource

Types with inequality. Minimum definition: '(<*)'.

Methods

(<*) :: a -> a -> boolSource

(>=*) :: a -> a -> boolSource

(>*) :: a -> a -> boolSource

(<=*) :: a -> a -> boolSource

minB :: (IfB bool a, OrdB bool a) => a -> a -> aSource

Variant of min using ifB and '(<=*)'

maxB :: (IfB bool a, OrdB bool a) => a -> a -> aSource

Variant of max using ifB and '(>=*)'