module Data.Algebra.Boolean.CoBoolean (
CoBoolean(..),
CoBoolean1(..),
toBool,
toBoolWith
) where
import Data.Algebra.Boolean
class CoBoolean a where
toBoolean :: Boolean b => a -> b
toBool :: CoBoolean a => a -> Bool
toBool = toBoolean
class CoBoolean1 b where
toBooleanWith :: Boolean c => (a -> c) -> b a -> c
toBoolWith :: CoBoolean1 b => (a -> Bool) -> b a -> Bool
toBoolWith = toBooleanWith
instance CoBoolean Bool where
toBoolean = fromBool
instance (CoBoolean f, CoBoolean g) => CoBoolean (Either f g) where
toBoolean (Left x) = toBoolean x
toBoolean (Right x) = toBoolean x
instance CoBoolean (Maybe a) where
toBoolean (Just _) = true
toBoolean Nothing = false
instance CoBoolean1 Maybe where
toBooleanWith f (Just x) = f x
toBooleanWith _ Nothing = false