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

Commit 5572418

Browse files
committed
Initial commit
0 parents  commit 5572418

File tree

6 files changed

+164
-0
lines changed

6 files changed

+164
-0
lines changed

.gitignore

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

README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Module Documentation
2+
3+
## Module Type.Proxy
4+
5+
6+
The `Proxy` type and values are for situations where type information is
7+
required for an input to determine the type of an output, but where it is
8+
not possible or convenient to provide a _value_ for the input.
9+
10+
A hypothetical example: if you have a class that is used to handle the
11+
result of an AJAX request, you may want to use this information to set the
12+
expected content type of the request, so you might have a class something
13+
like this:
14+
15+
``` purescript
16+
class AjaxResponse a where
17+
responseType :: a -> ResponseType
18+
fromResponse :: Foreign -> a
19+
```
20+
21+
The problem here is `responseType` requires a value of type `a`, but we
22+
won't have a value of that type until the request has been completed. The
23+
solution is to use a `Proxy` type instead:
24+
25+
``` purescript
26+
class AjaxResponse a where
27+
responseType :: Proxy a -> ResponseType
28+
fromResponse :: Foreign -> a
29+
```
30+
31+
We can now call `responseType (Proxy :: Proxy SomeContentType)` to produce
32+
a `ResponseType` for `SomeContentType` without having to construct some
33+
empty version of `SomeContentType` first.
34+
35+
#### `Proxy`
36+
37+
``` purescript
38+
data Proxy a
39+
= Proxy
40+
```
41+
42+
Value proxy for kind `*` types.
43+
44+
#### `Proxy2`
45+
46+
``` purescript
47+
data Proxy2 (a :: * -> *)
48+
= Proxy2
49+
```
50+
51+
Value proxy for kind `* -> *` types.
52+
53+
#### `Proxy3`
54+
55+
``` purescript
56+
data Proxy3 (a :: * -> * -> *)
57+
= Proxy3
58+
```
59+
60+
Value proxy for kind `* -> * -> *` types.
61+
62+
63+

bower.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "purescript-proxy",
3+
"homepage": "https://github.com/purescript/purescript-proxy",
4+
"description": "Value proxy for type inputs",
5+
"keywords": [
6+
"purescript"
7+
],
8+
"license": "MIT",
9+
"ignore": [
10+
"**/.*",
11+
"bower_components",
12+
"node_modules",
13+
"output",
14+
"test",
15+
"tmp",
16+
"bower.json",
17+
"gulpfile.js",
18+
"package.json"
19+
]
20+
}

gulpfile.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
gulp.task("make", function() {
9+
return gulp.src(["src/**/*.purs", "bower_components/purescript-*/src/**/*.purs"])
10+
.pipe(plumber())
11+
.pipe(purescript.pscMake());
12+
});
13+
14+
gulp.task("jsvalidate", ["make"], function () {
15+
return gulp.src("output/**/*.js")
16+
.pipe(plumber())
17+
.pipe(jsvalidate());
18+
});
19+
20+
gulp.task("docs", function () {
21+
return gulp.src("src/**/*.purs")
22+
.pipe(plumber())
23+
.pipe(purescript.pscDocs())
24+
.pipe(gulp.dest("README.md"));
25+
});
26+
27+
gulp.task("default", ["jsvalidate", "docs"]);

package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"private": true,
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"
8+
}
9+
}

src/Type/Proxy.purs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
-- | The `Proxy` type and values are for situations where type information is
2+
-- | required for an input to determine the type of an output, but where it is
3+
-- | not possible or convenient to provide a _value_ for the input.
4+
-- |
5+
-- | A hypothetical example: if you have a class that is used to handle the
6+
-- | result of an AJAX request, you may want to use this information to set the
7+
-- | expected content type of the request, so you might have a class something
8+
-- | like this:
9+
-- |
10+
-- | ``` purescript
11+
-- | class AjaxResponse a where
12+
-- | responseType :: a -> ResponseType
13+
-- | fromResponse :: Foreign -> a
14+
-- | ```
15+
-- |
16+
-- | The problem here is `responseType` requires a value of type `a`, but we
17+
-- | won't have a value of that type until the request has been completed. The
18+
-- | solution is to use a `Proxy` type instead:
19+
-- |
20+
-- | ``` purescript
21+
-- | class AjaxResponse a where
22+
-- | responseType :: Proxy a -> ResponseType
23+
-- | fromResponse :: Foreign -> a
24+
-- | ```
25+
-- |
26+
-- | We can now call `responseType (Proxy :: Proxy SomeContentType)` to produce
27+
-- | a `ResponseType` for `SomeContentType` without having to construct some
28+
-- | empty version of `SomeContentType` first.
29+
module Type.Proxy where
30+
31+
-- | Value proxy for kind `*` types.
32+
data Proxy a = Proxy
33+
34+
-- | Value proxy for kind `* -> *` types.
35+
data Proxy2 (a :: * -> *) = Proxy2
36+
37+
-- | Value proxy for kind `* -> * -> *` types.
38+
data Proxy3 (a :: * -> * -> *) = Proxy3

0 commit comments

Comments
 (0)