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,
- 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
Generalized boolean class
Types with conditionals
Crop a function, filling in
mempty where the test yeis false.
Types with equality. Minimum definition: '(==*)'.
Types with inequality. Minimum definition: '(<*)'.