diff --git a/.gitignore b/.gitignore index 2836c9a..e306283 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,8 @@ /.* !/.gitignore +!/.jscsrc +!/.jshintrc !/.travis.yml /bower_components/ /node_modules/ /output/ -/tmp/ diff --git a/.jscsrc b/.jscsrc new file mode 100644 index 0000000..342da66 --- /dev/null +++ b/.jscsrc @@ -0,0 +1,12 @@ +{ + "preset": "grunt", + "disallowSpacesInAnonymousFunctionExpression": null, + "requireSpacesInAnonymousFunctionExpression": { + "beforeOpeningRoundBrace": true, + "beforeOpeningCurlyBrace": true + }, + "disallowSpacesInsideObjectBrackets": null, + "requireSpacesInsideObjectBrackets": "all", + "validateQuoteMarks": "\"", + "requireCurlyBraces": null +} diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000..f391159 --- /dev/null +++ b/.jshintrc @@ -0,0 +1,19 @@ +{ + "bitwise": true, + "eqeqeq": true, + "forin": true, + "freeze": true, + "funcscope": true, + "futurehostile": true, + "globalstrict": true, + "latedef": true, + "maxparams": 1, + "noarg": true, + "nocomma": true, + "nonew": true, + "notypeof": true, + "singleGroups": true, + "undef": true, + "unused": true, + "eqnull": true +} diff --git a/bower.json b/bower.json index 228a950..5ab3763 100644 --- a/bower.json +++ b/bower.json @@ -1,18 +1,27 @@ { - "name": "purescript-semirings", - "moduleType": [ - "node" + "name": "purescript-refs", + "homepage": "https://github.com/purescript/purescript-refs", + "description": "Mutable value references", + "keywords": [ + "purescript" ], + "license": "MIT", + "repository": { + "type": "git", + "url": "git://github.com/purescript/purescript-refs.git" + }, "ignore": [ "**/.*", - "node_modules", "bower_components", + "node_modules", "output", + "test", "bower.json", "gulpfile.js", "package.json" ], "dependencies": { - "purescript-eff": "~0.1.0" + "purescript-eff": "^0.1.0", + "purescript-prelude": "^0.1.0" } } diff --git a/docs/Control.Monad.Eff.Ref.Unsafe.md b/docs/Control.Monad.Eff.Ref.Unsafe.md new file mode 100644 index 0000000..cafdc3c --- /dev/null +++ b/docs/Control.Monad.Eff.Ref.Unsafe.md @@ -0,0 +1,18 @@ +## Module Control.Monad.Eff.Ref.Unsafe + +Unsafe functions for working with mutable references. + +#### `unsafeRunRef` + +``` purescript +unsafeRunRef :: forall eff a. Eff (ref :: REF | eff) a -> Eff eff a +``` + +This handler function unsafely removes the `Ref` effect from an +effectful action. + +This function might be used when it is impossible to prove to the +typechecker that a particular mutable reference does not escape +its scope. + + diff --git a/docs/Control.Monad.Eff.Ref.md b/docs/Control.Monad.Eff.Ref.md index ccb624e..bf73222 100644 --- a/docs/Control.Monad.Eff.Ref.md +++ b/docs/Control.Monad.Eff.Ref.md @@ -1,8 +1,5 @@ -# Module Documentation - ## Module Control.Monad.Eff.Ref - This module defines an effect and actions for working with global mutable variables. @@ -46,7 +43,7 @@ Read the current value of a mutable reference #### `modifyRef'` ``` purescript -modifyRef' :: forall s b r. Ref s -> (s -> { value :: b, state :: s }) -> Eff (ref :: REF | r) b +modifyRef' :: forall s b r. Ref s -> (s -> { state :: s, value :: b }) -> Eff (ref :: REF | r) b ``` Update the value of a mutable reference by applying a function @@ -70,4 +67,3 @@ writeRef :: forall s r. Ref s -> s -> Eff (ref :: REF | r) Unit Update the value of a mutable reference to the specified value. - diff --git a/docs/Control.Monad.Eff.Unsafe.md b/docs/Control.Monad.Eff.Unsafe.md deleted file mode 100644 index 4c9fa37..0000000 --- a/docs/Control.Monad.Eff.Unsafe.md +++ /dev/null @@ -1,3 +0,0 @@ -# Module Documentation - - diff --git a/gulpfile.js b/gulpfile.js index f08e27b..be3696d 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,48 +1,61 @@ +/* jshint node: true */ "use strict"; var gulp = require("gulp"); +var jshint = require("gulp-jshint"); +var jscs = require("gulp-jscs"); var plumber = require("gulp-plumber"); var purescript = require("gulp-purescript"); -var jsvalidate = require("gulp-jsvalidate"); +var rimraf = require("rimraf"); -var paths = [ +var sources = [ "src/**/*.purs", "bower_components/purescript-*/src/**/*.purs" ]; -gulp.task("make", function() { - return gulp.src(paths) - .pipe(plumber()) - .pipe(purescript.pscMake()); +var foreigns = [ + "src/**/*.js", + "bower_components/purescript-*/src/**/*.js" +]; + +gulp.task("clean-docs", function (cb) { + rimraf("docs", cb); }); -gulp.task("jsvalidate", ["make"], function () { - return gulp.src("output/**/*.js") - .pipe(plumber()) - .pipe(jsvalidate()); +gulp.task("clean-output", function (cb) { + rimraf("output", cb); }); -var docTasks = []; +gulp.task("clean", ["clean-docs", "clean-output"]); -var docTask = function(name) { - var taskName = "docs-" + name.toLowerCase(); - gulp.task(taskName, function () { - return gulp.src("src/" + name.replace(/\./g, "/") + ".purs") - .pipe(plumber()) - .pipe(purescript.pscDocs()) - .pipe(gulp.dest("docs/" + name + ".md")); - }); - docTasks.push(taskName); -}; +gulp.task("lint", function() { + return gulp.src("src/**/*.js") + .pipe(jshint()) + .pipe(jshint.reporter()) + .pipe(jscs()); +}); -["Control.Monad.Eff.Ref", "Control.Monad.Eff.Unsafe"].forEach(docTask); +gulp.task("make", ["lint"], function() { + return gulp.src(sources) + .pipe(plumber()) + .pipe(purescript.pscMake({ ffi: foreigns })); +}); -gulp.task("docs", docTasks); +gulp.task("docs", ["clean-docs"], function () { + return gulp.src(sources) + .pipe(plumber()) + .pipe(purescript.pscDocs({ + docgen: { + "Control.Monad.Eff.Ref": "docs/Control.Monad.Eff.Ref.md", + "Control.Monad.Eff.Ref.Unsafe": "docs/Control.Monad.Eff.Ref.Unsafe.md" + } + })); +}); gulp.task("dotpsci", function () { - return gulp.src(paths) + return gulp.src(sources) .pipe(plumber()) .pipe(purescript.dotPsci()); }); -gulp.task("default", ["jsvalidate", "docs", "dotpsci"]); +gulp.task("default", ["make", "docs", "dotpsci"]); diff --git a/package.json b/package.json index fe845c8..fec217b 100644 --- a/package.json +++ b/package.json @@ -2,8 +2,10 @@ "private": true, "devDependencies": { "gulp": "^3.8.11", - "gulp-jsvalidate": "^1.0.1", + "gulp-jscs": "^1.6.0", + "gulp-jshint": "^1.10.0", "gulp-plumber": "^1.0.0", - "gulp-purescript": "^0.3.1" + "gulp-purescript": "^0.5.0-rc.1", + "rimraf": "^2.3.3" } } diff --git a/src/Control/Monad/Eff/Ref.js b/src/Control/Monad/Eff/Ref.js index f24f218..a0debc3 100644 --- a/src/Control/Monad/Eff/Ref.js +++ b/src/Control/Monad/Eff/Ref.js @@ -3,21 +3,21 @@ // module Control.Monad.Eff.Ref -exports.newRef = function(val) { +exports.newRef = function (val) { return function () { return { value: val }; }; }; -exports.readRef = function(ref) { - return function() { +exports.readRef = function (ref) { + return function () { return ref.value; }; }; -exports.modifyRef$prime = function(ref) { - return function(f) { - return function() { +exports["modifyRef'"] = function (ref) { + return function (f) { + return function () { var t = f(ref.value); ref.value = t.state; return t.value; @@ -25,9 +25,9 @@ exports.modifyRef$prime = function(ref) { }; }; -exports.writeRef = function(ref) { - return function(val) { - return function() { +exports.writeRef = function (ref) { + return function (val) { + return function () { ref.value = val; return {}; }; diff --git a/src/Control/Monad/Eff/Ref.purs b/src/Control/Monad/Eff/Ref.purs index 4917519..85b1e75 100644 --- a/src/Control/Monad/Eff/Ref.purs +++ b/src/Control/Monad/Eff/Ref.purs @@ -4,11 +4,9 @@ -- | _Note_: The `Control.Monad.ST` provides a _safe_ alternative -- | to global mutable variables when mutation is restricted to a -- | local scope. - module Control.Monad.Eff.Ref where import Prelude - import Control.Monad.Eff (Eff()) -- | The effect associated with the use of global mutable variables. diff --git a/src/Control/Monad/Eff/Ref/Unsafe.purs b/src/Control/Monad/Eff/Ref/Unsafe.purs index 1bdb123..fb12b08 100644 --- a/src/Control/Monad/Eff/Ref/Unsafe.purs +++ b/src/Control/Monad/Eff/Ref/Unsafe.purs @@ -2,11 +2,8 @@ module Control.Monad.Eff.Ref.Unsafe where -import Prelude - import Control.Monad.Eff (Eff()) import Control.Monad.Eff.Ref - import Control.Monad.Eff.Unsafe (unsafeInterleaveEff) -- | This handler function unsafely removes the `Ref` effect from an @@ -16,4 +13,4 @@ import Control.Monad.Eff.Unsafe (unsafeInterleaveEff) -- | typechecker that a particular mutable reference does not escape -- | its scope. unsafeRunRef :: forall eff a. Eff (ref :: REF | eff) a -> Eff eff a -unsafeRunRef = unsafeInterleaveEff \ No newline at end of file +unsafeRunRef = unsafeInterleaveEff