Skip to content

Commit a9cb77f

Browse files
committed
Merge pull request #3 from purescript/updates
Updates
2 parents 4ef2ee3 + 1159e5f commit a9cb77f

11 files changed

Lines changed: 173 additions & 138 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/.*
22
!/.gitignore
3+
!/.travis.yml
34
/bower_components/
45
/node_modules/
56
/output/

.travis.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
language: node_js
2+
node_js:
3+
- 0.10
4+
env:
5+
- PATH=$HOME/purescript:$PATH
6+
install:
7+
- 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')
8+
- wget -O $HOME/purescript.tar.gz https://github.com/purescript/purescript/releases/download/$TAG/linux64.tar.gz
9+
- tar -xvf $HOME/purescript.tar.gz -C $HOME/
10+
- chmod a+x $HOME/purescript
11+
- npm install bower gulp -g
12+
- npm install && bower install
13+
script:
14+
- gulp

Gruntfile.js

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

README.md

Lines changed: 8 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,16 @@
1-
# Module Documentation
1+
# purescript-refs
22

3-
## Module Control.Monad.Eff.Ref
3+
[![Build Status](https://travis-ci.org/purescript/purescript-refs.svg?branch=master)](https://travis-ci.org/purescript/purescript-refs)
44

5+
Mutable value references.
56

6-
This module defines an effect and actions for working with
7-
global mutable variables.
7+
## Installation
88

9-
_Note_: The `Control.Monad.ST` provides a _safe_ alternative
10-
to global mutable variables when mutation is restricted to a
11-
local scope.
12-
13-
#### `Ref`
14-
15-
``` purescript
16-
data Ref :: !
179
```
18-
19-
The effect associated with the use of global mutable variables.
20-
21-
#### `RefVal`
22-
23-
``` purescript
24-
data RefVal :: * -> *
25-
```
26-
27-
A value of type `RefVal a` represents a mutable reference
28-
which holds a value of type `a`.
29-
30-
#### `newRef`
31-
32-
``` purescript
33-
newRef :: forall s r. s -> Eff (ref :: Ref | r) (RefVal s)
34-
```
35-
36-
Create a new mutable reference containing the specified value.
37-
38-
#### `readRef`
39-
40-
``` purescript
41-
readRef :: forall s r. RefVal s -> Eff (ref :: Ref | r) s
42-
```
43-
44-
Read the current value of a mutable reference
45-
46-
#### `modifyRef'`
47-
48-
``` purescript
49-
modifyRef' :: forall s b r. RefVal s -> (s -> { retVal :: b, newState :: s }) -> Eff (ref :: Ref | r) b
50-
```
51-
52-
Update the value of a mutable reference by applying a function
53-
to the current value.
54-
55-
#### `modifyRef`
56-
57-
``` purescript
58-
modifyRef :: forall s r. RefVal s -> (s -> s) -> Eff (ref :: Ref | r) Unit
59-
```
60-
61-
Update the value of a mutable reference by applying a function
62-
to the current value.
63-
64-
#### `writeRef`
65-
66-
``` purescript
67-
writeRef :: forall s r. RefVal s -> s -> Eff (ref :: Ref | r) Unit
68-
```
69-
70-
Update the value of a mutable reference to the specified value.
71-
72-
73-
## Module Control.Monad.Eff.Ref.Unsafe
74-
75-
76-
Unsafe functions for working with mutable references.
77-
78-
#### `unsafeRunRef`
79-
80-
``` purescript
81-
unsafeRunRef :: forall eff a. Eff (ref :: Ref | eff) a -> Eff eff a
10+
bower install purescript-refs
8211
```
8312

84-
This handler function unsafely removes the `Ref` effect from an
85-
effectful action.
13+
## Module documentation
8614

87-
This function might be used when it is impossible to prove to the
88-
typechecker that a particular mutable reference does not escape
89-
its scope.
15+
- [Control.Monad.Eff.Ref](docs/Control.Monad.Eff.Ref.md)
16+
- [Control.Monad.Eff.Ref.Unsafe](docs/Control.Monad.Eff.Ref.Unsafe.md)

bower.json

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
{
2-
"name": "purescript-refs",
3-
"homepage": "https://github.com/purescript/purescript-refs",
4-
"description": "Mutable value references",
5-
"keywords": [
6-
"purescript"
2+
"name": "purescript-semirings",
3+
"moduleType": [
4+
"node"
75
],
8-
"license": "MIT",
96
"ignore": [
107
"**/.*",
11-
"bower_components",
128
"node_modules",
9+
"bower_components",
1310
"output",
14-
"tests",
15-
"tmp",
1611
"bower.json",
17-
"Gruntfile.js",
12+
"gulpfile.js",
1813
"package.json"
19-
]
14+
],
15+
"dependencies": {
16+
"purescript-foldable-traversable": "~0.4.0"
17+
}
2018
}

docs/Control.Monad.Eff.Ref.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Module Documentation
2+
3+
## Module Control.Monad.Eff.Ref
4+
5+
6+
This module defines an effect and actions for working with
7+
global mutable variables.
8+
9+
_Note_: The `Control.Monad.ST` provides a _safe_ alternative
10+
to global mutable variables when mutation is restricted to a
11+
local scope.
12+
13+
#### `REF`
14+
15+
``` purescript
16+
data REF :: !
17+
```
18+
19+
The effect associated with the use of global mutable variables.
20+
21+
#### `Ref`
22+
23+
``` purescript
24+
data Ref :: * -> *
25+
```
26+
27+
A value of type `Ref a` represents a mutable reference
28+
which holds a value of type `a`.
29+
30+
#### `newRef`
31+
32+
``` purescript
33+
newRef :: forall s r. s -> Eff (ref :: REF | r) (Ref s)
34+
```
35+
36+
Create a new mutable reference containing the specified value.
37+
38+
#### `readRef`
39+
40+
``` purescript
41+
readRef :: forall s r. Ref s -> Eff (ref :: REF | r) s
42+
```
43+
44+
Read the current value of a mutable reference
45+
46+
#### `modifyRef'`
47+
48+
``` purescript
49+
modifyRef' :: forall s b r. Ref s -> (s -> { value :: b, state :: s }) -> Eff (ref :: REF | r) b
50+
```
51+
52+
Update the value of a mutable reference by applying a function
53+
to the current value.
54+
55+
#### `modifyRef`
56+
57+
``` purescript
58+
modifyRef :: forall s r. Ref s -> (s -> s) -> Eff (ref :: REF | r) Unit
59+
```
60+
61+
Update the value of a mutable reference by applying a function
62+
to the current value.
63+
64+
#### `writeRef`
65+
66+
``` purescript
67+
writeRef :: forall s r. Ref s -> s -> Eff (ref :: REF | r) Unit
68+
```
69+
70+
Update the value of a mutable reference to the specified value.
71+
72+
73+

docs/Control.Monad.Eff.Unsafe.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Module Documentation
2+
3+

gulpfile.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"use strict";
2+
3+
var gulp = require("gulp");
4+
var plumber = require("gulp-plumber");
5+
var purescript = require("gulp-purescript");
6+
var jsvalidate = require("gulp-jsvalidate");
7+
8+
var paths = [
9+
"src/**/*.purs",
10+
"bower_components/purescript-*/src/**/*.purs"
11+
];
12+
13+
gulp.task("make", function() {
14+
return gulp.src(paths)
15+
.pipe(plumber())
16+
.pipe(purescript.pscMake());
17+
});
18+
19+
gulp.task("jsvalidate", ["make"], function () {
20+
return gulp.src("output/**/*.js")
21+
.pipe(plumber())
22+
.pipe(jsvalidate());
23+
});
24+
25+
var docTasks = [];
26+
27+
var docTask = function(name) {
28+
var taskName = "docs-" + name.toLowerCase();
29+
gulp.task(taskName, function () {
30+
return gulp.src("src/" + name.replace(/\./g, "/") + ".purs")
31+
.pipe(plumber())
32+
.pipe(purescript.pscDocs())
33+
.pipe(gulp.dest("docs/" + name + ".md"));
34+
});
35+
docTasks.push(taskName);
36+
};
37+
38+
["Control.Monad.Eff.Ref", "Control.Monad.Eff.Unsafe"].forEach(docTask);
39+
40+
gulp.task("docs", docTasks);
41+
42+
gulp.task("dotpsci", function () {
43+
return gulp.src(paths)
44+
.pipe(plumber())
45+
.pipe(purescript.dotPsci());
46+
});
47+
48+
gulp.task("default", ["jsvalidate", "docs", "dotpsci"]);

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
22
"private": true,
3-
"dependencies": {
4-
"grunt": "~0.4.4",
5-
"grunt-purescript": "~0.6.0",
6-
"grunt-contrib-clean": "~0.5.0"
3+
"devDependencies": {
4+
"gulp": "^3.8.11",
5+
"gulp-jsvalidate": "^1.0.1",
6+
"gulp-plumber": "^1.0.0",
7+
"gulp-purescript": "^0.3.1"
78
}
89
}

src/Control/Monad/Eff/Ref.purs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ module Control.Monad.Eff.Ref where
1010
import Control.Monad.Eff
1111

1212
-- | The effect associated with the use of global mutable variables.
13-
foreign import data Ref :: !
13+
foreign import data REF :: !
1414

15-
-- | A value of type `RefVal a` represents a mutable reference
15+
-- | A value of type `Ref a` represents a mutable reference
1616
-- | which holds a value of type `a`.
17-
foreign import data RefVal :: * -> *
17+
foreign import data Ref :: * -> *
1818

1919
-- | Create a new mutable reference containing the specified value.
2020
foreign import newRef """
@@ -23,7 +23,7 @@ foreign import newRef """
2323
return { value: val };
2424
};
2525
}
26-
""" :: forall s r. s -> Eff (ref :: Ref | r) (RefVal s)
26+
""" :: forall s r. s -> Eff (ref :: REF | r) (Ref s)
2727

2828
-- | Read the current value of a mutable reference
2929
foreign import readRef """
@@ -32,7 +32,7 @@ foreign import readRef """
3232
return ref.value;
3333
};
3434
}
35-
""" :: forall s r. RefVal s -> Eff (ref :: Ref | r) s
35+
""" :: forall s r. Ref s -> Eff (ref :: REF | r) s
3636

3737
-- | Update the value of a mutable reference by applying a function
3838
-- | to the current value.
@@ -41,17 +41,17 @@ foreign import modifyRef' """
4141
return function(f) {
4242
return function() {
4343
var t = f(ref.value);
44-
ref.value = t.newState;
45-
return t.retVal;
44+
ref.value = t.state;
45+
return t.value;
4646
};
4747
};
4848
}
49-
""" :: forall s b r. RefVal s -> (s -> {newState :: s, retVal :: b}) -> Eff (ref :: Ref | r) b
49+
""" :: forall s b r. Ref s -> (s -> { state :: s, value :: b }) -> Eff (ref :: REF | r) b
5050

5151
-- | Update the value of a mutable reference by applying a function
5252
-- | to the current value.
53-
modifyRef :: forall s r. RefVal s -> (s -> s) -> Eff (ref :: Ref | r) Unit
54-
modifyRef ref f = modifyRef' ref (\s -> {newState: f s, retVal: unit})
53+
modifyRef :: forall s r. Ref s -> (s -> s) -> Eff (ref :: REF | r) Unit
54+
modifyRef ref f = modifyRef' ref (\s -> { state: f s, value: unit })
5555

5656
-- | Update the value of a mutable reference to the specified value.
5757
foreign import writeRef """
@@ -63,4 +63,4 @@ foreign import writeRef """
6363
};
6464
};
6565
}
66-
""" :: forall s r. RefVal s -> s -> Eff (ref :: Ref | r) Unit
66+
""" :: forall s r. Ref s -> s -> Eff (ref :: REF | r) Unit

0 commit comments

Comments
 (0)