-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Generalized boolean ops -- -- Some classes for generalized boolean operations. -- -- Copyright 2009 Conal Elliott; BSD3 license. @package Boolean @version 0.0.0 -- | 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. module Data.Boolean -- | Generalized boolean class class Boolean b true :: (Boolean b) => b false :: (Boolean b) => b notB :: (Boolean b) => b -> b (&&*) :: (Boolean b) => b -> b -> b (||*) :: (Boolean b) => b -> b -> b -- | Types with conditionals class (Boolean bool) => IfB bool a | a -> bool ifB :: (IfB bool a) => bool -> a -> a -> a -- | Expression-lifted conditional with condition last boolean :: (IfB bool a) => a -> a -> bool -> a -- | Point-wise conditional cond :: (Applicative f, IfB bool a) => f bool -> f a -> f a -> f a -- | Crop a function, filling in mempty where the test yeis false. crop :: (Applicative f, Monoid (f a), IfB bool a) => f bool -> f a -> f a -- | Types with equality. Minimum definition: '(==*)'. class (Boolean bool) => EqB bool a | a -> bool (==*) :: (EqB bool a) => a -> a -> bool (/=*) :: (EqB bool a) => a -> a -> bool -- | Types with inequality. Minimum definition: '(<*)'. class (Boolean bool) => OrdB bool a | a -> bool (<*) :: (OrdB bool a) => a -> a -> bool (>=*) :: (OrdB bool a) => a -> a -> bool (>*) :: (OrdB bool a) => a -> a -> bool (<=*) :: (OrdB bool a) => a -> a -> bool instance (OrdB bool a) => OrdB (z -> bool) (z -> a) instance (EqB bool a) => EqB (z -> bool) (z -> a) instance (IfB bool a) => IfB (z -> bool) (z -> a) instance (Boolean bool) => Boolean (z -> bool) instance (IfB bool p, IfB bool q, IfB bool r, IfB bool s) => IfB bool (p, q, r, s) instance (IfB bool p, IfB bool q, IfB bool r) => IfB bool (p, q, r) instance (IfB bool p, IfB bool q) => IfB bool (p, q) instance OrdB Bool Float instance EqB Bool Float instance IfB Bool Float instance Boolean Bool