[Haskell-cafe] Inverting a Monad
Bas van Dijk
v.dijk.bas at gmail.com
Wed Feb 6 06:46:06 EST 2008
On Feb 6, 2008 12:39 PM, Miguel Mitrofanov <miguelimo38 at yandex.ru> wrote:
> > invM :: Maybe a -> Maybe ()
> > invM Nothing = Just ()
> > invM (Just _) = Nothing
> >
> > invL :: [] a -> [] ()
> > invL [] = [()]
> > invL (_:_) = []
> >
> >
> > How can I define this for an arbitrary Monad m?
>
> Such as Identity?
>
Well in:
inv :: (Monad m, ...) => m a -> m ()
inv m = ...
I don't mind that there are more constraints on 'm' than just Monad
maybe a MonadPlus constraint or others are needed.
(I was even thinking about a MonadTimes class as in:
class MonadPlus m => MonadTimes m where
mone :: m ()
mtimes :: m a -> m a -> m a
)
Thanks,
Bas
More information about the Haskell-Cafe
mailing list