packages feed

contstuff 1.0.1 → 1.1.0

raw patch · 3 files changed

+67/−5 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Control.ContStuff.Classes: class Monad m => Forkable m
+ Control.ContStuff.Classes: forkIO :: Forkable m => m a -> m ThreadId
+ Control.ContStuff.Classes: instance Forkable IO
+ Control.ContStuff.Trans: instance Forkable m => Forkable (ChoiceT r i m)
+ Control.ContStuff.Trans: instance Forkable m => Forkable (ContT r m)
+ Control.ContStuff.Trans: instance Forkable m => Forkable (EitherT r e m)
+ Control.ContStuff.Trans: instance Forkable m => Forkable (MaybeT r m)
+ Control.ContStuff.Trans: instance Forkable m => Forkable (StateT r s m)
- Control.ContStuff.Trans: findAll_ :: Applicative m => ChoiceT () i m a -> m ()
+ Control.ContStuff.Trans: findAll_ :: Applicative m => ChoiceT r i m a -> m ()
- Control.ContStuff.Trans: findFirst_ :: Applicative m => ChoiceT () i m a -> m ()
+ Control.ContStuff.Trans: findFirst_ :: Applicative m => ChoiceT r i m a -> m ()

Files

Control/ContStuff/Classes.hs view
@@ -16,6 +16,9 @@       Abortable(..),       -- ** Call with current continuation       CallCC(..), Label, labelCC, goto,+      -- ** Multithreading+      -- *** Forking+      Forkable(..),       -- ** Exceptions       HasExceptions(..),       bracket, bracket_, catch, finally, forbid, handle, raiseUnless,@@ -28,7 +31,9 @@     )     where +import qualified Control.Concurrent as Conc import Control.Applicative+import Control.Concurrent hiding (forkIO, forkOS) import Control.Monad import Control.Monad.Trans.Class import Prelude hiding (catch)@@ -72,6 +77,30 @@  goto :: Label m a -> a -> m () goto lk@(Label k) x = k x lk+++---------------------+-- Forkable monads --+---------------------++-- | Monads with support for forking threads.++class Monad m => Forkable m where+    -- | Generalization of 'Conc.forkIO'.+    forkIO :: m a -> m ThreadId++    -- x| Generalization of 'Conc.forkOS'.+    -- forkOS :: m a -> m ThreadId++    -- x| Generalization of 'Conc.runInBoundThread'.+    -- runInBoundThread :: m a -> m a++    -- x| Generalization of 'Conc.runInUnboundThread'.+    -- runInUnboundThread :: m a -> m a+++instance Forkable IO where+    forkIO = Conc.forkIO . (() <$)   ----------------
Control/ContStuff/Trans.hs view
@@ -85,6 +85,14 @@         ChoiceT $ \fold z k ->             cx (\xx yx kx -> cf (\xf yf kf -> fold xf (yf yx) kf) xx kx) z k +instance Forkable m => Forkable (ChoiceT r i m) where+    forkIO =+        let findAllM_ :: Monad m => ChoiceT r i m a -> m r+            findAllM_ = runChoiceT (\_ _ k -> k undefined)+                                   undefined+                                   (const $ return undefined)+        in lift . forkIO . findAllM_+ instance Functor (ChoiceT r i m) where     fmap f (ChoiceT c) =         ChoiceT $ \fold z k ->@@ -135,8 +143,10 @@  -- | Find all solutions and ignore them. -findAll_ :: Applicative m => ChoiceT () i m a -> m ()-findAll_ = runChoiceT (\_ _ k -> k undefined) undefined (const $ pure ())+findAll_ :: Applicative m => ChoiceT r i m a -> m ()+findAll_ =+    (() <$) .+    runChoiceT (\_ _ k -> k undefined) undefined (const $ pure undefined)   -- | Find the first solution.@@ -147,8 +157,10 @@  -- | Find the first solution and ignore it. -findFirst_ :: Applicative m => ChoiceT () i m a -> m ()-findFirst_ = runChoiceT (\_ _ _ -> pure ()) undefined (const $ pure ())+findFirst_ :: Applicative m => ChoiceT r i m a -> m ()+findFirst_ =+    (() <$) .+    runChoiceT (\_ _ _ -> pure undefined) undefined (const $ pure undefined)   -- | Turn a list into a computation with alternatives.@@ -196,6 +208,11 @@ instance CallCC (ContT r m) where     callCC f = ContT $ \k -> getContT (f (ContT . const . k)) k +instance Forkable m => Forkable (ContT r m) where+    forkIO (ContT c) =+        ContT $ \k ->+            forkIO (c (return . const undefined)) >>= k+ instance Functor (ContT r m) where     fmap f (ContT c) = ContT $ \k -> c (\x -> k (f x)) @@ -268,6 +285,12 @@         EitherT $ \k expk ->             getEitherT (f (\x -> EitherT $ \_ _ -> k x)) k expk +instance Forkable m => Forkable (EitherT r e m) where+    forkIO (EitherT c) =+        let uk :: Monad m => a -> m b+            uk = const (return undefined)+        in lift . forkIO $ c uk uk+ instance HasExceptions (EitherT r e m) where     type Exception (EitherT r e m) = e     raise exp = EitherT $ \_ expk -> expk exp@@ -358,6 +381,10 @@         MaybeT $ \just noth ->             getMaybeT (f (\x -> MaybeT $ \_ _ -> just x)) just noth +instance Forkable m => Forkable (MaybeT r m) where+    forkIO (MaybeT c) =+        lift . forkIO $ c (const $ return undefined) (return undefined)+ instance HasExceptions (MaybeT r m) where     type Exception (MaybeT r m) = ()     raise _ = MaybeT $ const id@@ -469,6 +496,12 @@     callCC f =         StateT $ \s0 k ->             getStateT (f (\x -> StateT $ \s1 _ -> k s1 x)) s0 k++instance Forkable m => Forkable (StateT r s m) where+    forkIO (StateT c) =+        StateT $ \s0 k ->+            forkIO (c s0 (const $ pure undefined))+            >>= k s0  instance Functor (StateT r s m) where     fmap f (StateT c) =
contstuff.cabal view
@@ -1,5 +1,5 @@ Name:          contstuff-Version:       1.0.1+Version:       1.1.0 Category:      Control, Monads Synopsis:      Fast, easy to use CPS-based monad transformers Maintainer:    Ertugrul Söylemez <es@ertes.de>