Skip to content

Commit f2f410f

Browse files
authored
Merge pull request #16 from purescript-contrib/compiler/0.12
Compiler/0.12
2 parents 489e8b6 + 59fd990 commit f2f410f

File tree

6 files changed

+51
-61
lines changed

6 files changed

+51
-61
lines changed

.gitignore

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
.psci*
2-
bower_components/
3-
output/
4-
.psc-package
5-
.psc-ide-port
1+
/.*
2+
!/.gitignore
3+
!/.travis.yml
4+
package-lock.json
5+
/bower_components/
6+
/node_modules/
7+
/output/

.travis.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
language: node_js
22
dist: trusty
33
sudo: required
4-
node_js: 6
4+
node_js: stable
5+
env:
6+
- PATH=$HOME/purescript:$PATH
57
install:
8+
- TAG=$(wget -q -O - https://github.com/purescript/purescript/releases/latest --server-response --max-redirect 0 2>&1 | sed -n -e 's/.*Location:.*tag\///p')
9+
- wget -O $HOME/purescript.tar.gz https://github.com/purescript/purescript/releases/download/$TAG/linux64.tar.gz
10+
- tar -xvf $HOME/purescript.tar.gz -C $HOME/
11+
- chmod a+x $HOME/purescript
612
- npm install -g bower
713
- npm install
814
script:

bower.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
"url": "git://github.com/purescript-contrib/purescript-aff-coroutines.git"
1515
},
1616
"dependencies": {
17-
"purescript-aff": "^4.0.0",
18-
"purescript-coroutines": "^4.0.0"
17+
"purescript-aff": "^5.0.0",
18+
"purescript-avar": "^3.0.0",
19+
"purescript-console": "^4.1.0",
20+
"purescript-coroutines": "^5.0.0"
1921
}
2022
}

package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
"test": "pulp test"
77
},
88
"devDependencies": {
9-
"pulp": "^11.0.0",
10-
"purescript-psa": "^0.5.0",
11-
"purescript": "^0.11.0",
12-
"rimraf": "^2.5.4"
9+
"pulp": "^12.2.0",
10+
"purescript-psa": "^0.6.0",
11+
"rimraf": "^2.6.2"
1312
}
1413
}

src/Control/Coroutine/Aff.purs

Lines changed: 22 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,37 @@
1-
-- | This module defines functions for creating coroutines on top of the `Aff` monad.
1+
-- | This module defines functions for creating coroutines on top of the `Aff`
2+
-- | monad.
23
-- |
3-
-- | The `Aff` monad only supports actions which return a single value, asynchronously, so this
4-
-- | module provides a principled way to deal with asynchronous _streams_ of values, and asynchronous consumers
5-
-- | of streamed data.
6-
4+
-- | The `Aff` monad only supports actions which return a single value,
5+
-- | asynchronously, so this module provides a principled way to deal with
6+
-- | asynchronous _streams_ of values, and asynchronous consumers of streamed
7+
-- | data.
78
module Control.Coroutine.Aff where
89

910
import Prelude
1011

1112
import Control.Coroutine (Producer, producer)
12-
import Control.Monad.Aff (Aff, runAff, forkAff)
13-
import Control.Monad.Aff.AVar (AVAR, makeEmptyVar, takeVar, putVar)
14-
import Control.Monad.Aff.Class (class MonadAff, liftAff)
15-
import Control.Monad.Eff (Eff)
16-
import Control.Monad.Eff.Class (liftEff)
13+
import Effect.Aff (Aff, runAff, forkAff)
14+
import Effect.Aff.AVar as AVar
15+
import Effect.Aff.Class (class MonadAff, liftAff)
16+
import Effect (Effect)
17+
import Effect.Class (liftEffect)
1718
import Control.Monad.Free.Trans (hoistFreeT)
1819
import Control.Monad.Trans.Class (lift)
1920
import Data.Either (Either(..))
2021
import Data.Newtype (class Newtype)
2122

22-
newtype Emitter m a r eff = Emitter (Step a r -> m (avar :: AVAR | eff) Unit)
23+
newtype Emitter m a r = Emitter (Step a r -> m Unit)
2324

24-
derive instance newtypeEmitter :: Newtype (Emitter m a r eff) _
25+
derive instance newtypeEmitter :: Newtype (Emitter m a r) _
2526

2627
data Step a b
2728
= Emit a
2829
| Finish b
2930

30-
emit
31-
:: forall m a r eff
32-
. Emitter m a r eff
33-
-> a
34-
-> m (avar :: AVAR | eff) Unit
31+
emit :: forall m a r. Emitter m a r -> a -> m Unit
3532
emit (Emitter f) = f <<< Emit
3633

37-
close
38-
:: forall m a r eff
39-
. Emitter m a r eff
40-
-> r
41-
-> m (avar :: AVAR | eff) Unit
34+
close :: forall m a r. Emitter m a r -> r -> m Unit
4235
close (Emitter f) = f <<< Finish
4336

4437
-- | Create a `Producer` using an asynchronous callback.
@@ -56,20 +49,13 @@ close (Emitter f) = f <<< Finish
5649
-- | log "Done!"
5750
-- | close emitter "finished"
5851
-- | ```
59-
produce
60-
:: forall a r eff
61-
. (Emitter Eff a r eff -> Eff (avar :: AVAR | eff) Unit)
62-
-> Producer a (Aff (avar :: AVAR | eff)) r
52+
produce :: forall a r. (Emitter Effect a r -> Effect Unit) -> Producer a Aff r
6353
produce recv = produceAff \(Emitter send) ->
64-
liftEff (recv (Emitter (void <<< runAff (const (pure unit)) <<< send)))
54+
liftEffect (recv (Emitter (void <<< runAff (const (pure unit)) <<< send)))
6555

6656
-- | A version of `produce` that creates a `Producer` with an underlying
6757
-- | `MonadAff`, rather than `Aff` specifically.
68-
produce'
69-
:: forall a r m eff
70-
. MonadAff (avar :: AVAR | eff) m
71-
=> (Emitter Eff a r eff -> Eff (avar :: AVAR | eff) Unit)
72-
-> Producer a m r
58+
produce' :: forall a r m. MonadAff m => (Emitter Effect a r -> Effect Unit) -> Producer a m r
7359
produce' = hoistFreeT liftAff <<< produce
7460

7561
-- | A variant of `produce` where the setup and callback functions use the `Aff`
@@ -84,13 +70,10 @@ produce' = hoistFreeT liftAff <<< produce
8470
-- | delay $ Milliseconds 1000
8571
-- | close emitter "finished"
8672
-- | ```
87-
produceAff
88-
:: forall a r eff
89-
. (Emitter Aff a r eff -> Aff (avar :: AVAR | eff) Unit)
90-
-> Producer a (Aff (avar :: AVAR | eff)) r
73+
produceAff :: forall a r. (Emitter Aff a r -> Aff Unit) -> Producer a Aff r
9174
produceAff recv = do
92-
v <- lift makeEmptyVar
93-
_ <- lift (forkAff (recv (Emitter (flip putVar v))))
94-
producer $ takeVar v <#> case _ of
75+
v <- lift AVar.empty
76+
_ <- lift (forkAff (recv (Emitter (flip AVar.put v))))
77+
producer $ AVar.take v <#> case _ of
9578
Emit a -> Left a
9679
Finish b -> Right b

test/Main.purs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@ import Prelude
44

55
import Control.Coroutine (Consumer, Producer, runProcess, consumer, ($$))
66
import Control.Coroutine.Aff (emit, close, produceAff)
7-
import Control.Monad.Aff (Aff, Milliseconds(..), delay, runAff)
8-
import Control.Monad.Aff.AVar (AVAR)
9-
import Control.Monad.Eff (Eff)
10-
import Control.Monad.Eff.Class (liftEff)
11-
import Control.Monad.Eff.Console (CONSOLE, log, logShow)
12-
import Control.Monad.Eff.Exception (EXCEPTION)
7+
import Effect.Aff (Aff, Milliseconds(..), delay, runAff)
8+
import Effect (Effect)
9+
import Effect.Class (liftEffect)
10+
import Effect.Console (log, logShow)
1311
import Data.Either (either)
1412
import Data.Maybe (Maybe(..))
1513

16-
p :: forall eff. Producer String (Aff (avar :: AVAR | eff)) String
14+
p :: Producer String Aff String
1715
p = produceAff \emitter -> do
1816
delay (Milliseconds 1000.0)
1917
emit emitter "Working..."
@@ -24,8 +22,8 @@ p = produceAff \emitter -> do
2422
delay (Milliseconds 1000.0)
2523
close emitter "Done!"
2624

27-
c :: forall eff. Consumer String (Aff (console :: CONSOLE | eff)) String
28-
c = consumer \s -> liftEff (log s) $> Nothing
25+
c :: Consumer String Aff String
26+
c = consumer \s -> liftEffect (log s) $> Nothing
2927

30-
main :: forall eff. Eff (console :: CONSOLE, avar :: AVAR, err :: EXCEPTION | eff) Unit
28+
main :: Effect Unit
3129
main = void $ runAff (either logShow log) $ runProcess (p $$ c)

0 commit comments

Comments
 (0)