Skip to content
This repository was archived by the owner on Oct 4, 2020. It is now read-only.

Commit 03b5e5e

Browse files
committed
More updates for 0.7
1 parent 25d08a6 commit 03b5e5e

File tree

9 files changed

+148
-124
lines changed

9 files changed

+148
-124
lines changed

docs/Control.Monad.Eff.Unsafe.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## Module Control.Monad.Eff.Unsafe
2+
3+
#### `unsafeInterleaveEff`
4+
5+
``` purescript
6+
unsafeInterleaveEff :: forall eff1 eff2 a. Eff eff1 a -> Eff eff2 a
7+
```
8+
9+
Change the type of an effectful computation, allowing it to be run in another context.
10+
11+
Note: use of this function can result in arbitrary side-effects.
12+
13+

docs/Control.Monad.Eff.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
## Module Control.Monad.Eff
2+
3+
#### `Eff`
4+
5+
``` purescript
6+
data Eff :: # ! -> * -> *
7+
```
8+
9+
##### Instances
10+
``` purescript
11+
instance functorEff :: Functor (Eff e)
12+
instance applyEff :: Apply (Eff e)
13+
instance applicativeEff :: Applicative (Eff e)
14+
instance bindEff :: Bind (Eff e)
15+
instance monadEff :: Monad (Eff e)
16+
```
17+
18+
The `Eff` type constructor is used to represent _native_ effects.
19+
20+
See [Handling Native Effects with the Eff Monad](https://github.com/purescript/purescript/wiki/Handling-Native-Effects-with-the-Eff-Monad) for more details.
21+
22+
The first type parameter is a row of effects which represents the contexts in which a computation can be run, and the second type parameter is the return type.
23+
24+
#### `Pure`
25+
26+
``` purescript
27+
type Pure a = forall e. Eff e a
28+
```
29+
30+
The `Pure` type synonym represents _pure_ computations, i.e. ones in which all effects have been handled.
31+
32+
The `runPure` function can be used to run pure computations and obtain their result.
33+
34+
#### `runPure`
35+
36+
``` purescript
37+
runPure :: forall a. Pure a -> a
38+
```
39+
40+
Run a pure computation and return its result.
41+
42+
Note: since this function has a rank-2 type, it may cause problems to apply this function using the `$` operator. The recommended approach
43+
is to use parentheses instead.
44+
45+
#### `untilE`
46+
47+
``` purescript
48+
untilE :: forall e. Eff e Boolean -> Eff e Unit
49+
```
50+
51+
Loop until a condition becomes `true`.
52+
53+
`untilE b` is an effectful computation which repeatedly runs the effectful computation `b`,
54+
until its return value is `true`.
55+
56+
#### `whileE`
57+
58+
``` purescript
59+
whileE :: forall e a. Eff e Boolean -> Eff e a -> Eff e Unit
60+
```
61+
62+
Loop while a condition is `true`.
63+
64+
`whileE b m` is effectful computation which runs the effectful computation `b`. If its result is
65+
`true`, it runs the effectful computation `m` and loops. If not, the computation ends.
66+
67+
#### `forE`
68+
69+
``` purescript
70+
forE :: forall e. Number -> Number -> (Number -> Eff e Unit) -> Eff e Unit
71+
```
72+
73+
Loop over a consecutive collection of numbers.
74+
75+
`forE lo hi f` runs the computation returned by the function `f` for each of the inputs
76+
between `lo` (inclusive) and `hi` (exclusive).
77+
78+
#### `foreachE`
79+
80+
``` purescript
81+
foreachE :: forall e a. Array a -> (a -> Eff e Unit) -> Eff e Unit
82+
```
83+
84+
Loop over an array of values.
85+
86+
`foreach xs f` runs the computation returned by the function `f` for each of the inputs `xs`.
87+
88+

docs/Prelude.Unsafe.md

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

docs/Prelude.md

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

gulpfile.js

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@ var jscs = require("gulp-jscs");
77
var plumber = require("gulp-plumber");
88
var purescript = require("gulp-purescript");
99

10-
var paths = [
10+
var sources = [
1111
"src/**/*.purs",
1212
"bower_components/purescript-*/src/**/*.purs"
1313
];
1414

15+
var foreigns = [
16+
"src/**/*.js",
17+
"bower_components/purescript-*/src/**/*.js"
18+
];
19+
1520
gulp.task("lint", function() {
1621
return gulp.src("src/**/*.js")
1722
.pipe(jshint())
@@ -20,30 +25,24 @@ gulp.task("lint", function() {
2025
});
2126

2227
gulp.task("make", ["lint"], function() {
23-
return gulp.src(paths)
28+
return gulp.src(sources)
2429
.pipe(plumber())
25-
.pipe(purescript.pscMake());
30+
.pipe(purescript.pscMake({ ffi: foreigns }));
2631
});
2732

28-
var docTasks = [];
29-
30-
var docTask = function(name) {
31-
var taskName = "docs-" + name.toLowerCase();
32-
gulp.task(taskName, function () {
33-
return gulp.src("src/" + name.replace(/\./g, "/") + ".purs")
34-
.pipe(plumber())
35-
.pipe(purescript.pscDocs())
36-
.pipe(gulp.dest("docs/" + name + ".md"));
37-
});
38-
docTasks.push(taskName);
39-
};
40-
41-
["Control.Monad.Eff", "Control.Monad.Eff.Unsafe"].forEach(docTask);
42-
43-
gulp.task("docs", docTasks);
33+
gulp.task("docs", function () {
34+
return gulp.src(sources)
35+
.pipe(plumber())
36+
.pipe(purescript.pscDocs({
37+
docgen: {
38+
"Control.Monad.Eff": "docs/Control.Monad.Eff.md",
39+
"Control.Monad.Eff.Unsafe": "docs/Control.Monad.Eff.Unsafe.md"
40+
}
41+
}));
42+
});
4443

4544
gulp.task("dotpsci", function () {
46-
return gulp.src(paths)
45+
return gulp.src(sources)
4746
.pipe(plumber())
4847
.pipe(purescript.dotPsci());
4948
});

src/Control/Monad/Eff.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,34 @@
33

44
// module Control.Monad.Eff
55

6-
exports.returnE = function(a) {
7-
return function() {
6+
exports.returnE = function (a) {
7+
return function () {
88
return a;
99
};
1010
};
1111

12-
exports.bindE = function(a) {
13-
return function(f) {
14-
return function() {
12+
exports.bindE = function (a) {
13+
return function (f) {
14+
return function () {
1515
return f(a())();
1616
};
1717
};
1818
};
1919

20-
exports.runPure = function(f) {
20+
exports.runPure = function (f) {
2121
return f();
2222
};
2323

24-
exports.untilE = function(f) {
25-
return function() {
24+
exports.untilE = function (f) {
25+
return function () {
2626
while (!f());
2727
return {};
2828
};
2929
};
3030

31-
exports.whileE = function(f) {
32-
return function(a) {
33-
return function() {
31+
exports.whileE = function (f) {
32+
return function (a) {
33+
return function () {
3434
while (f()) {
3535
a();
3636
}
@@ -39,10 +39,10 @@ exports.whileE = function(f) {
3939
};
4040
};
4141

42-
exports.forE = function(lo) {
43-
return function(hi) {
44-
return function(f) {
45-
return function() {
42+
exports.forE = function (lo) {
43+
return function (hi) {
44+
return function (f) {
45+
return function () {
4646
for (var i = lo; i < hi; i++) {
4747
f(i)();
4848
}
@@ -51,9 +51,9 @@ exports.forE = function(lo) {
5151
};
5252
};
5353

54-
exports.foreachE = function(as) {
55-
return function(f) {
56-
return function() {
54+
exports.foreachE = function (as) {
55+
return function (f) {
56+
return function () {
5757
for (var i = 0, l = as.length; i < l; i++) {
5858
f(as[i])();
5959
}

src/Control/Monad/Eff.purs

Lines changed: 7 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,9 @@ module Control.Monad.Eff
1212
-- | The first type parameter is a row of effects which represents the contexts in which a computation can be run, and the second type parameter is the return type.
1313
foreign import data Eff :: # ! -> * -> *
1414

15-
foreign import returnE
16-
"""
17-
function returnE(a) {
18-
return function() {
19-
return a;
20-
};
21-
}
22-
""" :: forall e a. a -> Eff e a
15+
foreign import returnE :: forall e a. a -> Eff e a
2316

24-
foreign import bindE
25-
"""
26-
function bindE(a) {
27-
return function(f) {
28-
return function() {
29-
return f(a())();
30-
};
31-
};
32-
}
33-
""" :: forall e a b. Eff e a -> (a -> Eff e b) -> Eff e b
17+
foreign import bindE :: forall e a b. Eff e a -> (a -> Eff e b) -> Eff e b
3418

3519
-- | The `Pure` type synonym represents _pure_ computations, i.e. ones in which all effects have been handled.
3620
-- |
@@ -41,12 +25,7 @@ type Pure a = forall e. Eff e a
4125
-- |
4226
-- | Note: since this function has a rank-2 type, it may cause problems to apply this function using the `$` operator. The recommended approach
4327
-- | is to use parentheses instead.
44-
foreign import runPure
45-
"""
46-
function runPure(f) {
47-
return f();
48-
}
49-
""" :: forall a. Pure a -> a
28+
foreign import runPure :: forall a. Pure a -> a
5029

5130
instance functorEff :: Functor (Eff e) where
5231
map = liftA1
@@ -66,65 +45,21 @@ instance monadEff :: Monad (Eff e)
6645
-- |
6746
-- | `untilE b` is an effectful computation which repeatedly runs the effectful computation `b`,
6847
-- | until its return value is `true`.
69-
foreign import untilE
70-
"""
71-
function untilE(f) {
72-
return function() {
73-
while (!f());
74-
return {};
75-
};
76-
}
77-
""" :: forall e. Eff e Boolean -> Eff e Unit
48+
foreign import untilE :: forall e. Eff e Boolean -> Eff e Unit
7849

7950
-- | Loop while a condition is `true`.
8051
-- |
8152
-- | `whileE b m` is effectful computation which runs the effectful computation `b`. If its result is
8253
-- | `true`, it runs the effectful computation `m` and loops. If not, the computation ends.
83-
foreign import whileE
84-
"""
85-
function whileE(f) {
86-
return function(a) {
87-
return function() {
88-
while (f()) {
89-
a();
90-
}
91-
return {};
92-
};
93-
};
94-
}
95-
""" :: forall e a. Eff e Boolean -> Eff e a -> Eff e Unit
54+
foreign import whileE :: forall e a. Eff e Boolean -> Eff e a -> Eff e Unit
9655

9756
-- | Loop over a consecutive collection of numbers.
9857
-- |
9958
-- | `forE lo hi f` runs the computation returned by the function `f` for each of the inputs
10059
-- | between `lo` (inclusive) and `hi` (exclusive).
101-
foreign import forE
102-
"""
103-
function forE(lo) {
104-
return function(hi) {
105-
return function(f) {
106-
return function() {
107-
for (var i = lo; i < hi; i++) {
108-
f(i)();
109-
}
110-
};
111-
};
112-
};
113-
}
114-
""" :: forall e. Number -> Number -> (Number -> Eff e Unit) -> Eff e Unit
60+
foreign import forE :: forall e. Number -> Number -> (Number -> Eff e Unit) -> Eff e Unit
11561

11662
-- | Loop over an array of values.
11763
-- |
11864
-- | `foreach xs f` runs the computation returned by the function `f` for each of the inputs `xs`.
119-
foreign import foreachE
120-
"""
121-
function foreachE(as) {
122-
return function(f) {
123-
return function() {
124-
for (var i = 0; i < as.length; i++) {
125-
f(as[i])();
126-
}
127-
};
128-
};
129-
}
130-
""" :: forall e a. Array a -> (a -> Eff e Unit) -> Eff e Unit
65+
foreign import foreachE :: forall e a. Array a -> (a -> Eff e Unit) -> Eff e Unit

src/Control/Monad/Eff/Unsafe.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/* global exports */
22
"use strict";
33

4-
// module Control.Monad.Eff.Unsafe where
4+
// module Control.Monad.Eff.Unsafe
55

6-
exports.unsafeInterleaveEff = function(f) {
6+
exports.unsafeInterleaveEff = function (f) {
77
return f;
88
};

src/Control/Monad/Eff/Unsafe.purs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,4 @@ import Control.Monad.Eff
55
-- | Change the type of an effectful computation, allowing it to be run in another context.
66
-- |
77
-- | Note: use of this function can result in arbitrary side-effects.
8-
foreign import unsafeInterleaveEff
9-
"""
10-
function unsafeInterleaveEff(f) {
11-
return f;
12-
}
13-
""" :: forall eff1 eff2 a. Eff eff1 a -> Eff eff2 a
8+
foreign import unsafeInterleaveEff :: forall eff1 eff2 a. Eff eff1 a -> Eff eff2 a

0 commit comments

Comments
 (0)