Skip to content

Commit 9970bed

Browse files
authored
Merge pull request #2 from slamdata/compiler/0.12
Compiler/0.12
2 parents f3c6800 + 521dd30 commit 9970bed

File tree

8 files changed

+70
-72
lines changed

8 files changed

+70
-72
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: node_js
22
dist: trusty
33
sudo: required
4-
node_js: 6
4+
node_js: 8
55
install:
66
- npm install -g bower
77
- npm install

bower.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
"output"
1313
],
1414
"dependencies": {
15-
"purescript-aff": "^4.0.2"
15+
"purescript-aff": "^5.0.0",
16+
"purescript-avar": "^3.0.0"
1617
},
1718
"devDependencies": {
18-
"purescript-psci-support": "^3.0.0",
19-
"purescript-test-unit": "^13.0.0"
19+
"purescript-psci-support": "^4.0.0",
20+
"purescript-test-unit": "^14.0.0"
2021
}
2122
}

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
"test": "pulp test"
77
},
88
"devDependencies": {
9-
"pulp": "^12.0.1",
10-
"purescript": "^0.11.7",
9+
"pulp": "^12.0.0",
10+
"purescript": "^0.12.0",
1111
"purescript-psa": "^0.6.0",
12-
"rimraf": "^2.6.1"
12+
"rimraf": "^2.6.2"
1313
}
1414
}

src/Concurrent/BoundedQueue.purs

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,52 +14,53 @@ module Concurrent.BoundedQueue
1414

1515
import Prelude
1616

17-
import Control.Monad.Aff (Aff)
18-
import Control.Monad.Aff.AVar as AV
1917
import Data.Array (unsafeIndex)
2018
import Data.Maybe (Maybe(..))
2119
import Data.Unfoldable (replicateA)
20+
import Effect.Aff (Aff)
21+
import Effect.Aff.AVar (AVar)
22+
import Effect.Aff.AVar as AVar
2223
import Partial.Unsafe (unsafePartial)
2324

2425
newtype BoundedQueue a =
2526
BoundedQueue
2627
{ size Int
27-
, contents Array (AV.AVar a)
28-
, readPos AV.AVar Int
29-
, writePos AV.AVar Int
28+
, contents Array (AVar a)
29+
, readPos AVar Int
30+
, writePos AVar Int
3031
}
3132

3233
-- | Creates a new `BoundedQueue` with the given capacity,
33-
new a eff. Int Aff (avar AV.AVAR | eff) (BoundedQueue a)
34+
new a. Int Aff (BoundedQueue a)
3435
new size = do
35-
contents ← replicateA size AV.makeEmptyVar
36-
readPos ← AV.makeVar 0
37-
writePos ← AV.makeVar 0
36+
contents ← replicateA size AVar.empty
37+
readPos ← AVar.new 0
38+
writePos ← AVar.new 0
3839
pure (BoundedQueue { size, contents, readPos, writePos })
3940

4041
-- | Writes an element to the given queue. Will block if the queue is full until
4142
-- | someone reads from it.
42-
write a eff. BoundedQueue a a Aff (avar AV.AVAR | eff) Unit
43+
write a. BoundedQueue a a Aff Unit
4344
write (BoundedQueue q) a = do
44-
w ← AV.takeVar q.writePos
45-
AV.putVar a (unsafePartial unsafeIndex q.contents w)
46-
AV.putVar ((w + 1) `mod` q.size) q.writePos
45+
w ← AVar.take q.writePos
46+
AVar.put a (unsafePartial unsafeIndex q.contents w)
47+
AVar.put ((w + 1) `mod` q.size) q.writePos
4748

4849
-- | Reads an element from the given queue, will block if the queue is empty,
4950
-- | until someone writes to it.
50-
read a eff. BoundedQueue a Aff (avar AV.AVAR | eff) a
51+
read a. BoundedQueue a Aff a
5152
read (BoundedQueue q) = do
52-
r ← AV.takeVar q.readPos
53-
v ← AV.takeVar (unsafePartial unsafeIndex q.contents r)
54-
AV.putVar ((r + 1) `mod` q.size) q.readPos
53+
r ← AVar.take q.readPos
54+
v ← AVar.take (unsafePartial unsafeIndex q.contents r)
55+
AVar.put ((r + 1) `mod` q.size) q.readPos
5556
pure v
5657

5758
-- | Checks whether the given queue is empty. Never blocks.
58-
isEmpty a eff. BoundedQueue a Aff (avar AV.AVAR | eff) Boolean
59+
isEmpty a. BoundedQueue a Aff Boolean
5960
isEmpty (BoundedQueue q) = do
60-
AV.tryReadVar q.readPos >>= case _ of
61+
AVar.tryRead q.readPos >>= case _ of
6162
Nothing → pure true
62-
Just r → AV.tryReadVar (unsafePartial unsafeIndex q.contents r) <#> case _ of
63+
Just r → AVar.tryRead (unsafePartial unsafeIndex q.contents r) <#> case _ of
6364
Nothingtrue
6465
Just _ → false
6566

@@ -68,29 +69,29 @@ isEmpty (BoundedQueue q) = do
6869
-- |
6970
-- | *Careful!* If other readers are blocked on the queue `tryRead` will also
7071
-- | block.
71-
tryRead a eff. BoundedQueue a Aff (avar AV.AVAR | eff) (Maybe a)
72+
tryRead a. BoundedQueue a Aff (Maybe a)
7273
tryRead (BoundedQueue q) = do
73-
r ← AV.takeVar q.readPos
74-
AV.tryTakeVar (unsafePartial unsafeIndex q.contents r) >>= case _ of
74+
r ← AVar.take q.readPos
75+
AVar.tryTake (unsafePartial unsafeIndex q.contents r) >>= case _ of
7576
Just v → do
76-
AV.putVar ((r + 1) `mod` q.size) q.readPos
77+
AVar.put ((r + 1) `mod` q.size) q.readPos
7778
pure (Just v)
7879
Nothingdo
79-
AV.putVar r q.readPos
80+
AVar.put r q.readPos
8081
pure Nothing
8182

8283
-- | Attempts to write an element into the given queue. If the queue is full,
8384
-- | returns `false` otherwise `true`.
8485
-- |
8586
-- | *Careful!* If other writers are blocked on the queue `tryWrite` will also
8687
-- | block.
87-
tryWrite a eff. BoundedQueue a a Aff (avar AV.AVAR | eff) Boolean
88+
tryWrite a. BoundedQueue a a Aff Boolean
8889
tryWrite (BoundedQueue q) a = do
89-
w ← AV.takeVar q.writePos
90-
AV.tryPutVar a (unsafePartial unsafeIndex q.contents w) >>= if _
90+
w ← AVar.take q.writePos
91+
AVar.tryPut a (unsafePartial unsafeIndex q.contents w) >>= if _
9192
then do
92-
AV.putVar ((w + 1) `mod` q.size) q.writePos
93+
AVar.put ((w + 1) `mod` q.size) q.writePos
9394
pure true
9495
else do
95-
AV.putVar w q.writePos
96+
AVar.put w q.writePos
9697
pure false

src/Concurrent/Queue.purs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ module Concurrent.Queue
99

1010
import Prelude
1111

12-
import Control.Monad.Aff (Aff)
13-
import Control.Monad.Aff.AVar (AVAR, AVar, makeEmptyVar, makeVar, putVar, readVar, takeVar, tryReadVar)
1412
import Data.Maybe (Maybe(..))
13+
import Effect.Aff (Aff)
14+
import Effect.Aff.AVar (AVar)
15+
import Effect.Aff.AVar as AVar
1516

1617
-- | An unbounded Queue fit for concurrent access.
1718
newtype Queue a = Queue
@@ -23,42 +24,42 @@ type Stream a = AVar (QItem a)
2324
data QItem a = QItem a (Stream a)
2425

2526
-- | Creates a new `Queue`.
26-
new a e. Aff (avar AVAR | e) (Queue a)
27+
new a. Aff (Queue a)
2728
new = do
28-
hole ← makeEmptyVar
29-
readEnd ← makeVar hole
30-
writeEnd ← makeVar hole
29+
hole ← AVar.empty
30+
readEnd ← AVar.new hole
31+
writeEnd ← AVar.new hole
3132
pure (Queue { readEnd, writeEnd })
3233

3334
-- | Writes a new value into the queue
34-
write a e. Queue a a Aff (avar AVAR | e) Unit
35+
write a. Queue a a Aff Unit
3536
write (Queue q) a = do
36-
newHole ← makeEmptyVar
37-
oldHole ← takeVar q.writeEnd
38-
putVar (QItem a newHole) oldHole
39-
putVar newHole q.writeEnd
37+
newHole ← AVar.empty
38+
oldHole ← AVar.take q.writeEnd
39+
AVar.put (QItem a newHole) oldHole
40+
AVar.put newHole q.writeEnd
4041

4142
-- | Reads a value from the queue. Blocks if the queue is empty, and resumes
4243
-- | when it has been written to.
43-
read a e. Queue a Aff (avar AVAR | e) a
44+
read a. Queue a Aff a
4445
read (Queue q) = do
45-
readEnd ← takeVar q.readEnd
46-
QItem a newRead ← readVar readEnd
47-
putVar newRead q.readEnd
46+
readEnd ← AVar.take q.readEnd
47+
QItem a newRead ← AVar.read readEnd
48+
AVar.put newRead q.readEnd
4849
pure a
4950

5051
-- | Attempts to read a value from the queue. Fails with `Nothing` if the queue
5152
-- | is empty.
5253
-- |
5354
-- | *CAREFUL!* This will block if other readers are blocked on the
5455
-- | queue.
55-
tryRead a e. Queue a Aff (avar AVAR | e) (Maybe a)
56+
tryRead a. Queue a Aff (Maybe a)
5657
tryRead (Queue q) = do
57-
readEnd ← takeVar q.readEnd
58-
tryReadVar readEnd >>= case _ of
58+
readEnd ← AVar.take q.readEnd
59+
AVar.tryRead readEnd >>= case _ of
5960
Just (QItem a newRead) → do
60-
putVar newRead q.readEnd
61+
AVar.put newRead q.readEnd
6162
pure (Just a)
6263
Nothingdo
63-
putVar readEnd q.readEnd
64+
AVar.put readEnd q.readEnd
6465
pure Nothing

test/BoundedQueue.purs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,20 @@ import Prelude
44

55
import Concurrent.BoundedQueue as BQ
66
import Control.Alt ((<|>))
7-
import Control.Monad.Aff (Aff, Milliseconds(..), delay, forkAff, parallel, sequential)
8-
import Control.Monad.Aff.AVar (AVAR)
97
import Data.Either (Either(..), isLeft, isRight)
108
import Data.Int (toNumber)
119
import Data.Maybe (Maybe(..), isNothing)
10+
import Effect.Aff (Aff, Milliseconds(..), delay, forkAff, parallel, sequential)
1211
import Test.Unit (TestSuite, suite, test)
1312
import Test.Unit.Assert as Assert
1413

15-
race a b e. Aff e a Aff e b Aff e (Either a b)
14+
race a b. Aff a Aff b Aff (Either a b)
1615
race a b = sequential ((parallel (map Left a)) <|> (parallel (map Right b)))
1716

18-
delayMs e. Int Aff e Unit
17+
delayMs Int Aff Unit
1918
delayMs = delay <<< Milliseconds <<< toNumber
2019

21-
boundedQueueSuite e. TestSuite (avar AVAR | e)
20+
boundedQueueSuite TestSuite
2221
boundedQueueSuite = do
2322
suite "Simple operations" do
2423
test "inserting and popping elements" do

test/Main.purs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,13 @@ module Test.Main where
22

33
import Prelude
44

5-
import Control.Monad.Aff.AVar (AVAR)
6-
import Control.Monad.Aff.Console (CONSOLE)
7-
import Control.Monad.Eff (Eff)
5+
import Effect (Effect)
86
import Test.BoundedQueue (boundedQueueSuite)
97
import Test.Queue (queueSuite)
108
import Test.Unit (suite)
11-
import Test.Unit.Console (TESTOUTPUT)
129
import Test.Unit.Main (runTest)
1310

14-
main e. Eff (console CONSOLE, testOutput TESTOUTPUT, avar AVAR | e) Unit
11+
main Effect Unit
1512
main = runTest do
1613
suite "Queue" queueSuite
1714
suite "BoundedQueue" boundedQueueSuite

test/Queue.purs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,20 @@ import Prelude
44

55
import Concurrent.Queue as Q
66
import Control.Alt ((<|>))
7-
import Control.Monad.Aff (Aff, Milliseconds(..), delay, forkAff, parallel, sequential)
8-
import Control.Monad.Aff.AVar (AVAR)
97
import Data.Either (Either(..), isLeft, isRight)
108
import Data.Int (toNumber)
119
import Data.Maybe (Maybe(..), isNothing)
10+
import Effect.Aff (Aff, Milliseconds(..), delay, forkAff, parallel, sequential)
1211
import Test.Unit (TestSuite, suite, test)
1312
import Test.Unit.Assert as Assert
1413

15-
race a b e. Aff e a Aff e b Aff e (Either a b)
14+
race a b. Aff a Aff b Aff (Either a b)
1615
race a b = sequential ((parallel (map Left a)) <|> (parallel (map Right b)))
1716

18-
delayMs e. Int Aff e Unit
17+
delayMs Int Aff Unit
1918
delayMs = delay <<< Milliseconds <<< toNumber
2019

21-
queueSuite e. TestSuite (avar AVAR | e)
20+
queueSuite TestSuite
2221
queueSuite = do
2322
suite "Simple operations" do
2423
test "inserting and popping elements" do

0 commit comments

Comments
 (0)