Skip to content

Commit 088ef5f

Browse files
committed
Merge pull request #55 from kRITZCREEK/0.9
updates for 0.9
2 parents 7428d85 + 9011e1b commit 088ef5f

File tree

11 files changed

+64
-70
lines changed

11 files changed

+64
-70
lines changed

bower.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
"package.json"
1818
],
1919
"dependencies": {
20-
"purescript-console": "^0.1.0",
21-
"purescript-exceptions": "^0.3.0",
22-
"purescript-functions": "^0.1.0",
23-
"purescript-transformers": "^0.8.1"
20+
"purescript-console": "^1.0.0",
21+
"purescript-exceptions": "^1.0.0",
22+
"purescript-functions": "^1.0.0",
23+
"purescript-transformers": "^1.0.0"
2424
}
2525
}

package.json

+3-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
"private": true,
33
"scripts": {
44
"clean": "rimraf output && rimraf .pulp-cache",
5-
"build": "pulp build",
6-
"test": "pulp test"
5+
"build": "psc \"src/**/*.purs\" \"bower_components/purescript-*/src/**/*.purs\"",
6+
"test": "psc \"src/**/*.purs\" \"bower_components/purescript-*/src/**/*.purs\" \"test/**/*.purs\" && psc-bundle \"output/**/*.js\" --module Test.Main --main Test.Main | node"
77
},
88
"devDependencies": {
9-
"pulp": "^8.1.0",
10-
"purescript": "^0.7.6",
9+
"purescript": "^0.9.1-rc.1",
1110
"rimraf": "^2.5.2"
1211
}
1312
}

src/Control/Monad/Aff.js

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
/* global exports */
22
"use strict";
33

4-
// module Control.Monad.Aff
5-
64
exports._cancelWith = function (nonCanceler, aff, canceler1) {
75
return function(success, error) {
86
var canceler2 = aff(success, error);

src/Control/Monad/Aff.purs

+15-15
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,20 @@ module Control.Monad.Aff
2121
where
2222

2323
import Prelude
24-
25-
import Control.Alt (Alt)
26-
import Control.Alternative (Alternative)
27-
import Control.Monad.Cont.Class (MonadCont)
28-
import Control.Monad.Eff (Eff())
29-
import Control.Monad.Eff.Class (MonadEff)
30-
import Control.Monad.Eff.Exception (Error(), EXCEPTION(), throwException, error)
31-
import Control.Monad.Error.Class (MonadError, throwError)
32-
import Control.Monad.Rec.Class (MonadRec, tailRecM)
33-
import Control.MonadPlus (MonadPlus)
34-
import Control.Plus (Plus)
35-
24+
import Control.Alt (class Alt)
25+
import Control.Alternative (class Alternative)
26+
import Control.Monad.Cont.Class (class MonadCont)
27+
import Control.Monad.Eff (Eff)
28+
import Control.Monad.Eff.Class (class MonadEff)
29+
import Control.Monad.Eff.Exception (Error, EXCEPTION, throwException, error)
30+
import Control.Monad.Error.Class (class MonadError, throwError)
31+
import Control.Monad.Rec.Class (class MonadRec)
32+
import Control.MonadPlus (class MonadZero, class MonadPlus)
33+
import Control.Plus (class Plus)
3634
import Data.Either (Either(..), either, isLeft)
37-
import Data.Foldable (Foldable, foldl)
38-
import Data.Function (Fn2(), Fn3(), runFn2, runFn3)
39-
import Data.Monoid (Monoid, mempty)
35+
import Data.Foldable (class Foldable, foldl)
36+
import Data.Function.Uncurried (Fn2, Fn3, runFn2, runFn3)
37+
import Data.Monoid (class Monoid, mempty)
4038

4139
-- | An asynchronous computation with effects `e`. The computation either
4240
-- | errors or produces a value of type `a`.
@@ -188,6 +186,8 @@ instance plusAff :: Plus (Aff e) where
188186

189187
instance alternativeAff :: Alternative (Aff e)
190188

189+
instance monadZero :: MonadZero (Aff e)
190+
191191
instance monadPlusAff :: MonadPlus (Aff e)
192192

193193
instance monadRecAff :: MonadRec (Aff e) where

src/Control/Monad/Aff/AVar.js

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
/* global exports */
22
"use strict";
33

4-
// module Control.Monad.Aff.AVar
5-
64
exports._makeVar = function (nonCanceler) {
75
return function(success, error) {
86
try {
@@ -16,8 +14,8 @@ exports._makeVar = function (nonCanceler) {
1614
}
1715

1816
return nonCanceler;
19-
}
20-
}
17+
};
18+
};
2119

2220
exports._takeVar = function (nonCanceler, avar) {
2321
return function(success, error) {
@@ -32,8 +30,8 @@ exports._takeVar = function (nonCanceler, avar) {
3230
}
3331

3432
return nonCanceler;
35-
}
36-
}
33+
};
34+
};
3735

3836
exports._putVar = function (nonCanceler, avar, a) {
3937
return function(success, error) {
@@ -64,8 +62,8 @@ exports._putVar = function (nonCanceler, avar, a) {
6462
}
6563

6664
return nonCanceler;
67-
}
68-
}
65+
};
66+
};
6967

7068
exports._killVar = function (nonCanceler, avar, e) {
7169
return function(success, error) {
@@ -91,5 +89,5 @@ exports._killVar = function (nonCanceler, avar, e) {
9189
}
9290

9391
return nonCanceler;
94-
}
95-
}
92+
};
93+
};

src/Control/Monad/Aff/AVar.purs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import Prelude
1616
import Control.Monad.Aff (Aff(), Canceler(), nonCanceler)
1717
import Control.Monad.Eff.Exception (Error())
1818

19-
import Data.Function (Fn2(), Fn3(), runFn2, runFn3)
19+
import Data.Function.Uncurried (Fn2(), Fn3(), runFn2, runFn3)
2020

2121
foreign import data AVAR :: !
2222

@@ -33,7 +33,7 @@ makeVar' :: forall e a. a -> AffAVar e (AVar a)
3333
makeVar' a = do
3434
v <- makeVar
3535
putVar v a
36-
return v
36+
pure v
3737

3838
-- | Takes the next value from the asynchronous avar.
3939
takeVar :: forall e a. AVar a -> AffAVar e a

src/Control/Monad/Aff/Class.purs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Prelude
44

55
import Control.Monad.Aff (Aff())
66
import Control.Monad.Cont.Trans (ContT())
7-
import Control.Monad.Eff.Class (MonadEff)
7+
import Control.Monad.Eff.Class (class MonadEff)
88
import Control.Monad.Except.Trans (ExceptT())
99
import Control.Monad.List.Trans (ListT())
1010
import Control.Monad.Maybe.Trans (MaybeT())
@@ -14,7 +14,7 @@ import Control.Monad.State.Trans (StateT())
1414
import Control.Monad.Trans (lift)
1515
import Control.Monad.Writer.Trans (WriterT())
1616

17-
import Data.Monoid (Monoid)
17+
import Data.Monoid (class Monoid)
1818

1919
class (MonadEff eff m) <= MonadAff eff m where
2020
liftAff :: forall a. Aff eff a -> m a

src/Control/Monad/Aff/Console.purs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Control.Monad.Aff.Console where
22

33
import Prelude
4-
import qualified Control.Monad.Eff.Console as C
4+
import Control.Monad.Eff.Console as C
55

66
import Control.Monad.Aff (Aff())
77
import Control.Monad.Eff.Class (liftEff)
@@ -11,7 +11,7 @@ import Control.Monad.Eff.Class (liftEff)
1111
log :: forall e. String -> Aff (console :: C.CONSOLE | e) Unit
1212
log = liftEff <<< C.log
1313

14-
-- | Prints any `Show`-able value to the console. This basically saves you
15-
-- | from writing `liftEff $ print x` everywhere.
16-
print :: forall e a. (Show a) => a -> Aff (console :: C.CONSOLE | e) Unit
17-
print = liftEff <<< C.print
14+
-- | Logs any `Show`-able value to the console. This basically saves you
15+
-- | from writing `liftEff $ logShow x` everywhere.
16+
logShow :: forall e a. (Show a) => a -> Aff (console :: C.CONSOLE | e) Unit
17+
logShow = liftEff <<< C.logShow

src/Control/Monad/Aff/Par.purs

+8-10
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,14 @@ module Control.Monad.Aff.Par
77
) where
88

99
import Prelude
10-
11-
import Control.Alt (Alt)
12-
import Control.Alternative (Alternative)
10+
import Control.Alt (class Alt)
11+
import Control.Alternative (class Alternative)
1312
import Control.Monad.Aff (attempt, cancelWith, forkAff)
14-
import Control.Monad.Aff.AVar (AffAVar(), AVar(), makeVar, makeVar', takeVar, putVar, killVar)
15-
import Control.Monad.Eff.Exception (Error())
16-
import Control.Plus (Plus, empty)
17-
18-
import Data.Either (Either(), either)
19-
import Data.Monoid (Monoid, mempty)
13+
import Control.Monad.Aff.AVar (AffAVar, AVar, makeVar, makeVar', takeVar, putVar, killVar)
14+
import Control.Monad.Eff.Exception (Error)
15+
import Control.Plus (class Plus, empty)
16+
import Data.Either (Either, either)
17+
import Data.Monoid (class Monoid, mempty)
2018

2119
newtype Par e a = Par (AffAVar e a)
2220

@@ -51,7 +49,7 @@ instance altPar :: Alt (Par e) where
5149
alt (Par a1) (Par a2) =
5250
let maybeKill va ve err = do
5351
e <- takeVar ve
54-
if e == 1 then killVar va err else return unit
52+
if e == 1 then killVar va err else pure unit
5553
putVar ve (e + 1)
5654
in Par do
5755
va <- makeVar -- the `a` value

src/Control/Monad/Aff/Unsafe.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
/* global exports */
22
"use strict";
33

4-
// module Control.Monad.Aff.Unsafe
5-
64
exports.unsafeTrace = function (v) {
75
return function(success, error) {
86
console.log(v);
@@ -20,13 +18,13 @@ exports.unsafeTrace = function (v) {
2018
success(false);
2119

2220
return nonCanceler;
23-
}
21+
};
2422
};
2523

2624
return nonCanceler;
2725
};
28-
}
26+
};
2927

3028
exports.unsafeInterleaveAff = function (aff) {
3129
return aff;
32-
}
30+
};

test/Test/Main.purs

+14-11
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,30 @@ import Prelude
44

55
import Control.Alt ((<|>))
66
import Control.Apply ((*>))
7-
import Control.Monad.Aff (Aff(), runAff, later, later', forkAff, forkAll, Canceler(..), cancel, attempt, finally, apathize)
8-
import Control.Monad.Aff.AVar (AVAR(), makeVar, makeVar', putVar, modifyVar, takeVar, killVar)
7+
import Control.Monad.Aff (Aff, runAff, later, later', forkAff, forkAll, Canceler(..), cancel, attempt, finally, apathize)
8+
import Control.Monad.Aff.AVar (AVAR, makeVar, makeVar', putVar, modifyVar, takeVar, killVar)
99
import Control.Monad.Aff.Console (log)
1010
import Control.Monad.Aff.Par (Par(..), runPar)
1111
import Control.Monad.Cont.Class (callCC)
12-
import Control.Monad.Eff (Eff())
13-
import Control.Monad.Eff.Console (CONSOLE())
14-
import Control.Monad.Eff.Exception (EXCEPTION(), throwException, error)
12+
import Control.Monad.Eff (Eff)
13+
import Control.Monad.Eff.Console (CONSOLE)
14+
import Control.Monad.Eff.Exception (EXCEPTION, throwException, error)
1515
import Control.Monad.Error.Class (throwError)
1616
import Control.Monad.Rec.Class (tailRecM)
1717

18-
import Data.Array (replicate)
1918
import Data.Either (Either(..), either)
19+
import Data.Unfoldable (replicate)
2020

2121
type Test a = forall e. Aff (console :: CONSOLE | e) a
2222
type TestAVar a = forall e. Aff (console :: CONSOLE, avar :: AVAR | e) a
2323

24+
replicateArray :: forall a. Int -> a -> Array a
25+
replicateArray = replicate
26+
2427
test_sequencing :: Int -> Test Unit
2528
test_sequencing 0 = log "Done"
2629
test_sequencing n = do
27-
later' 100 (log (show (n / 10) ++ " seconds left"))
30+
later' 100 (log (show (n / 10) <> " seconds left"))
2831
test_sequencing (n - 1)
2932

3033
test_pure :: Test Unit
@@ -49,7 +52,7 @@ test_putTakeVar = do
4952
v <- makeVar
5053
forkAff (later $ putVar v 1.0)
5154
a <- takeVar v
52-
log ("Success: Value " ++ show a)
55+
log ("Success: Value " <> show a)
5356

5457
test_killFirstForked :: Test Unit
5558
test_killFirstForked = do
@@ -136,7 +139,7 @@ test_syncTailRecM = do
136139
log (if b then "Success: Synchronous tailRecM resolved synchronously"
137140
else "Failure: Synchronous tailRecM resolved asynchronously")
138141
where
139-
go { n = 0, v } = do
142+
go { n: 0, v } = do
140143
modifyVar (const true) v
141144
pure (Right 0)
142145
go { n, v } = pure (Left { n: n - 1, v })
@@ -155,13 +158,13 @@ loopAndBounce n = do
155158
all :: forall eff. Int -> Aff (console :: CONSOLE, avar :: AVAR | eff) Unit
156159
all n = do
157160
var <- makeVar' 0
158-
forkAll $ replicate n (modifyVar (+ 1) var)
161+
forkAll $ replicateArray n (modifyVar (_ + 1) var)
159162
count <- takeVar var
160163
log ("Forked " <> show count)
161164

162165
cancelAll :: forall eff. Int -> Aff (console :: CONSOLE, avar :: AVAR | eff) Unit
163166
cancelAll n = do
164-
canceler <- forkAll $ replicate n (later' 100000 (log "oops"))
167+
canceler <- forkAll $ replicateArray n (later' 100000 (log "oops"))
165168
canceled <- cancel canceler (error "bye")
166169
log ("Cancelled all: " <> show canceled)
167170

0 commit comments

Comments
 (0)