Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add instances for Applicative and Functor #10

Merged
merged 1 commit into from Mar 14, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions Remote/Process.hs
Expand Up @@ -67,6 +67,7 @@ module Remote.Process (
import qualified Prelude as Prelude
import Prelude hiding (catch, id, init, last, lookup, pi)

import Control.Applicative (Applicative(..))
import Control.Concurrent (forkIO,ThreadId,threadDelay)
import Control.Concurrent.MVar (MVar,newMVar, newEmptyMVar,takeMVar,putMVar,modifyMVar,modifyMVar_,readMVar)
import Control.Exception (ErrorCall(..),throwTo,bracket,try,Exception,throw,evaluate,finally,SomeException,catch)
Expand Down Expand Up @@ -282,6 +283,14 @@ instance Monad ProcessM where
instance Functor ProcessM where
fmap f v = ProcessM $ (\p -> (runProcessM v) p >>= (\x -> return $ fmap f x))

instance Applicative ProcessM where
mf <*> mx =
ProcessM $ \p0 ->
runProcessM mf p0 >>= \(p1, f) ->
runProcessM mx p1 >>= \(p2, x) ->
return (p2, f x)
pure = return

instance MonadIO ProcessM where
liftIO arg = ProcessM $ \pr -> (arg >>= (\x -> return (pr,x)))

Expand Down
15 changes: 15 additions & 0 deletions Remote/Task.hs
Expand Up @@ -39,6 +39,7 @@ import System.Directory (renameFile)
import Data.Binary (Binary,get,put,putWord8,getWord8)
import Control.Exception (SomeException,Exception,throw)
import Data.Typeable (Typeable)
import Control.Applicative (Applicative(..))
import Control.Monad (liftM,when)
import Control.Monad.Trans (liftIO)
import Control.Concurrent.MVar (MVar,modifyMVar,modifyMVar_,newMVar,newEmptyMVar,takeMVar,putMVar,readMVar,withMVar)
Expand Down Expand Up @@ -851,6 +852,20 @@ instance Monad TaskM where
return (ts'',a')
return x = TaskM $ \ts -> return $ (ts,x)

instance Functor TaskM where
f `fmap` m =
TaskM $ \ts ->
runTaskM m ts >>= \(ts', x) ->
return (ts', f x)

instance Applicative TaskM where
mf <*> mx =
TaskM $ \ts ->
runTaskM mf ts >>= \(ts', f) ->
runTaskM mx ts' >>= \(ts'', x) ->
return (ts'', f x)
pure = return

lookupForwardedRedeemer :: PromiseId -> TaskM (Maybe ProcessId)
lookupForwardedRedeemer q =
TaskM $ \ts ->
Expand Down