Skip to content
This repository was archived by the owner on Jan 17, 2020. It is now read-only.

Commit 61f5732

Browse files
authored
Merge pull request #7 from felixSchl/feature/ParIO
Add `ParIO`
2 parents eb96f34 + 3f81414 commit 61f5732

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

src/Control/Monad/IO.purs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
module Control.Monad.IO
22
( module Control.Monad.IO.Effect
33
, IO(..)
4+
, ParIO(..)
45
, runIO
56
, runIO'
67
, launchIO
78
) where
89

10+
import Prelude
11+
912
import Control.Alt (class Alt)
1013
import Control.Alternative (class Alternative)
11-
import Control.Monad.Aff (Aff, launchAff)
12-
import Control.Monad.Aff.Class (class MonadAff)
14+
import Control.Monad.Aff (Aff, ParAff(..), launchAff)
15+
import Control.Monad.Aff.Class (class MonadAff, liftAff)
1316
import Control.Monad.Aff.Unsafe (unsafeCoerceAff)
1417
import Control.Monad.Eff.Class (class MonadEff, liftEff)
1518
import Control.Monad.Eff.Exception (Error)
@@ -19,13 +22,16 @@ import Control.Monad.IO.Effect (INFINITY)
1922
import Control.Monad.IOSync (IOSync)
2023
import Control.Monad.Rec.Class (class MonadRec)
2124
import Control.MonadZero (class MonadZero)
25+
import Control.Parallel (class Parallel, parallel, sequential)
2226
import Control.Plus (class Plus)
2327
import Data.Monoid (class Monoid)
2428
import Data.Newtype (class Newtype, unwrap, wrap)
2529
import Prelude
2630

2731
newtype IO a = IO (Aff (infinity :: INFINITY) a)
2832

33+
newtype ParIO a = ParIO (ParAff (infinity :: INFINITY) a)
34+
2935
runIO :: IO ~> Aff (infinity :: INFINITY)
3036
runIO = unwrap
3137

@@ -42,16 +48,23 @@ derive newtype instance applyIO :: Apply IO
4248
derive newtype instance applicativeIO :: Applicative IO
4349
derive newtype instance bindIO :: Bind IO
4450
derive newtype instance monadIO :: Monad IO
51+
derive newtype instance monadRecIO :: MonadRec IO
52+
derive newtype instance semigroupIO :: (Semigroup a) => Semigroup (IO a)
53+
derive newtype instance monoidIO :: (Monoid a) => Monoid (IO a)
4554

46-
derive newtype instance monadRecIO :: MonadRec IO
47-
48-
derive newtype instance semigroupIO :: (Semigroup a) => Semigroup (IO a)
49-
50-
derive newtype instance monoidIO :: (Monoid a) => Monoid (IO a)
55+
derive newtype instance functorParIO :: Functor ParIO
56+
derive newtype instance applyParIO :: Apply ParIO
57+
derive newtype instance applicativeParIO :: Applicative ParIO
58+
derive newtype instance semigroupParIO :: (Semigroup a) => Semigroup (IO a)
59+
derive newtype instance monoidParIO :: (Monoid a) => Monoid (IO a)
5160

5261
instance monadAffIO :: MonadAff eff IO where
5362
liftAff = wrap <<< unsafeCoerceAff
5463

64+
instance parallelParIO :: Parallel ParIO IO where
65+
parallel = ParIO <<< ParAff <<< runIO
66+
sequential (ParIO (ParAff ma)) = IO ma
67+
5568
instance monadEffIO :: MonadEff eff IO where
5669
liftEff = wrap <<< liftEff <<< unsafeCoerceEff
5770

0 commit comments

Comments
 (0)