Skip to content

Commit b5689df

Browse files
committed
Updates for RC
1 parent 08f7232 commit b5689df

File tree

14 files changed

+212
-158
lines changed

14 files changed

+212
-158
lines changed

.gitignore

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
.psci
2-
/output/
3-
/node_modules/
1+
/.*
2+
!/.gitignore
3+
!/.jscsrc
4+
!/.jshintrc
5+
!/.travis.yml
46
/bower_components/
5-
/tmp/
7+
/node_modules/
8+
/output/

.jscsrc

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

.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+
}

.travis.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ install:
88
- wget -O $HOME/purescript.tar.gz https://github.com/purescript/purescript/releases/download/$TAG/linux64.tar.gz
99
- tar -xvf $HOME/purescript.tar.gz -C $HOME/
1010
- chmod a+x $HOME/purescript
11-
- npm install bower grunt-cli -g
12-
- npm install
13-
- bower update
11+
- npm install bower gulp -g
12+
- npm install && bower install
1413
script:
15-
- grunt
14+
- gulp

Gruntfile.js

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

LICENSE-MIT renamed to LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2014 Phil Freeman
1+
Copyright (c) 2014 PureScript
22

33
Permission is hereby granted, free of charge, to any person
44
obtaining a copy of this software and associated documentation

README.md

Lines changed: 7 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,15 @@
1-
# Module Documentation
1+
# purescript-exists
22

3-
## Module Data.Exists
3+
[![Build Status](https://travis-ci.org/purescript/purescript-exists.svg?branch=master)](https://travis-ci.org/purescript/purescript-exists)
44

5-
#### `Exists`
5+
Existential types as a library.
66

7-
``` purescript
8-
data Exists :: (* -> *) -> *
9-
```
10-
11-
This type constructor can be used to existentially quantify over a type of kind `*`.
12-
13-
Specifically, the type `Exists f` is isomorphic to the existential type `exists a. f a`.
14-
15-
Existential types can be encoded using universal types (`forall`) for endofunctors in more general
16-
categories. The benefit of this library is that, by using the FFI, we can create an efficient
17-
representation of the existential by simply hiding type information.
18-
19-
For example, consider the type `exists s. Tuple s (s -> Tuple s a)` which represents infinite streams
20-
of elements of type `a`.
7+
## Installation
218

22-
This type can be constructed by creating a type constructor `StreamF` as follows:
23-
24-
```purescript
25-
data StreamF a s = StreamF s (s -> Tuple s a)
269
```
27-
28-
We can then define the type of streams using `Exists`:
29-
30-
```purescript
31-
type Stream a = Exists (StreamF a)
10+
bower install purescript-exists
3211
```
3312

34-
#### `mkExists`
35-
36-
``` purescript
37-
mkExists :: forall f a. f a -> Exists f
38-
```
39-
40-
The `mkExists` function is used to introduce a value of type `Exists f`, by providing a value of
41-
type `f a`, for some type `a` which will be hidden in the existentially-quantified type.
42-
43-
For example, to create a value of type `Stream Number`, we might use `mkExists` as follows:
44-
45-
```purescript
46-
nats :: Stream Number
47-
nats = mkExists $ StreamF 0 (\n -> Tuple (n + 1) n)
48-
```
49-
50-
#### `runExists`
51-
52-
``` purescript
53-
runExists :: forall f r. (forall a. f a -> r) -> Exists f -> r
54-
```
55-
56-
The `runExists` function is used to eliminate a value of type `Exists f`. The rank 2 type ensures
57-
that the existentially-quantified type does not escape its scope. Since the function is required
58-
to work for _any_ type `a`, it will work for the existentially-quantified type.
59-
60-
For example, we can write a function to obtain the head of a stream by using `runExists` as follows:
13+
## Module documentation
6114

62-
```purescript
63-
head :: forall a. Stream a -> a
64-
head = runExists head'
65-
where
66-
head' :: forall s. StreamF a s -> a
67-
head' (StreamF s f) = snd (f s)
68-
```
15+
- [Data.Exists](docs/Data.Exists.md)

bower.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,22 @@
22
"name": "purescript-exists",
33
"description": "Existential types as a library",
44
"keywords": ["purescript"],
5+
"license": "MIT",
6+
"repository": {
7+
"type": "git",
8+
"url": "git://github.com/purescript/purescript-exists.git"
9+
},
510
"ignore": [
611
"**/.*",
712
"bower_components",
813
"node_modules",
914
"output",
10-
"tests",
11-
"output",
12-
"js",
13-
"tmp",
15+
"test",
1416
"bower.json",
15-
"Gruntfile.js",
17+
"gulpfile.js",
1618
"package.json"
1719
],
1820
"devDependencies": {
19-
"purescript-console": "~0.1.0"
21+
"purescript-console": "^0.1.0"
2022
}
2123
}

docs/Data.Exists.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
## Module Data.Exists
2+
3+
#### `Exists`
4+
5+
``` purescript
6+
data Exists :: (* -> *) -> *
7+
```
8+
9+
This type constructor can be used to existentially quantify over a type of kind `*`.
10+
11+
Specifically, the type `Exists f` is isomorphic to the existential type `exists a. f a`.
12+
13+
Existential types can be encoded using universal types (`forall`) for endofunctors in more general
14+
categories. The benefit of this library is that, by using the FFI, we can create an efficient
15+
representation of the existential by simply hiding type information.
16+
17+
For example, consider the type `exists s. Tuple s (s -> Tuple s a)` which represents infinite streams
18+
of elements of type `a`.
19+
20+
This type can be constructed by creating a type constructor `StreamF` as follows:
21+
22+
```purescript
23+
data StreamF a s = StreamF s (s -> Tuple s a)
24+
```
25+
26+
We can then define the type of streams using `Exists`:
27+
28+
```purescript
29+
type Stream a = Exists (StreamF a)
30+
```
31+
32+
#### `mkExists`
33+
34+
``` purescript
35+
mkExists :: forall f a. f a -> Exists f
36+
```
37+
38+
The `mkExists` function is used to introduce a value of type `Exists f`, by providing a value of
39+
type `f a`, for some type `a` which will be hidden in the existentially-quantified type.
40+
41+
For example, to create a value of type `Stream Number`, we might use `mkExists` as follows:
42+
43+
```purescript
44+
nats :: Stream Number
45+
nats = mkExists $ StreamF 0 (\n -> Tuple (n + 1) n)
46+
```
47+
48+
#### `runExists`
49+
50+
``` purescript
51+
runExists :: forall f r. (forall a. f a -> r) -> Exists f -> r
52+
```
53+
54+
The `runExists` function is used to eliminate a value of type `Exists f`. The rank 2 type ensures
55+
that the existentially-quantified type does not escape its scope. Since the function is required
56+
to work for _any_ type `a`, it will work for the existentially-quantified type.
57+
58+
For example, we can write a function to obtain the head of a stream by using `runExists` as follows:
59+
60+
```purescript
61+
head :: forall a. Stream a -> a
62+
head = runExists head'
63+
where
64+
head' :: forall s. StreamF a s -> a
65+
head' (StreamF s f) = snd (f s)
66+
```
67+
68+

gulpfile.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/* jshint node: true */
2+
"use strict";
3+
4+
var gulp = require("gulp");
5+
var jshint = require("gulp-jshint");
6+
var jscs = require("gulp-jscs");
7+
var plumber = require("gulp-plumber");
8+
var purescript = require("gulp-purescript");
9+
var rimraf = require("rimraf");
10+
var run = require("gulp-run");
11+
12+
var sources = [
13+
"src/**/*.purs",
14+
"bower_components/purescript-*/src/**/*.purs"
15+
];
16+
17+
var foreigns = [
18+
"src/**/*.js",
19+
"bower_components/purescript-*/src/**/*.js"
20+
];
21+
22+
gulp.task("clean-docs", function (cb) {
23+
rimraf("docs", cb);
24+
});
25+
26+
gulp.task("clean-output", function (cb) {
27+
rimraf("output", cb);
28+
});
29+
30+
gulp.task("clean", ["clean-docs", "clean-output"]);
31+
32+
gulp.task("lint", function() {
33+
return gulp.src("src/**/*.js")
34+
.pipe(jshint())
35+
.pipe(jshint.reporter())
36+
.pipe(jscs());
37+
});
38+
39+
gulp.task("make", ["lint"], function() {
40+
return gulp.src(sources)
41+
.pipe(plumber())
42+
.pipe(purescript.pscMake({ ffi: foreigns }));
43+
});
44+
45+
gulp.task("docs", ["clean-docs"], function () {
46+
return gulp.src(sources)
47+
.pipe(plumber())
48+
.pipe(purescript.pscDocs({
49+
docgen: {
50+
"Data.Exists": "docs/Data.Exists.md"
51+
}
52+
}));
53+
});
54+
55+
gulp.task("dotpsci", function () {
56+
return gulp.src(sources)
57+
.pipe(plumber())
58+
.pipe(purescript.dotPsci());
59+
});
60+
61+
gulp.task("test", ["make"], function() {
62+
return gulp.src(sources.concat(["test/**/*.purs"]))
63+
.pipe(plumber())
64+
.pipe(purescript.psc({ main: "Test.Main", ffi: foreigns }))
65+
.pipe(run("node"));
66+
});
67+
68+
gulp.task("default", ["make", "docs", "dotpsci", "test"]);

js/index.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

package.json

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
{
2-
"name": "purescript-exists",
3-
"version": "0.1.0",
4-
"description": "Existential types as a library",
5-
"main": "",
62
"private": true,
7-
"author": "Phil Freeman",
8-
"license": "MIT",
9-
"dependencies": {
10-
"grunt": "~0.4.4",
11-
"grunt-contrib-copy": "~0.5.0",
12-
"grunt-contrib-clean": "~0.5.0",
13-
"grunt-execute": "~0.1.5",
14-
"grunt-purescript": "~0.6.0"
3+
"devDependencies": {
4+
"gulp": "^3.8.11",
5+
"gulp-jscs": "^1.6.0",
6+
"gulp-jshint": "^1.10.0",
7+
"gulp-plumber": "^1.0.0",
8+
"gulp-purescript": "^0.5.0-rc.1",
9+
"gulp-run": "^1.6.8",
10+
"rimraf": "^2.3.3"
1511
}
1612
}

0 commit comments

Comments
 (0)