monad-fork (empty) → 0.1
raw patch · 5 files changed
+83/−0 lines, 5 filesdep +basedep +monad-controlsetup-changed
Dependencies added: base, monad-control
Files
- CONTRIBUTORS +1/−0
- LICENSE +2/−0
- Setup.hs +2/−0
- monad-fork.cabal +29/−0
- src/Control/Monad/Fork/Class.hs +49/−0
+ CONTRIBUTORS view
@@ -0,0 +1,1 @@+Robin Banks <anarchomorphism@seomraspraoi.org>
+ LICENSE view
@@ -0,0 +1,2 @@+may the last IP lawyer be hung+with the guts of the last cop
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ monad-fork.cabal view
@@ -0,0 +1,29 @@+name: monad-fork+version: 0.1+synopsis: Type class for monads which support a fork operation.+license: PublicDomain+license-file: LICENSE+author: Robin Banks+maintainer: anarchomorphism@seomraspraoi.org+stability: Experimental+category: Control+cabal-version: >= 1.6+build-type: Simple++extra-source-files:+ CONTRIBUTORS++Library+ hs-source-dirs:+ src++ exposed-modules:+ Control.Monad.Fork.Class++ build-depends:+ base > 4 && < 5,+ monad-control > 0.3 && < 0.4++source-repository head+ type: git+ location: git://git.seomraspraoi.org/monad-fork.git
+ src/Control/Monad/Fork/Class.hs view
@@ -0,0 +1,49 @@+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE OverlappingInstances #-}+{-# LANGUAGE UndecidableInstances #-}++module Control.Monad.Fork.Class+ ( MonadFork (..)+ )+where++import Control.Concurrent (ThreadId, forkIO)+import Control.Monad (liftM)+import Control.Monad.Trans.Control+ ( MonadBaseControl+ , MonadTransControl+ , liftBaseDiscard+ , liftWith+ )++------------------------------------------------------------------------------+-- | The 'MonadFork' type class, for monads which support a fork operation.+--+-- The instance for 'IO' is simply 'forkIO', while several very overlapping+-- instances are provided for composite monads, using the monad-control+-- package.+--+-- An example of a monad which has a 'MonadFork' instance that is not simply+-- a lifted form of 'forkIO' is the @ResourceT@ monad from the conduit+-- package, which defines the operation @resourceForkIO@. The instances+-- defined here, using the OverlappingInstances extension, will correctly+-- handle the case of monads transformed on top of @ResourceT@ (assuming a+-- definition exists for @ResourceT@).+class MonadFork m where+ fork :: m () -> m ThreadId+++------------------------------------------------------------------------------+instance MonadFork IO where+ fork = forkIO+++------------------------------------------------------------------------------+instance (MonadFork b, MonadBaseControl b m) => MonadFork m where+ fork = liftBaseDiscard fork+++------------------------------------------------------------------------------+instance (MonadTransControl t, MonadFork m, Monad m) => MonadFork (t m) where+ fork m = liftWith $ \run -> fork $ liftM (const ()) $ run m