contstuff 0.4.1 → 0.5.0
raw patch · 2 files changed
+85/−1 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Control.ContStuff: MaybeT :: ((a -> m r) -> m r -> m r) -> MaybeT r m a
+ Control.ContStuff: evalMaybeT :: (Applicative m) => MaybeT (Maybe a) m a -> m (Maybe a)
+ Control.ContStuff: getMaybeT :: MaybeT r m a -> (a -> m r) -> m r -> m r
+ Control.ContStuff: instance (Alternative m) => MonadPlus (MaybeT r m)
+ Control.ContStuff: instance (Alternative m) => Writable (MaybeT r m) r
+ Control.ContStuff: instance (Applicative m) => Abortable (MaybeT r m)
+ Control.ContStuff: instance (Functor m, Monoid w) => Writable (MaybeT (r, w) m) w
+ Control.ContStuff: instance (LiftBase m, Monad m) => LiftBase (MaybeT r m)
+ Control.ContStuff: instance Alternative (MaybeT r m)
+ Control.ContStuff: instance Applicative (MaybeT r m)
+ Control.ContStuff: instance CallCC (MaybeT r m)
+ Control.ContStuff: instance Functor (MaybeT r m)
+ Control.ContStuff: instance HasExceptions (MaybeT r m)
+ Control.ContStuff: instance Monad (MaybeT r m)
+ Control.ContStuff: instance Runnable (MaybeT r) r m a
+ Control.ContStuff: instance Transformer (MaybeT r)
+ Control.ContStuff: modifyMaybeT :: (Functor m) => (r -> r) -> MaybeT r m ()
+ Control.ContStuff: newtype MaybeT r m a
+ Control.ContStuff: runMaybeT :: (a -> m r) -> m r -> MaybeT r m a -> m r
Files
- Control/ContStuff.hs +84/−0
- contstuff.cabal +1/−1
Control/ContStuff.hs view
@@ -24,6 +24,7 @@ listChoiceT, listA, maybeChoiceT, -- ** Exceptions EitherT(..), runEitherT, evalEitherT, modifyEitherT,+ MaybeT(..), runMaybeT, evalMaybeT, modifyMaybeT, -- ** State StateT(..), runStateT, evalStateT, execStateT, -- ** Writer monads@@ -440,6 +441,87 @@ lift = IdT +------------+-- MaybeT --+------------++-- | Monad transformer for CPS computations with an additional exception+-- continuation with no argument.++newtype MaybeT r m a =+ MaybeT { getMaybeT :: (a -> m r) -> m r -> m r }++instance Applicative m => Abortable (MaybeT r m) where+ type Result (MaybeT r m) = r+ abort x = MaybeT $ \_ _ -> pure x++instance Applicative (MaybeT r m) where+ pure x = MaybeT $ \just _ -> just x+ MaybeT cf <*> MaybeT cx =+ MaybeT $ \just noth -> cf (\f -> cx (\x -> just (f x)) noth) noth++instance Alternative (MaybeT r m) where+ empty = MaybeT $ \_ noth -> noth+ MaybeT c <|> MaybeT d =+ MaybeT $ \just noth ->+ c (\x -> just x) (d (\x -> just x) noth)++instance CallCC (MaybeT r m) where+ callCC f =+ MaybeT $ \just noth ->+ getMaybeT (f (\x -> MaybeT $ \_ _ -> just x)) just noth++instance HasExceptions (MaybeT r m) where+ type Exception (MaybeT r m) = ()+ raise _ = MaybeT $ const id+ try (MaybeT c) = MaybeT $ \just _ -> c (just . Right) (just $ Left ())++instance Functor (MaybeT r m) where+ fmap f (MaybeT c) =+ MaybeT $ \just noth -> c (just . f) noth++instance Monad (MaybeT r m) where+ return x = MaybeT $ \just _ -> just x+ MaybeT c >>= f =+ MaybeT $ \just noth ->+ c (\x -> getMaybeT (f x) just noth) noth++instance Alternative m => MonadPlus (MaybeT r m) where+ mzero = empty+ mplus = (<|>)++instance Runnable (MaybeT r) r m a where+ type Argument (MaybeT r) r m a = (a -> m r, m r)+ runT (just, noth) (MaybeT c) = c just noth++instance Transformer (MaybeT r) where+ lift c = MaybeT $ \just _ -> c >>= just++instance Alternative m => Writable (MaybeT r m) r where+ tell x = MaybeT $ \just _ -> pure x <|> just ()++instance (Functor m, Monoid w) => Writable (MaybeT (r, w) m) w where+ tell x = MaybeT $ \just _ -> fmap (second (`mappend` x)) (just ())+++-- | Run a 'MaybeT' transformer.++runMaybeT :: (a -> m r) -> m r -> MaybeT r m a -> m r+runMaybeT just noth (MaybeT c) = c just noth+++-- | Run a 'MaybeT' transformer returning a 'Maybe' result.++evalMaybeT :: Applicative m => MaybeT (Maybe a) m a -> m (Maybe a)+evalMaybeT (MaybeT c) = c (pure . Just) (pure Nothing)+++-- | Modify the result of a 'MaybeT' computation along the way.++modifyMaybeT :: Functor m => (r -> r) -> MaybeT r m ()+modifyMaybeT f = MaybeT $ \just _ -> fmap f (just ())++ ---------------- -- OldWriterT -- ----------------@@ -750,6 +832,8 @@ type Base (ContT r m) = Base m; base = lift . base instance (LiftBase m, Monad m) => LiftBase (EitherT r e m) where type Base (EitherT r e m) = Base m; base = lift . base+instance (LiftBase m, Monad m) => LiftBase (MaybeT r m) where+ type Base (MaybeT r m) = Base m; base = lift . base instance (LiftBase m, Monad m) => LiftBase (StateT r s m) where type Base (StateT r s m) = Base m; base = lift . base
contstuff.cabal view
@@ -1,5 +1,5 @@ Name: contstuff-Version: 0.4.1+Version: 0.5.0 Category: Control, Monads Synopsis: Easy to use CPS-based monads Maintainer: Ertugrul Söylemez <es@ertes.de>