Stability | experimental |
---|---|

Maintainer | conal@conal.net |

Safe Haskell | Safe-Inferred |

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.

- class Boolean b where
- type family BooleanOf a
- class Boolean (BooleanOf a) => IfB a where
- boolean :: (IfB a, bool ~ BooleanOf a) => a -> a -> bool -> a
- cond :: (Applicative f, IfB a, bool ~ BooleanOf a) => f bool -> f a -> f a -> f a
- crop :: (Applicative f, Monoid (f a), IfB a, bool ~ BooleanOf a) => f bool -> f a -> f a
- class Boolean (BooleanOf a) => EqB a where
- class Boolean (BooleanOf a) => OrdB a where
- minB :: (IfB a, OrdB a) => a -> a -> a
- maxB :: (IfB a, OrdB a) => a -> a -> a
- sort2B :: (IfB a, OrdB a) => (a, a) -> (a, a)
- guardedB :: (IfB b, bool ~ BooleanOf b) => bool -> [(bool, b)] -> b -> b
- caseB :: (IfB b, bool ~ BooleanOf b) => a -> [(a -> bool, b)] -> b -> b

# Documentation

Generalized boolean class

class Boolean (BooleanOf a) => IfB a whereSource

Types with conditionals

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 -> aSource

Expression-lifted conditional with condition last

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

Point-wise conditional

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

Generalized cropping, filling in `mempty`

where the test yields false.