Skip to content

Commit

Permalink
Merge pull request #24 from anttih/ps-0.7
Browse files Browse the repository at this point in the history
Updates for psc-0.7
  • Loading branch information
jdegoes committed Jul 2, 2015
2 parents c883eda + 8fb187b commit fdc300a
Show file tree
Hide file tree
Showing 26 changed files with 12,406 additions and 1,996 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/.*
!/.gitignore
!/.travis.yml
/output/
/node_modules/
/bower_components/
/tmp/
/node_modules/
/node_modules/
15 changes: 15 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
language: node_js
sudo: false
node_js:
- 0.12
env:
- PATH=$HOME/purescript:$PATH
install:
- 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')
- wget -O $HOME/purescript.tar.gz https://github.com/purescript/purescript/releases/download/$TAG/linux64.tar.gz
- tar -xvf $HOME/purescript.tar.gz -C $HOME/
- chmod a+x $HOME/purescript
- npm install bower gulp -g
- npm install && bower install
script:
- gulp
52 changes: 0 additions & 52 deletions Gruntfile.js

This file was deleted.

21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The moral equivalent of `ErrorT (ContT Unit (Eff e) a`, for effects `e`.
```purescript
main = launchAff $
do response <- Ajax.get "http://foo.bar"
liftEff $ trace response.body
liftEff $ log response.body
```

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

```purescript
do response <- ajaxGet' req
liftEff $ trace response.body
liftEff $ log response.body
```

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

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

```purescript
do e <- liftEff' myExcFunc
liftEff $ either (const $ trace "Oh noes!") (const $ trace "Yays!") e
liftEff $ either (const $ log "Oh noes!") (const $ log "Yays!") e
```

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

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

#### 2. Alt
Expand Down Expand Up @@ -168,7 +168,7 @@ using the returned canceler:
```purescript
canceler <- forkAff myAff
canceled <- canceler `cancel` (error "Just had to cancel")
_ <- liftEff $ if canceled then (trace "Canceled") else (trace "Not Canceled")
_ <- liftEff $ if canceled then (log "Canceled") else (log "Not Canceled")
```

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

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

# API Docs

[MODULES.md](MODULES.md)
* [Control.Monad.Aff](docs/Control.Monad.Aff.md)
* [Control.Monad.Aff.AVar](docs/Control.Monad.Aff.AVar.md)
* [Control.Monad.Aff.Console](docs/Control.Monad.Aff.Console.md)
* [Control.Monad.Aff.Class](docs/Control.Monad.Aff.Class.md)
* [Control.Monad.Aff.Par](docs/Control.Monad.Aff.Par.md)
* [Control.Monad.Aff.Unsafe](docs/Control.Monad.Aff.Unsafe.md)
21 changes: 12 additions & 9 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@
"package.json"
],
"dependencies": {
"purescript-tuples": "~0.3.0",
"purescript-either": "~0.1.4",
"purescript-monoid": "~0.2.0",
"purescript-exceptions": "~0.2.2",
"purescript-control": "~0.2.2",
"purescript-maybe": "~0.2.1",
"purescript-monad-eff": "~0.1.0",
"purescript-transformers": "~0.5.1"
"purescript-prelude": "~0.1.0",
"purescript-console": "~0.1.0",
"purescript-tuples": "~0.4.0",
"purescript-either": "~0.2.0",
"purescript-monoid": "~0.3.0",
"purescript-exceptions": "~0.3.0",
"purescript-control": "~0.3.0",
"purescript-maybe": "~0.3.0",
"purescript-eff": "~0.1.0",
"purescript-transformers": "~0.6.0",
"purescript-functions": "~0.1.0"
}
}
}
72 changes: 72 additions & 0 deletions docs/Control.Monad.Aff.AVar.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
## Module Control.Monad.Aff.AVar

A low-level primitive for building asynchronous code.

#### `AVAR`

``` purescript
data AVAR :: !
```

#### `AVar`

``` purescript
data AVar :: * -> *
```

#### `AffAVar`

``` purescript
type AffAVar e a = Aff (avar :: AVAR | e) a
```

#### `makeVar`

``` purescript
makeVar :: forall e a. AffAVar e (AVar a)
```

Makes a new asynchronous avar.

#### `makeVar'`

``` purescript
makeVar' :: forall e a. a -> AffAVar e (AVar a)
```

Makes a avar and sets it to some value.

#### `takeVar`

``` purescript
takeVar :: forall e a. AVar a -> AffAVar e a
```

Takes the next value from the asynchronous avar.

#### `putVar`

``` purescript
putVar :: forall e a. AVar a -> a -> AffAVar e Unit
```

Puts a new value into the asynchronous avar. If the avar has
been killed, this will result in an error.

#### `modifyVar`

``` purescript
modifyVar :: forall e a. (a -> a) -> AVar a -> AffAVar e Unit
```

Modifies the value at the head of the avar (will suspend until one is available).

#### `killVar`

``` purescript
killVar :: forall e a. AVar a -> Error -> AffAVar e Unit
```

Kills an asynchronous avar.


15 changes: 15 additions & 0 deletions docs/Control.Monad.Aff.Class.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## Module Control.Monad.Aff.Class

#### `MonadAff`

``` purescript
class MonadAff e m where
liftAff :: forall a. Aff e a -> m a
```

##### Instances
``` purescript
instance monadAffAff :: MonadAff e (Aff e)
```


21 changes: 21 additions & 0 deletions docs/Control.Monad.Aff.Console.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## Module Control.Monad.Aff.Console

#### `log`

``` purescript
log :: forall e. String -> Aff (console :: CONSOLE | e) String
```

Logs any string to the console. This basically saves you
from writing `liftEff $ log x` everywhere.

#### `print`

``` purescript
print :: forall e a. (Show a) => a -> Aff (console :: CONSOLE | e) a
```

Prints any `Show`-able value to the console. This basically saves you
from writing `liftEff $ print x` everywhere.


34 changes: 34 additions & 0 deletions docs/Control.Monad.Aff.Par.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
## Module Control.Monad.Aff.Par

A newtype over `Aff` that provides `Applicative` instances that run in
parallel. This is useful, for example, if you want to run a whole bunch
of AJAX requests at the same time, rather than sequentially.

#### `Par`

``` purescript
newtype Par e a
= Par (AffAVar e a)
```

##### Instances
``` purescript
instance semigroupPar :: (Semigroup a) => Semigroup (Par e a)
instance monoidPar :: (Monoid a) => Monoid (Par e a)
instance functorPar :: Functor (Par e)
instance applyPar :: Apply (Par e)
instance applicativePar :: Applicative (Par e)
instance altPar :: Alt (Par e)
instance plusPar :: Plus (Par e)
instance alternativePar :: Alternative (Par e)
```

#### `runPar`

``` purescript
runPar :: forall e a. Par e a -> AffAVar e a
```

Extracts the `Aff` from the `Par`.


15 changes: 15 additions & 0 deletions docs/Control.Monad.Aff.Unsafe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## Module Control.Monad.Aff.Unsafe

#### `unsafeTrace`

``` purescript
unsafeTrace :: forall e a. a -> Aff e Unit
```

#### `unsafeInterleaveAff`

``` purescript
unsafeInterleaveAff :: forall e1 e2 a. Aff e1 a -> Aff e2 a
```


Loading

0 comments on commit fdc300a

Please sign in to comment.