Skip to content

Commit 6f483e4

Browse files
committed
Merge pull request #19 from purescript/foreign-updates
Updates for external foreign definitions
2 parents bb50cf5 + d07caf1 commit 6f483e4

File tree

10 files changed

+313
-287
lines changed

10 files changed

+313
-287
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/.*
22
!/.gitignore
3+
!/.jscsrc
4+
!/.jshintrc
35
!/.travis.yml
46
/bower_components/
57
/node_modules/

.jscsrc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"preset": "grunt",
3+
"disallowSpacesInAnonymousFunctionExpression": null,
4+
"requireSpacesInAnonymousFunctionExpression": {
5+
"beforeOpeningRoundBrace": true,
6+
"beforeOpeningCurlyBrace": true
7+
},
8+
"validateQuoteMarks": "\"",
9+
"requireCurlyBraces": null
10+
}

.jshintrc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"bitwise": true,
3+
"eqeqeq": true,
4+
"forin": true,
5+
"freeze": true,
6+
"funcscope": true,
7+
"futurehostile": true,
8+
"globalstrict": true,
9+
"latedef": true,
10+
"maxparams": 1,
11+
"noarg": true,
12+
"nocomma": true,
13+
"nonew": true,
14+
"notypeof": true,
15+
"singleGroups": true,
16+
"undef": true,
17+
"unused": true,
18+
"eqnull": true
19+
}

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,3 @@ bower install purescript-prelude
1313
## Module documentation
1414

1515
- [Prelude](docs/Prelude.md)
16-
- [Prelude.Unsafe](docs/Prelude.Unsafe.md)

docs/Prelude.Unsafe.md

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

docs/Prelude.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,13 +613,15 @@ instance semiringUnit :: Semiring Unit
613613
(+) :: forall a. (Semiring a) => a -> a -> a
614614
```
615615

616+
`(+)` is an alias for `add`.
616617

617618
#### `(*)`
618619

619620
``` purescript
620621
(*) :: forall a. (Semiring a) => a -> a -> a
621622
```
622623

624+
`(*)` is an alias for `mul`.
623625

624626
#### `Ring`
625627

@@ -663,6 +665,7 @@ instance ringUnit :: Ring Unit
663665
(-) :: forall a. (Ring a) => a -> a -> a
664666
```
665667

668+
`(-)` is an alias for `sub`.
666669

667670
#### `negate`
668671

@@ -714,6 +717,7 @@ instance moduloSemiringUnit :: ModuloSemiring Unit
714717
(/) :: forall a. (ModuloSemiring a) => a -> a -> a
715718
```
716719

720+
`(/)` is an alias for `div`.
717721

718722
#### `DivisionRing`
719723

@@ -786,14 +790,14 @@ The `Eq` type class represents types which support decidable equality.
786790
- Reflexivity: `x == x = true`
787791
- Symmetry: `x == y = y == x`
788792
- Transitivity: if `x == y` and `y == z` then `x == z`
789-
- Negation: `x /= y = not (x == y)`
790793

791794
#### `(==)`
792795

793796
``` purescript
794797
(==) :: forall a. (Eq a) => a -> a -> Boolean
795798
```
796799

800+
`(==)` is an alias for `eq`.
797801

798802
#### `(/=)`
799803

gulpfile.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
1+
/* jshint node: true */
12
"use strict";
23

34
var gulp = require("gulp");
5+
var jshint = require("gulp-jshint");
6+
var jscs = require("gulp-jscs");
47
var plumber = require("gulp-plumber");
58
var purescript = require("gulp-purescript");
6-
var jsvalidate = require("gulp-jsvalidate");
7-
var run = require('gulp-run');
9+
var run = require("gulp-run");
810

911
var paths = [
1012
"src/**/*.purs",
1113
"bower_components/purescript-*/src/**/*.purs"
1214
];
1315

14-
gulp.task("make", function() {
15-
return gulp.src(paths)
16-
.pipe(plumber())
17-
.pipe(purescript.pscMake());
16+
gulp.task("lint", function() {
17+
return gulp.src("src/**/*.js")
18+
.pipe(jshint())
19+
.pipe(jshint.reporter())
20+
.pipe(jscs());
1821
});
1922

20-
gulp.task("jsvalidate", ["make"], function () {
21-
return gulp.src("output/**/*.js")
23+
gulp.task("make", ["lint"], function() {
24+
return gulp.src(paths)
2225
.pipe(plumber())
23-
.pipe(jsvalidate());
26+
.pipe(purescript.pscMake());
2427
});
2528

2629
var docTasks = [];
@@ -36,7 +39,7 @@ var docTask = function(name) {
3639
docTasks.push(taskName);
3740
};
3841

39-
["Prelude", "Prelude.Unsafe"].forEach(docTask);
42+
["Prelude"].forEach(docTask);
4043

4144
gulp.task("docs", docTasks);
4245

@@ -47,10 +50,10 @@ gulp.task("dotpsci", function () {
4750
});
4851

4952
gulp.task("test", function() {
50-
return gulp.src(paths.concat(['test/Main.purs']))
53+
return gulp.src(paths.concat(["test/Main.purs"]))
5154
.pipe(plumber())
5255
.pipe(purescript.psc({ main: "Test.Main" }))
5356
.pipe(run("node"));
54-
})
57+
});
5558

56-
gulp.task("default", ["jsvalidate", "docs", "dotpsci"]);
59+
gulp.task("default", ["make", "docs", "dotpsci"]);

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
"private": true,
33
"devDependencies": {
44
"gulp": "^3.8.11",
5-
"gulp-jsvalidate": "^1.0.1",
5+
"gulp-jscs": "^1.6.0",
6+
"gulp-jshint": "^1.10.0",
67
"gulp-plumber": "^1.0.0",
78
"gulp-purescript": "^0.3.1",
89
"gulp-run": "~1.6.7"

src/Prelude.js

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
/* global exports */
2+
"use strict";
3+
4+
// module Prelude
5+
6+
//- Functor --------------------------------------------------------------------
7+
8+
exports.arrayMap = function (f) {
9+
return function (arr) {
10+
var l = arr.length;
11+
var result = new Array(l);
12+
for (var i = 0; i < l; i++) {
13+
result[i] = f(arr[i]);
14+
}
15+
return result;
16+
};
17+
};
18+
19+
//- Bind -----------------------------------------------------------------------
20+
21+
exports.arrayBind = function (arr) {
22+
return function (f) {
23+
var result = [];
24+
for (var i = 0, l = arr.length; i < l; i++) {
25+
Array.prototype.push.apply(result, f(arr[i]));
26+
}
27+
return result;
28+
};
29+
};
30+
31+
//- Monoid ---------------------------------------------------------------------
32+
33+
exports.concatString = function (s1) {
34+
return function (s2) {
35+
return s1 + s2;
36+
};
37+
};
38+
39+
exports.concatArray = function (xs) {
40+
return function (ys) {
41+
return xs.concat(ys);
42+
};
43+
};
44+
45+
//- Semiring -------------------------------------------------------------------
46+
47+
exports.intAdd = function (x) {
48+
return function (y) {
49+
/* jshint bitwise: false */
50+
return x + y | 0;
51+
};
52+
};
53+
54+
exports.intMul = function (x) {
55+
return function (y) {
56+
/* jshint bitwise: false */
57+
return x * y | 0;
58+
};
59+
};
60+
61+
exports.numAdd = function (n1) {
62+
return function (n2) {
63+
return n1 + n2;
64+
};
65+
};
66+
67+
exports.numMul = function (n1) {
68+
return function (n2) {
69+
return n1 * n2;
70+
};
71+
};
72+
73+
//- ModuloSemiring -------------------------------------------------------------
74+
75+
exports.intDiv = function (x) {
76+
return function (y) {
77+
/* jshint bitwise: false */
78+
return x / y | 0;
79+
};
80+
};
81+
82+
exports.intMod = function (x) {
83+
return function (y) {
84+
return x % y;
85+
};
86+
};
87+
88+
exports.numDiv = function (n1) {
89+
return function (n2) {
90+
return n1 / n2;
91+
};
92+
};
93+
94+
//- Ring -----------------------------------------------------------------------
95+
96+
exports.intSub = function (x) {
97+
return function (y) {
98+
/* jshint bitwise: false */
99+
return x - y | 0;
100+
};
101+
};
102+
103+
exports.numSub = function (n1) {
104+
return function (n2) {
105+
return n1 - n2;
106+
};
107+
};
108+
109+
//- Eq -------------------------------------------------------------------------
110+
111+
exports.refEq = function (r1) {
112+
return function (r2) {
113+
return r1 === r2;
114+
};
115+
};
116+
117+
exports.refIneq = function (r1) {
118+
return function (r2) {
119+
return r1 !== r2;
120+
};
121+
};
122+
123+
exports.eqArrayImpl = function (f) {
124+
return function (xs) {
125+
return function (ys) {
126+
if (xs.length !== ys.length) return false;
127+
for (var i = 0; i < xs.length; i++) {
128+
if (!f(xs[i])(ys[i])) return false;
129+
}
130+
return true;
131+
};
132+
};
133+
};
134+
135+
exports.ordArrayImpl = function (f) {
136+
return function (xs) {
137+
return function (ys) {
138+
var i = 0;
139+
var xlen = xs.length;
140+
var ylen = ys.length;
141+
while (i < xlen && i < ylen) {
142+
var x = xs[i];
143+
var y = ys[i];
144+
var o = f(x)(y);
145+
if (o !== 0) {
146+
return o;
147+
}
148+
i++;
149+
}
150+
if (xlen === ylen) {
151+
return 0;
152+
} else if (xlen > ylen) {
153+
return -1;
154+
} else {
155+
return 1;
156+
}
157+
};
158+
};
159+
};
160+
161+
//- Ord ------------------------------------------------------------------------
162+
163+
exports.unsafeCompareImpl = function (lt) {
164+
return function (eq) {
165+
return function (gt) {
166+
return function (x) {
167+
return function (y) {
168+
return x < y ? lt : x > y ? gt : eq;
169+
};
170+
};
171+
};
172+
};
173+
};
174+
175+
//- Lattice --------------------------------------------------------------------
176+
177+
exports.boolOr = function (b1) {
178+
return function (b2) {
179+
return b1 || b2;
180+
};
181+
};
182+
183+
exports.boolAnd = function (b1) {
184+
return function (b2) {
185+
return b1 && b2;
186+
};
187+
};
188+
189+
//- ComplementedLattice --------------------------------------------------------
190+
191+
exports.boolNot = function (b) {
192+
return !b;
193+
};
194+
195+
//- Show -----------------------------------------------------------------------
196+
197+
exports.showIntImpl = function (n) {
198+
return n.toString();
199+
};
200+
201+
exports.showNumberImpl = function (n) {
202+
/* jshint bitwise: false */
203+
return n === (n | 0) ? n + ".0" : n.toString();
204+
};
205+
206+
exports.showCharImpl = function (c) {
207+
return c === "'" ? "'\\''" : "'" + c + "'";
208+
};
209+
210+
exports.showStringImpl = function (s) {
211+
return JSON.stringify(s);
212+
};
213+
214+
exports.showArrayImpl = function (f) {
215+
return function (xs) {
216+
var ss = [];
217+
for (var i = 0, l = xs.length; i < l; i++) {
218+
ss[i] = f(xs[i]);
219+
}
220+
return "[" + ss.join(",") + "]";
221+
};
222+
};

0 commit comments

Comments
 (0)