monad-resumption 0.1.1.1 → 0.1.1.3
raw patch · 3 files changed
+34/−4 lines, 3 filesPVP: minor bump suggested
API additions: PVP suggests at least a minor version bump
API changes (from Hackage documentation)
+ Control.Monad.Resumption.Connectors: (<||>) :: Monad m => ReacT i1 o1 m a -> ReacT i2 o2 m a -> ReacT (i1, i2) (o1, o2) m a
+ Control.Monad.Resumption.Connectors: pipeline :: Monad m => ReacT i z m a -> ReacT z o m a -> ReacT i o m a
+ Control.Monad.Resumption.Connectors: refold :: Monad m => (o1 -> o2) -> (o1 -> i2 -> i1) -> ReacT i1 o1 m a -> ReacT i2 o2 m a
Files
- Control/Monad/Resumption/Connectors.hs +31/−0
- README.md +1/−3
- monad-resumption.cabal +2/−1
+ Control/Monad/Resumption/Connectors.hs view
@@ -0,0 +1,31 @@+module Control.Monad.Resumption.Connectors where++import Control.Monad.Resumption.Reactive++-- | The parallel operator for combining computations in ReacT that share +-- the same underlying monad and halting types. No guarantees are given to +-- which device's halting message will be seen by a handler.+(<||>) :: (Monad m) => ReacT i1 o1 m a -> ReacT i2 o2 m a -> ReacT (i1,i2) (o1,o2) m a+(<||>) (ReacT l) (ReacT r) = ReacT $ do+ l' <- l+ r' <- r+ case (l',r') of+ (Left a,_) -> return $ Left a+ (_,Left a) -> return $ Left a+ (Right (o1,res1),Right (o2,res2)) -> return $ Right ((o1,o2),\(i1,i2) -> (res1 i1) <||> (res2 i2))++-- | The refold operator changes the output and input types of a reactive resumption+refold :: (Monad m) => (o1 -> o2) -> (o1 -> i2 -> i1) -> ReacT i1 o1 m a -> ReacT i2 o2 m a+refold otpt inpt (ReacT r) = ReacT $ do+ r' <- r+ case r' of+ Left a -> return $ Left a+ Right (o1,res1) -> return $ Right (otpt o1, \i2 -> refold otpt inpt (res1 (inpt o1 i2)))++-- | Chains two reactive resumptions together in a pipelined fashioned. That is, inputs+-- and outputs are passed along between devices "tickwise".+pipeline :: (Monad m) => ReacT i z m a -> ReacT z o m a -> ReacT i o m a+pipeline r1 r2 = let r' = r1 <||> r2+ in refold snd pipe r'+ where+ pipe oldout newinp = (newinp,(fst oldout))
README.md view
@@ -1,6 +1,4 @@-monad-resumption+monad-resumption [](https://travis-ci.org/igraves/monad-resumption) ================= This library implements resumption and reactive resumption monads for use in resumption-passing style programming in Haskell. For more information on the basis behind Resumptions in Haskell, [Cheap (But Functional) Threads](http://people.cs.missouri.edu/~harrisonwl/drafts/CheapThreads.pdf) is an advisable read.--For additional reading, you can also consult this [blog post](ian.grav.es/monad-profile-reactive-resumption/).
monad-resumption.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: monad-resumption-version: 0.1.1.1+version: 0.1.1.3 synopsis: Resumption and reactive resumption monads for Haskell. description: This package contains the definitions of Resumption and Reactive Resumption Monads. homepage: https://github.com/igraves/resumption_monads@@ -23,6 +23,7 @@ exposed-modules: Control.Monad.Resumption Control.Monad.Resumption.Reactive+ Control.Monad.Resumption.Connectors -- other-modules: -- other-extensions: build-depends: base >=4.6 && <= 4.8, transformers, mtl