Boolean-0.2.3: Generalized booleans and numbers

Copyright(c) Conal Elliott 2009-2012
LicenseBSD3
Maintainerconal@conal.net
Stabilityexperimental
Safe HaskellSafe-Inferred
LanguageHaskell98

Data.Boolean

Description

Some classes for generalized boolean operations.

In this design, for if-then-else, equality and inequality tests, the boolean type depends on the value type.

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.

Starting with 0.1.0, this package uses type families. Up to version 0.0.2, it used MPTCs with functional dependencies. My thanks to Andy Gill for suggesting & helping with the change.

Synopsis

Documentation

class Boolean b where

Generalized boolean class

Methods

true, false :: b

notB :: b -> b

(&&*), (||*) :: b -> b -> b infixr 3 &&*infixr 2 ||*

Instances

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

type family BooleanOf a

BooleanOf computed the boolean analog of a specific type.

Instances

type BooleanOf Bool = Bool 
type BooleanOf Char = Bool 
type BooleanOf Double = Bool 
type BooleanOf Float = Bool 
type BooleanOf Int = Bool 
type BooleanOf Integer = Bool 
type BooleanOf [a] = BooleanOf a 
type BooleanOf (z -> a) = z -> BooleanOf a 
type BooleanOf (a, b) = BooleanOf a 
type BooleanOf (a, b, c) = BooleanOf a 
type BooleanOf (a, b, c, d) = BooleanOf a 

class Boolean (BooleanOf a) => IfB a where

Types with conditionals

Methods

ifB :: (bool ~ BooleanOf a) => bool -> a -> a -> a

Instances

IfB Bool 
IfB Char 
IfB Double 
IfB Float 
IfB Int 
IfB Integer 
(Boolean (BooleanOf a), (~) * (BooleanOf a) Bool) => IfB [a] 
IfB a => IfB (z -> a) 
((~) * bool (BooleanOf p), (~) * bool (BooleanOf q), IfB p, IfB q) => IfB (p, q) 
((~) * bool (BooleanOf p), (~) * bool (BooleanOf q), (~) * bool (BooleanOf r), IfB p, IfB q, IfB r) => IfB (p, q, r) 
((~) * bool (BooleanOf p), (~) * bool (BooleanOf q), (~) * bool (BooleanOf r), (~) * bool (BooleanOf s), IfB p, IfB q, IfB r, IfB s) => IfB (p, q, r, s) 

boolean :: (IfB a, bool ~ BooleanOf a) => a -> a -> bool -> a

Expression-lifted conditional with condition last

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

Point-wise conditional

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

Generalized cropping, filling in mempty where the test yields false.

class Boolean (BooleanOf a) => EqB a where

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

Minimal complete definition

(==*)

Methods

(==*), (/=*) :: (bool ~ BooleanOf a) => a -> a -> bool infix 4 ==*, /=*

Instances

class Boolean (BooleanOf a) => OrdB a where

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

Minimal complete definition

(<*)

Methods

(<*), (>=*), (>*), (<=*) :: (bool ~ BooleanOf a) => a -> a -> bool infix 4 <*, >=*, >*, <=*

Instances

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

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

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

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

sort2B :: (IfB a, OrdB a) => (a, a) -> (a, a)

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

guardedB :: (IfB b, bool ~ BooleanOf b) => bool -> [(bool, b)] -> b -> b

A generalized replacement for guards and chained ifs.

caseB :: (IfB b, bool ~ BooleanOf b) => a -> [(a -> bool, b)] -> b -> b

A generalized version of a case like control structure.