Skip to content

Commit 4a64b5a

Browse files
authored
Merge pull request #20 from purescript/compiler/0.12
Update for PureScript 0.12
2 parents ac3a983 + 632113a commit 4a64b5a

File tree

11 files changed

+262
-120
lines changed

11 files changed

+262
-120
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
/bower_components/
66
/node_modules/
77
/output/
8+
package-lock.json

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ install:
1111
- chmod a+x $HOME/purescript
1212
- npm install -g bower
1313
- npm install
14-
- bower install
14+
- bower install --production
1515
script:
1616
- npm run -s build
17+
- bower install
18+
- npm run -s test
1719
after_success:
1820
- >-
1921
test $TRAVIS_TAG &&

LICENSE

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
1-
The MIT License (MIT)
1+
Copyright 2018 PureScript
22

3-
Copyright (c) 2015 PureScript
3+
Redistribution and use in source and binary forms, with or without modification,
4+
are permitted provided that the following conditions are met:
45

5-
Permission is hereby granted, free of charge, to any person obtaining a copy of
6-
this software and associated documentation files (the "Software"), to deal in
7-
the Software without restriction, including without limitation the rights to
8-
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9-
the Software, and to permit persons to whom the Software is furnished to do so,
10-
subject to the following conditions:
6+
1. Redistributions of source code must retain the above copyright notice, this
7+
list of conditions and the following disclaimer.
118

12-
The above copyright notice and this permission notice shall be included in all
13-
copies or substantial portions of the Software.
9+
2. Redistributions in binary form must reproduce the above copyright notice,
10+
this list of conditions and the following disclaimer in the documentation and/or
11+
other materials provided with the distribution.
1412

15-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17-
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18-
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19-
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20-
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13+
3. Neither the name of the copyright holder nor the names of its contributors
14+
may be used to endorse or promote products derived from this software without
15+
specific prior written permission.
16+
17+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
21+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

bower.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "purescript-st",
33
"homepage": "https://github.com/purescript/purescript-st",
44
"description": "The ST effect, for safe local mutation",
5-
"license": "MIT",
5+
"license": "BSD-3-Clause",
66
"repository": {
77
"type": "git",
88
"url": "git://github.com/purescript/purescript-st.git"
@@ -17,6 +17,11 @@
1717
"package.json"
1818
],
1919
"dependencies": {
20-
"purescript-eff": "^3.0.0"
20+
"purescript-prelude": "^4.0.0",
21+
"purescript-tailrec": "^4.0.0",
22+
"purescript-partial": "^2.0.0"
23+
},
24+
"devDependencies": {
25+
"purescript-console": "^4.0.0"
2126
}
2227
}

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
"private": true,
33
"scripts": {
44
"clean": "rimraf output && rimraf .pulp-cache",
5-
"build": "eslint src && pulp build -- --censor-lib --strict"
5+
"build": "eslint src && pulp build -- --censor-lib --strict",
6+
"test": "pulp test"
67
},
78
"devDependencies": {
8-
"eslint": "^4.9.0",
9-
"pulp": "^12.0.1",
10-
"purescript": "^0.11.6",
11-
"purescript-psa": "^0.5.1",
9+
"eslint": "^4.19.1",
10+
"pulp": "^12.2.0",
11+
"purescript-psa": "^0.6.0",
1212
"rimraf": "^2.6.2"
1313
}
1414
}

src/Control/Monad/ST.js

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

src/Control/Monad/ST.purs

Lines changed: 2 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,3 @@
1-
module Control.Monad.ST where
1+
module Control.Monad.ST (module Internal) where
22

3-
import Control.Monad.Eff (Eff, kind Effect, runPure)
4-
5-
-- | The `ST` effect represents _local mutation_, i.e. mutation which does not
6-
-- | "escape" into the surrounding computation.
7-
-- |
8-
-- | An `ST` computation is parameterized by a phantom type which is used to
9-
-- | restrict the set of reference cells it is allowed to access.
10-
-- |
11-
-- | The `runST` function can be used to handle the `ST` effect.
12-
foreign import data ST :: Type -> Effect
13-
14-
-- | The type `STRef h a` represents a mutable reference holding a value of
15-
-- | type `a`, which can be used with the `ST h` effect.
16-
foreign import data STRef :: Type -> Type -> Type
17-
18-
-- | Create a new mutable reference.
19-
foreign import newSTRef
20-
:: forall a h r
21-
. a
22-
-> Eff (st :: ST h | r) (STRef h a)
23-
24-
-- | Read the current value of a mutable reference.
25-
foreign import readSTRef
26-
:: forall a h r
27-
. STRef h a
28-
-> Eff (st :: ST h | r) a
29-
30-
-- | Modify the value of a mutable reference by applying a function to the
31-
-- | current value.
32-
foreign import modifySTRef
33-
:: forall a h r
34-
. STRef h a -> (a -> a)
35-
-> Eff (st :: ST h | r) a
36-
37-
-- | Set the value of a mutable reference.
38-
foreign import writeSTRef
39-
:: forall a h r
40-
. STRef h a
41-
-> a
42-
-> Eff (st :: ST h | r) a
43-
44-
-- | Run an `ST` computation.
45-
-- |
46-
-- | Note: the type of `runST` uses a rank-2 type to constrain the phantom
47-
-- | type `h`, such that the computation must not leak any mutable references
48-
-- | to the surrounding computation.
49-
-- |
50-
-- | It may cause problems to apply this function using the `$` operator. The
51-
-- | recommended approach is to use parentheses instead.
52-
foreign import runST
53-
:: forall a r
54-
. (forall h. Eff (st :: ST h | r) a)
55-
-> Eff r a
56-
57-
-- | A convenience function which combines `runST` with `runPure`, which can be
58-
-- | used when the only required effect is `ST`.
59-
-- |
60-
-- | Note: since this function has a rank-2 type, it may cause problems to apply
61-
-- | this function using the `$` operator. The recommended approach is to use
62-
-- | parentheses instead.
63-
pureST :: forall a. (forall h. Eff (st :: ST h) a) -> a
64-
pureST st = runPure (runST st)
3+
import Control.Monad.ST.Internal (ST, kind Region, run, while, for, foreach) as Internal

src/Control/Monad/ST/Internal.js

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
"use strict";
2+
3+
exports.map_ = function (f) {
4+
return function (a) {
5+
return function () {
6+
return f(a());
7+
};
8+
};
9+
};
10+
11+
exports.pure_ = function (a) {
12+
return function () {
13+
return a;
14+
};
15+
};
16+
17+
exports.bind_ = function (a) {
18+
return function (f) {
19+
return function () {
20+
return f(a())();
21+
};
22+
};
23+
};
24+
25+
exports.run = function (f) {
26+
return f();
27+
};
28+
29+
exports["while"] = function (f) {
30+
return function (a) {
31+
return function () {
32+
while (f()) {
33+
a();
34+
}
35+
};
36+
};
37+
};
38+
39+
exports["for"] = function (lo) {
40+
return function (hi) {
41+
return function (f) {
42+
return function () {
43+
for (var i = lo; i < hi; i++) {
44+
f(i)();
45+
}
46+
};
47+
};
48+
};
49+
};
50+
51+
exports.foreach = function (as) {
52+
return function (f) {
53+
return function () {
54+
for (var i = 0, l = as.length; i < l; i++) {
55+
f(as[i])();
56+
}
57+
};
58+
};
59+
};
60+
61+
exports.new = function (val) {
62+
return function () {
63+
return { value: val };
64+
};
65+
};
66+
67+
exports.read = function (ref) {
68+
return function () {
69+
return ref.value;
70+
};
71+
};
72+
73+
exports["modify'"] = function (f) {
74+
return function (ref) {
75+
return function () {
76+
var t = f(ref.value);
77+
ref.value = t.state;
78+
return t.value;
79+
};
80+
};
81+
};
82+
83+
exports.write = function (a) {
84+
return function (ref) {
85+
return function () {
86+
return ref.value = a; // eslint-disable-line no-return-assign
87+
};
88+
};
89+
};

0 commit comments

Comments
 (0)