Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/.*
!/.gitignore
!/.travis.yml
/bower_components/
/node_modules/
/output/
Expand Down
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
30 changes: 0 additions & 30 deletions Gruntfile.js

This file was deleted.

89 changes: 8 additions & 81 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
- [Control.Monad.Eff.Ref](docs/Control.Monad.Eff.Ref.md)
- [Control.Monad.Eff.Ref.Unsafe](docs/Control.Monad.Eff.Ref.Unsafe.md)
20 changes: 9 additions & 11 deletions bower.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
73 changes: 73 additions & 0 deletions docs/Control.Monad.Eff.Ref.md
Original file line number Diff line number Diff line change
@@ -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.



3 changes: 3 additions & 0 deletions docs/Control.Monad.Eff.Unsafe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Module Documentation


48 changes: 48 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -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"]);
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
22 changes: 11 additions & 11 deletions src/Control/Monad/Eff/Ref.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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 """
Expand All @@ -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 """
Expand All @@ -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.
Expand All @@ -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 """
Expand All @@ -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
2 changes: 1 addition & 1 deletion src/Control/Monad/Eff/Ref/Unsafe.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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