Skip to content

Commit ac1fff8

Browse files
authored
Merge pull request #151 from slamdata/compiler/0.12
Updates for PureScript 0.12
2 parents 3457df9 + a2309ad commit ac1fff8

15 files changed

+662
-908
lines changed

README.md

Lines changed: 13 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,20 @@ asynchronously without any callbacks. Error handling is baked in so you only
3737
deal with it when you want to.
3838

3939
The library contains instances for `Semigroup`, `Monoid`, `Apply`,
40-
`Applicative`, `Bind`, `Monad`, `Alt`, `Plus`, `MonadEff`, `MonadError`, and
40+
`Applicative`, `Bind`, `Monad`, `Alt`, `Plus`, `MonadEffect`, `MonadError`, and
4141
`Parallel`. These instances allow you to compose asynchronous code as easily
42-
as `Eff`, as well as interop with existing `Eff` code.
42+
as `Effect`, as well as interop with existing `Effect` code.
4343

4444
## Escaping Callback Hell
4545

4646
Hopefully, you're using libraries that already use the `Aff` type, so you
4747
don't even have to think about callbacks!
4848

4949
If you're building your own library, then you can make an `Aff` from
50-
low-level `Eff` callbacks with `makeAff`.
50+
low-level `Effect` callbacks with `makeAff`.
5151

5252
```purescript
53-
makeAff :: forall eff a. ((Either Error a -> Eff eff Unit) -> Eff eff (Canceler eff)) -> Aff eff a
53+
makeAff :: forall a. ((Either Error a -> Effect Unit) -> Effect Canceler) -> Aff a
5454
```
5555

5656
This function expects you to provide a handler, which should call the
@@ -60,7 +60,7 @@ You should also return `Canceler`, which is just a cleanup effect. Since
6060
`Aff` threads may be killed, all asynchronous operations should provide a
6161
mechanism for unscheduling it.
6262

63-
`Control.Monad.Aff.Compat` provides functions for easily binding FFI
63+
`Effect.Aff.Compat` provides functions for easily binding FFI
6464
definitions:
6565

6666
```javascript
@@ -84,14 +84,14 @@ exports._ajaxGet = function (request) { // accepts a request
8484
```
8585

8686
```purescript
87-
foreign import _ajaxGet :: forall eff. Request -> EffFnAff (ajax :: AJAX | eff) Response
87+
foreign import _ajaxGet :: Request -> EffectFnAff Response
8888
```
8989

9090
We can wrap this into an asynchronous computation like so:
9191

9292
```purescript
93-
ajaxGet :: forall eff. Request -> Aff (ajax :: AJAX | eff) Response
94-
ajaxGet = fromEffFnAff <<< _ajaxGet
93+
ajaxGet :: Request -> Aff Response
94+
ajaxGet = fromEffectFnAff <<< _ajaxGet
9595
```
9696

9797
This eliminates callback hell and allows us to write code simply using `do`
@@ -103,22 +103,18 @@ example = do
103103
log response.body
104104
```
105105

106-
## Eff
106+
## Effect
107107

108-
All purely synchronous computations (`Eff`) can be lifted to asynchronous
109-
computations with `liftEff` defined in `Control.Monad.Eff.Class`.
108+
All purely synchronous computations (`Effect`) can be lifted to asynchronous
109+
computations with `liftEffect` defined in `Effect.Class`.
110110

111111
```purescript
112-
liftEff $ log "Hello world!"
112+
liftEffect $ log "Hello world!"
113113
```
114114

115115
This lets you write your whole program in `Aff`, and still call out to
116116
synchronous code.
117117

118-
If your `Eff` code throws exceptions (`exception :: EXCEPTION`), you can
119-
remove the exception label using `liftEff'`. Exceptions are part of `Aff`s
120-
built-in semantics, so they will always be caught and propagated anyway.
121-
122118
## Dealing with Failure
123119

124120
`Aff` has error handling baked in, so ordinarily you don't have to worry
@@ -188,7 +184,7 @@ Because Javascript is single-threaded, forking does not actually cause the
188184
computation to be run in a separate thread. Forking just allows the subsequent
189185
actions to execute without waiting for the forked computation to complete.
190186

191-
Forking returns a `Fiber eff a`, representing the deferred computation. You can
187+
Forking returns a `Fiber a`, representing the deferred computation. You can
192188
kill a `Fiber` with `killFiber`, which will run any cancelers and cleanup, and
193189
you can observe a `Fiber`'s final value with `joinFiber`. If a `Fiber` threw
194190
an exception, it will be rethrown upon joining.
@@ -203,53 +199,6 @@ example = do
203199
else (log "Not Canceled")
204200
```
205201

206-
207-
## AVars
208-
209-
The `Control.Monad.Aff.AVar` module contains asynchronous variables, which
210-
are very similar to Haskell's `MVar`.
211-
212-
`AVar`s represent a value that is either full or empty. Calling `takeVar` on
213-
an empty `AVar` will queue until it is filled by a `putVar`.
214-
215-
```purescript
216-
example = do
217-
var <- makeEmptyVar
218-
_ <- forkAff do
219-
value <- takeVar var
220-
log $ "Got a value: " <> value
221-
_ <- forkAff do
222-
delay (Milliseconds 100.0)
223-
putVar var "hello"
224-
pure unit
225-
```
226-
```
227-
(Waits 100ms)
228-
> Got a value: hello
229-
```
230-
231-
Likewise, calling `putVar` on a filled `AVar` will queue until it is emptied by
232-
a `takeVar`.
233-
234-
```purescript
235-
example = do
236-
var <- makeVar "hello"
237-
_ <- forkAff do
238-
delay (Milliseconds 100.0)
239-
value <- takeVar var
240-
log $ "Got a value: " <> value
241-
putVar var "next"
242-
log "Value put"
243-
```
244-
```
245-
(Waits 100ms)
246-
> Got a value: hello
247-
> Value put
248-
```
249-
250-
These combinators (and a few more) can be used as the building blocks for
251-
complex asynchronous coordination.
252-
253202
## Parallel Execution
254203

255204
The `Parallel` instance for `Aff` makes writing parallel computations a breeze.

bower.json

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,19 @@
1717
"package.json"
1818
],
1919
"dependencies": {
20-
"purescript-console": "^3.0.0",
21-
"purescript-exceptions": "^3.0.0",
22-
"purescript-functions": "^3.0.0",
23-
"purescript-parallel": "^3.0.0",
24-
"purescript-transformers": "^3.0.0",
25-
"purescript-unsafe-coerce": "^3.0.0",
26-
"purescript-datetime": "^3.0.0",
27-
"purescript-free": "^4.0.1",
28-
"purescript-st": "^3.0.0",
29-
"purescript-type-equality": "^2.1.0",
30-
"purescript-avar": "^2.0.0"
20+
"purescript-exceptions": "^4.0.0",
21+
"purescript-functions": "^4.0.0",
22+
"purescript-parallel": "^4.0.0",
23+
"purescript-transformers": "^4.0.0",
24+
"purescript-unsafe-coerce": "^4.0.0",
25+
"purescript-datetime": "^4.0.0",
26+
"purescript-effect": "^2.0.0"
3127
},
3228
"devDependencies": {
33-
"purescript-partial": "^1.2.0",
34-
"purescript-minibench": "^1.0.0",
35-
"purescript-assert": "^3.0.0",
36-
"purescript-js-timers": "^3.0.0"
29+
"purescript-console": "^4.1.0",
30+
"purescript-partial": "^2.0.0",
31+
"purescript-minibench": "^2.0.0",
32+
"purescript-assert": "^4.0.0",
33+
"purescript-free": "^5.0.0"
3734
}
3835
}

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
},
88
"devDependencies": {
99
"jscs": "^3.0.7",
10-
"jshint": "^2.9.4",
11-
"pulp": "^11.0.0",
12-
"purescript-psa": "^0.5.0",
13-
"purescript": "^0.11.0",
14-
"rimraf": "^2.5.4"
10+
"jshint": "^2.9.5",
11+
"pulp": "^12.2.0",
12+
"purescript-psa": "^0.6.0",
13+
"purescript": "slamdata/node-purescript#0.12",
14+
"rimraf": "^2.6.2"
1515
},
1616
"jscsConfig": {
1717
"validateIndentation": false

0 commit comments

Comments
 (0)