Skip to content

Commit fdc300a

Browse files
committed
Merge pull request #24 from anttih/ps-0.7
Updates for psc-0.7
2 parents c883eda + 8fb187b commit fdc300a

26 files changed

+12406
-1996
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/.*
22
!/.gitignore
3+
!/.travis.yml
34
/output/
45
/node_modules/
56
/bower_components/
67
/tmp/
7-
/node_modules/
8+
/node_modules/

.travis.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
language: node_js
2+
sudo: false
3+
node_js:
4+
- 0.12
5+
env:
6+
- PATH=$HOME/purescript:$PATH
7+
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
12+
- npm install bower gulp -g
13+
- npm install && bower install
14+
script:
15+
- gulp

Gruntfile.js

Lines changed: 0 additions & 52 deletions
This file was deleted.

README.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ The moral equivalent of `ErrorT (ContT Unit (Eff e) a`, for effects `e`.
1111
```purescript
1212
main = launchAff $
1313
do response <- Ajax.get "http://foo.bar"
14-
liftEff $ trace response.body
14+
liftEff $ log response.body
1515
```
1616

1717
See the [examples directory](/examples/src/Examples.purs) for more examples.
@@ -78,7 +78,7 @@ This eliminates callback hell and allows us to write code simply using `do` nota
7878

7979
```purescript
8080
do response <- ajaxGet' req
81-
liftEff $ trace response.body
81+
liftEff $ log response.body
8282
```
8383

8484
## Eff
@@ -88,7 +88,7 @@ All purely synchronous computations (`Eff`) can be lifted to asynchronous comput
8888
```purescript
8989
import Control.Monad.Eff.Class
9090
91-
liftEff $ trace "Hello world!"
91+
liftEff $ log "Hello world!"
9292
```
9393

9494
This lets you write your whole program in `Aff`, and still call out to synchronous code.
@@ -97,7 +97,7 @@ If your `Eff` code throws exceptions (`err :: Exception`), you can remove the ex
9797

9898
```purescript
9999
do e <- liftEff' myExcFunc
100-
liftEff $ either (const $ trace "Oh noes!") (const $ trace "Yays!") e
100+
liftEff $ either (const $ log "Oh noes!") (const $ log "Yays!") e
101101
```
102102

103103
## Dealing with Failure
@@ -122,7 +122,7 @@ This returns an `Either Error a` that you can use to recover from failure.
122122

123123
```purescript
124124
do e <- attempt $ Ajax.get "http://foo.com"
125-
liftEff $ either (const $ trace "Oh noes!") (const $ trace "Yays!") e
125+
liftEff $ either (const $ log "Oh noes!") (const $ log "Yays!") e
126126
```
127127

128128
#### 2. Alt
@@ -168,7 +168,7 @@ using the returned canceler:
168168
```purescript
169169
canceler <- forkAff myAff
170170
canceled <- canceler `cancel` (error "Just had to cancel")
171-
_ <- liftEff $ if canceled then (trace "Canceled") else (trace "Not Canceled")
171+
_ <- liftEff $ if canceled then (log "Canceled") else (log "Not Canceled")
172172
```
173173

174174
If you want to run a custom canceler if some other asynchronous computation is
@@ -186,7 +186,7 @@ The `Control.Monad.Aff.AVar` module contains asynchronous variables, which are v
186186
do v <- makeVar
187187
forkAff (later $ putVar v 1.0)
188188
a <- takeVar v
189-
liftEff $ trace ("Succeeded with " ++ show a)
189+
liftEff $ log ("Succeeded with " ++ show a)
190190
```
191191

192192
You can use these constructs as one-sided blocking queues, which suspend (if
@@ -212,4 +212,9 @@ A parallel computation can be canceled if both of its individual components can
212212

213213
# API Docs
214214

215-
[MODULES.md](MODULES.md)
215+
* [Control.Monad.Aff](docs/Control.Monad.Aff.md)
216+
* [Control.Monad.Aff.AVar](docs/Control.Monad.Aff.AVar.md)
217+
* [Control.Monad.Aff.Console](docs/Control.Monad.Aff.Console.md)
218+
* [Control.Monad.Aff.Class](docs/Control.Monad.Aff.Class.md)
219+
* [Control.Monad.Aff.Par](docs/Control.Monad.Aff.Par.md)
220+
* [Control.Monad.Aff.Unsafe](docs/Control.Monad.Aff.Unsafe.md)

bower.json

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@
1919
"package.json"
2020
],
2121
"dependencies": {
22-
"purescript-tuples": "~0.3.0",
23-
"purescript-either": "~0.1.4",
24-
"purescript-monoid": "~0.2.0",
25-
"purescript-exceptions": "~0.2.2",
26-
"purescript-control": "~0.2.2",
27-
"purescript-maybe": "~0.2.1",
28-
"purescript-monad-eff": "~0.1.0",
29-
"purescript-transformers": "~0.5.1"
22+
"purescript-prelude": "~0.1.0",
23+
"purescript-console": "~0.1.0",
24+
"purescript-tuples": "~0.4.0",
25+
"purescript-either": "~0.2.0",
26+
"purescript-monoid": "~0.3.0",
27+
"purescript-exceptions": "~0.3.0",
28+
"purescript-control": "~0.3.0",
29+
"purescript-maybe": "~0.3.0",
30+
"purescript-eff": "~0.1.0",
31+
"purescript-transformers": "~0.6.0",
32+
"purescript-functions": "~0.1.0"
3033
}
31-
}
34+
}

docs/Control.Monad.Aff.AVar.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
## Module Control.Monad.Aff.AVar
2+
3+
A low-level primitive for building asynchronous code.
4+
5+
#### `AVAR`
6+
7+
``` purescript
8+
data AVAR :: !
9+
```
10+
11+
#### `AVar`
12+
13+
``` purescript
14+
data AVar :: * -> *
15+
```
16+
17+
#### `AffAVar`
18+
19+
``` purescript
20+
type AffAVar e a = Aff (avar :: AVAR | e) a
21+
```
22+
23+
#### `makeVar`
24+
25+
``` purescript
26+
makeVar :: forall e a. AffAVar e (AVar a)
27+
```
28+
29+
Makes a new asynchronous avar.
30+
31+
#### `makeVar'`
32+
33+
``` purescript
34+
makeVar' :: forall e a. a -> AffAVar e (AVar a)
35+
```
36+
37+
Makes a avar and sets it to some value.
38+
39+
#### `takeVar`
40+
41+
``` purescript
42+
takeVar :: forall e a. AVar a -> AffAVar e a
43+
```
44+
45+
Takes the next value from the asynchronous avar.
46+
47+
#### `putVar`
48+
49+
``` purescript
50+
putVar :: forall e a. AVar a -> a -> AffAVar e Unit
51+
```
52+
53+
Puts a new value into the asynchronous avar. If the avar has
54+
been killed, this will result in an error.
55+
56+
#### `modifyVar`
57+
58+
``` purescript
59+
modifyVar :: forall e a. (a -> a) -> AVar a -> AffAVar e Unit
60+
```
61+
62+
Modifies the value at the head of the avar (will suspend until one is available).
63+
64+
#### `killVar`
65+
66+
``` purescript
67+
killVar :: forall e a. AVar a -> Error -> AffAVar e Unit
68+
```
69+
70+
Kills an asynchronous avar.
71+
72+

docs/Control.Monad.Aff.Class.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## Module Control.Monad.Aff.Class
2+
3+
#### `MonadAff`
4+
5+
``` purescript
6+
class MonadAff e m where
7+
liftAff :: forall a. Aff e a -> m a
8+
```
9+
10+
##### Instances
11+
``` purescript
12+
instance monadAffAff :: MonadAff e (Aff e)
13+
```
14+
15+

docs/Control.Monad.Aff.Console.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## Module Control.Monad.Aff.Console
2+
3+
#### `log`
4+
5+
``` purescript
6+
log :: forall e. String -> Aff (console :: CONSOLE | e) String
7+
```
8+
9+
Logs any string to the console. This basically saves you
10+
from writing `liftEff $ log x` everywhere.
11+
12+
#### `print`
13+
14+
``` purescript
15+
print :: forall e a. (Show a) => a -> Aff (console :: CONSOLE | e) a
16+
```
17+
18+
Prints any `Show`-able value to the console. This basically saves you
19+
from writing `liftEff $ print x` everywhere.
20+
21+

docs/Control.Monad.Aff.Par.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
## Module Control.Monad.Aff.Par
2+
3+
A newtype over `Aff` that provides `Applicative` instances that run in
4+
parallel. This is useful, for example, if you want to run a whole bunch
5+
of AJAX requests at the same time, rather than sequentially.
6+
7+
#### `Par`
8+
9+
``` purescript
10+
newtype Par e a
11+
= Par (AffAVar e a)
12+
```
13+
14+
##### Instances
15+
``` purescript
16+
instance semigroupPar :: (Semigroup a) => Semigroup (Par e a)
17+
instance monoidPar :: (Monoid a) => Monoid (Par e a)
18+
instance functorPar :: Functor (Par e)
19+
instance applyPar :: Apply (Par e)
20+
instance applicativePar :: Applicative (Par e)
21+
instance altPar :: Alt (Par e)
22+
instance plusPar :: Plus (Par e)
23+
instance alternativePar :: Alternative (Par e)
24+
```
25+
26+
#### `runPar`
27+
28+
``` purescript
29+
runPar :: forall e a. Par e a -> AffAVar e a
30+
```
31+
32+
Extracts the `Aff` from the `Par`.
33+
34+

docs/Control.Monad.Aff.Unsafe.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## Module Control.Monad.Aff.Unsafe
2+
3+
#### `unsafeTrace`
4+
5+
``` purescript
6+
unsafeTrace :: forall e a. a -> Aff e Unit
7+
```
8+
9+
#### `unsafeInterleaveAff`
10+
11+
``` purescript
12+
unsafeInterleaveAff :: forall e1 e2 a. Aff e1 a -> Aff e2 a
13+
```
14+
15+

0 commit comments

Comments
 (0)