diff --git a/.gitignore b/.gitignore index dc070b8..2836c9a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /.* !/.gitignore +!/.travis.yml /bower_components/ /node_modules/ /output/ diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..a9061e2 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,14 @@ +language: node_js +node_js: + - 0.10 +env: + - PATH=$HOME/purescript:$PATH +install: + - TAG=$(wget -q -O - https://github.com/purescript/purescript/releases/latest --server-response --max-redirect 0 2>&1 | sed -n -e 's/.*Location:.*tag\///p') + - wget -O $HOME/purescript.tar.gz https://github.com/purescript/purescript/releases/download/$TAG/linux64.tar.gz + - tar -xvf $HOME/purescript.tar.gz -C $HOME/ + - chmod a+x $HOME/purescript + - npm install bower gulp -g + - npm install && bower install +script: + - gulp diff --git a/Gruntfile.js b/Gruntfile.js deleted file mode 100644 index 1e63887..0000000 --- a/Gruntfile.js +++ /dev/null @@ -1,30 +0,0 @@ -module.exports = function(grunt) { - - "use strict"; - - grunt.initConfig({ - - libFiles: [ - "src/**/*.purs", - "bower_components/purescript-*/src/**/*.purs", - ], - - clean: ["output"], - - pscMake: ["<%=libFiles%>"], - dotPsci: ["<%=libFiles%>"], - pscDocs: { - readme: { - src: "src/**/*.purs", - dest: "README.md" - } - } - - }); - - grunt.loadNpmTasks("grunt-contrib-clean"); - grunt.loadNpmTasks("grunt-purescript"); - - grunt.registerTask("make", ["pscMake", "dotPsci", "pscDocs"]); - grunt.registerTask("default", ["make"]); -}; diff --git a/README.md b/README.md index b84faed..da2d929 100644 --- a/README.md +++ b/README.md @@ -1,89 +1,16 @@ -# Module Documentation +# purescript-refs -## Module Control.Monad.Eff.Ref +[![Build Status](https://travis-ci.org/purescript/purescript-refs.svg?branch=master)](https://travis-ci.org/purescript/purescript-refs) +Mutable value references. -This module defines an effect and actions for working with -global mutable variables. +## Installation -_Note_: The `Control.Monad.ST` provides a _safe_ alternative -to global mutable variables when mutation is restricted to a -local scope. - -#### `Ref` - -``` purescript -data Ref :: ! ``` - -The effect associated with the use of global mutable variables. - -#### `RefVal` - -``` purescript -data RefVal :: * -> * -``` - -A value of type `RefVal a` represents a mutable reference -which holds a value of type `a`. - -#### `newRef` - -``` purescript -newRef :: forall s r. s -> Eff (ref :: Ref | r) (RefVal s) -``` - -Create a new mutable reference containing the specified value. - -#### `readRef` - -``` purescript -readRef :: forall s r. RefVal s -> Eff (ref :: Ref | r) s -``` - -Read the current value of a mutable reference - -#### `modifyRef'` - -``` purescript -modifyRef' :: forall s b r. RefVal s -> (s -> { retVal :: b, newState :: s }) -> Eff (ref :: Ref | r) b -``` - -Update the value of a mutable reference by applying a function -to the current value. - -#### `modifyRef` - -``` purescript -modifyRef :: forall s r. RefVal s -> (s -> s) -> Eff (ref :: Ref | r) Unit -``` - -Update the value of a mutable reference by applying a function -to the current value. - -#### `writeRef` - -``` purescript -writeRef :: forall s r. RefVal s -> s -> Eff (ref :: Ref | r) Unit -``` - -Update the value of a mutable reference to the specified value. - - -## 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 +bower install purescript-refs ``` -This handler function unsafely removes the `Ref` effect from an -effectful action. +## Module documentation -This function might be used when it is impossible to prove to the -typechecker that a particular mutable reference does not escape -its scope. \ No newline at end of file +- [Control.Monad.Eff.Ref](docs/Control.Monad.Eff.Ref.md) +- [Control.Monad.Eff.Ref.Unsafe](docs/Control.Monad.Eff.Ref.Unsafe.md) diff --git a/bower.json b/bower.json index 832bf45..08f00f4 100644 --- a/bower.json +++ b/bower.json @@ -1,20 +1,18 @@ { - "name": "purescript-refs", - "homepage": "https://github.com/purescript/purescript-refs", - "description": "Mutable value references", - "keywords": [ - "purescript" + "name": "purescript-semirings", + "moduleType": [ + "node" ], - "license": "MIT", "ignore": [ "**/.*", - "bower_components", "node_modules", + "bower_components", "output", - "tests", - "tmp", "bower.json", - "Gruntfile.js", + "gulpfile.js", "package.json" - ] + ], + "dependencies": { + "purescript-foldable-traversable": "~0.4.0" + } } diff --git a/docs/Control.Monad.Eff.Ref.md b/docs/Control.Monad.Eff.Ref.md new file mode 100644 index 0000000..ccb624e --- /dev/null +++ b/docs/Control.Monad.Eff.Ref.md @@ -0,0 +1,73 @@ +# Module Documentation + +## Module Control.Monad.Eff.Ref + + +This module defines an effect and actions for working with +global mutable variables. + +_Note_: The `Control.Monad.ST` provides a _safe_ alternative +to global mutable variables when mutation is restricted to a +local scope. + +#### `REF` + +``` purescript +data REF :: ! +``` + +The effect associated with the use of global mutable variables. + +#### `Ref` + +``` purescript +data Ref :: * -> * +``` + +A value of type `Ref a` represents a mutable reference +which holds a value of type `a`. + +#### `newRef` + +``` purescript +newRef :: forall s r. s -> Eff (ref :: REF | r) (Ref s) +``` + +Create a new mutable reference containing the specified value. + +#### `readRef` + +``` purescript +readRef :: forall s r. Ref s -> Eff (ref :: REF | r) s +``` + +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 +``` + +Update the value of a mutable reference by applying a function +to the current value. + +#### `modifyRef` + +``` purescript +modifyRef :: forall s r. Ref s -> (s -> s) -> Eff (ref :: REF | r) Unit +``` + +Update the value of a mutable reference by applying a function +to the current value. + +#### `writeRef` + +``` purescript +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 new file mode 100644 index 0000000..4c9fa37 --- /dev/null +++ b/docs/Control.Monad.Eff.Unsafe.md @@ -0,0 +1,3 @@ +# Module Documentation + + diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 0000000..f08e27b --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,48 @@ +"use strict"; + +var gulp = require("gulp"); +var plumber = require("gulp-plumber"); +var purescript = require("gulp-purescript"); +var jsvalidate = require("gulp-jsvalidate"); + +var paths = [ + "src/**/*.purs", + "bower_components/purescript-*/src/**/*.purs" +]; + +gulp.task("make", function() { + return gulp.src(paths) + .pipe(plumber()) + .pipe(purescript.pscMake()); +}); + +gulp.task("jsvalidate", ["make"], function () { + return gulp.src("output/**/*.js") + .pipe(plumber()) + .pipe(jsvalidate()); +}); + +var docTasks = []; + +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); +}; + +["Control.Monad.Eff.Ref", "Control.Monad.Eff.Unsafe"].forEach(docTask); + +gulp.task("docs", docTasks); + +gulp.task("dotpsci", function () { + return gulp.src(paths) + .pipe(plumber()) + .pipe(purescript.dotPsci()); +}); + +gulp.task("default", ["jsvalidate", "docs", "dotpsci"]); diff --git a/package.json b/package.json index 8a9a934..fe845c8 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,9 @@ { "private": true, - "dependencies": { - "grunt": "~0.4.4", - "grunt-purescript": "~0.6.0", - "grunt-contrib-clean": "~0.5.0" + "devDependencies": { + "gulp": "^3.8.11", + "gulp-jsvalidate": "^1.0.1", + "gulp-plumber": "^1.0.0", + "gulp-purescript": "^0.3.1" } } diff --git a/src/Control/Monad/Eff/Ref.purs b/src/Control/Monad/Eff/Ref.purs index 6092ac3..cf03150 100644 --- a/src/Control/Monad/Eff/Ref.purs +++ b/src/Control/Monad/Eff/Ref.purs @@ -10,11 +10,11 @@ module Control.Monad.Eff.Ref where import Control.Monad.Eff -- | The effect associated with the use of global mutable variables. -foreign import data Ref :: ! +foreign import data REF :: ! --- | A value of type `RefVal a` represents a mutable reference +-- | A value of type `Ref a` represents a mutable reference -- | which holds a value of type `a`. -foreign import data RefVal :: * -> * +foreign import data Ref :: * -> * -- | Create a new mutable reference containing the specified value. foreign import newRef """ @@ -23,7 +23,7 @@ foreign import newRef """ return { value: val }; }; } -""" :: forall s r. s -> Eff (ref :: Ref | r) (RefVal s) +""" :: forall s r. s -> Eff (ref :: REF | r) (Ref s) -- | Read the current value of a mutable reference foreign import readRef """ @@ -32,7 +32,7 @@ foreign import readRef """ return ref.value; }; } -""" :: forall s r. RefVal s -> Eff (ref :: Ref | r) s +""" :: forall s r. Ref s -> Eff (ref :: REF | r) s -- | Update the value of a mutable reference by applying a function -- | to the current value. @@ -41,17 +41,17 @@ foreign import modifyRef' """ return function(f) { return function() { var t = f(ref.value); - ref.value = t.newState; - return t.retVal; + ref.value = t.state; + return t.value; }; }; } -""" :: forall s b r. RefVal s -> (s -> {newState :: s, retVal :: b}) -> Eff (ref :: Ref | r) b +""" :: 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 -- | to the current value. -modifyRef :: forall s r. RefVal s -> (s -> s) -> Eff (ref :: Ref | r) Unit -modifyRef ref f = modifyRef' ref (\s -> {newState: f s, retVal: unit}) +modifyRef :: forall s r. Ref s -> (s -> s) -> Eff (ref :: REF | r) Unit +modifyRef ref f = modifyRef' ref (\s -> { state: f s, value: unit }) -- | Update the value of a mutable reference to the specified value. foreign import writeRef """ @@ -63,4 +63,4 @@ foreign import writeRef """ }; }; } -""" :: forall s r. RefVal s -> s -> Eff (ref :: Ref | r) Unit +""" :: forall s r. Ref s -> s -> Eff (ref :: REF | r) Unit diff --git a/src/Control/Monad/Eff/Ref/Unsafe.purs b/src/Control/Monad/Eff/Ref/Unsafe.purs index 1c53705..97a9af3 100644 --- a/src/Control/Monad/Eff/Ref/Unsafe.purs +++ b/src/Control/Monad/Eff/Ref/Unsafe.purs @@ -14,4 +14,4 @@ import Control.Monad.Eff.Ref foreign import unsafeRunRef "function unsafeRunRef(f) {\ \ return f;\ - \}" :: forall eff a. Eff (ref :: Ref | eff) a -> Eff eff a + \}" :: forall eff a. Eff (ref :: REF | eff) a -> Eff eff a