Stability | experimental |
---|---|
Maintainer | [email protected] |
Safe Haskell | 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.
- class Boolean b where
- class Boolean bool => IfB bool a | a -> bool where
- ifB :: bool -> a -> a -> a
- boolean :: IfB bool a => a -> a -> bool -> a
- cond :: (Applicative f, IfB bool a) => f bool -> f a -> f a -> f a
- crop :: (Applicative f, Monoid (f a), IfB bool a) => f bool -> f a -> f a
- class Boolean bool => EqB bool a | a -> bool where
- class Boolean bool => OrdB bool a | a -> bool where
- minB :: (IfB bool a, OrdB bool a) => a -> a -> a
- maxB :: (IfB bool a, OrdB bool a) => a -> a -> a
Documentation
Generalized boolean class
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: '(==*)'.