I've discovered that if contravariant data types have access to a monad, it's possible to implement monadic versions of them:
newtype Predicate m a = Predicate
{ getPredicate :: a -> m Bool
}
newtype Comparison m a = Comparison
{ getComparison :: a -> a -> m Ordering
}
newtype Op m a b = Op
{ getOp :: b -> m a
}
class ContravariantM t where
cmapM :: Monad m => (a -> m b) -> t m b -> t m a
class DivisibleM t where
divide :: Monad m => (a -> m (b, c)) -> t m b -> t m c -> t m a
class DecidableM t where
decide :: Monad m => (a -> m (Either b c)) -> t m b -> t m c -> t m a
Monadic contravariant functions like the above ones are used in co-log. Does it make sense in general to have such abstractions? And do they have a proper name?
I've discovered that if contravariant data types have access to a monad, it's possible to implement monadic versions of them:
Monadic contravariant functions like the above ones are used in
co-log
. Does it make sense in general to have such abstractions? And do they have a proper name?