Boolean-0.0.1: Generalized booleans

Stability experimental conal@conal.net Safe-Infered

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, false :: bSource

notB :: b -> bSource

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

Instances

 Boolean Bool Boolean bool => Boolean (z -> bool)

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

Types with conditionals

Methods

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

Instances

 IfB Bool Float (IfB bool p, IfB bool q) => IfB bool (p, q) (IfB bool p, IfB bool q, IfB bool r) => IfB bool (p, q, r) (IfB bool p, IfB bool q, IfB bool r, IfB bool s) => IfB bool (p, q, r, s) IfB bool a => IfB (z -> bool) (z -> a)

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

Instances

 EqB Bool Float EqB bool a => EqB (z -> bool) (z -> a)

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

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

Methods

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

Instances

 OrdB Bool Float OrdB bool a => OrdB (z -> bool) (z -> a)

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 '(>=*)'