Skip to content

Commit 4ef2ee3

Browse files
committed
Docs
1 parent 73ab3ee commit 4ef2ee3

File tree

5 files changed

+99
-15
lines changed

5 files changed

+99
-15
lines changed

Gruntfile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = function(grunt) {
1313

1414
pscMake: ["<%=libFiles%>"],
1515
dotPsci: ["<%=libFiles%>"],
16-
docgen: {
16+
pscDocs: {
1717
readme: {
1818
src: "src/**/*.purs",
1919
dest: "README.md"
@@ -25,6 +25,6 @@ module.exports = function(grunt) {
2525
grunt.loadNpmTasks("grunt-contrib-clean");
2626
grunt.loadNpmTasks("grunt-purescript");
2727

28-
grunt.registerTask("make", ["pscMake", "dotPsci", "docgen"]);
28+
grunt.registerTask("make", ["pscMake", "dotPsci", "pscDocs"]);
2929
grunt.registerTask("default", ["make"]);
3030
};

README.md

Lines changed: 71 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,88 @@
22

33
## Module Control.Monad.Eff.Ref
44

5-
### Types
65

7-
data Ref :: !
6+
This module defines an effect and actions for working with
7+
global mutable variables.
88

9-
data RefVal :: * -> *
9+
_Note_: The `Control.Monad.ST` provides a _safe_ alternative
10+
to global mutable variables when mutation is restricted to a
11+
local scope.
1012

13+
#### `Ref`
1114

12-
### Values
15+
``` purescript
16+
data Ref :: !
17+
```
1318

14-
modifyRef :: forall s r. RefVal s -> (s -> s) -> Eff (ref :: Ref | r) Unit
19+
The effect associated with the use of global mutable variables.
1520

16-
modifyRef' :: forall s b r. RefVal s -> (s -> { retVal :: b, newState :: s }) -> Eff (ref :: Ref | r) b
21+
#### `RefVal`
1722

18-
newRef :: forall s r. s -> Eff (ref :: Ref | r) (RefVal s)
23+
``` purescript
24+
data RefVal :: * -> *
25+
```
1926

20-
readRef :: forall s r. RefVal s -> Eff (ref :: Ref | r) s
27+
A value of type `RefVal a` represents a mutable reference
28+
which holds a value of type `a`.
2129

22-
writeRef :: forall s r. RefVal s -> s -> Eff (ref :: Ref | r) Unit
30+
#### `newRef`
31+
32+
``` purescript
33+
newRef :: forall s r. s -> Eff (ref :: Ref | r) (RefVal s)
34+
```
35+
36+
Create a new mutable reference containing the specified value.
37+
38+
#### `readRef`
39+
40+
``` purescript
41+
readRef :: forall s r. RefVal s -> Eff (ref :: Ref | r) s
42+
```
43+
44+
Read the current value of a mutable reference
45+
46+
#### `modifyRef'`
47+
48+
``` purescript
49+
modifyRef' :: forall s b r. RefVal s -> (s -> { retVal :: b, newState :: s }) -> Eff (ref :: Ref | r) b
50+
```
51+
52+
Update the value of a mutable reference by applying a function
53+
to the current value.
54+
55+
#### `modifyRef`
56+
57+
``` purescript
58+
modifyRef :: forall s r. RefVal s -> (s -> s) -> Eff (ref :: Ref | r) Unit
59+
```
60+
61+
Update the value of a mutable reference by applying a function
62+
to the current value.
63+
64+
#### `writeRef`
65+
66+
``` purescript
67+
writeRef :: forall s r. RefVal s -> s -> Eff (ref :: Ref | r) Unit
68+
```
69+
70+
Update the value of a mutable reference to the specified value.
2371

2472

2573
## Module Control.Monad.Eff.Ref.Unsafe
2674

27-
### Values
2875

29-
unsafeRunRef :: forall eff a. Eff (ref :: Ref | eff) a -> Eff eff a
76+
Unsafe functions for working with mutable references.
77+
78+
#### `unsafeRunRef`
79+
80+
``` purescript
81+
unsafeRunRef :: forall eff a. Eff (ref :: Ref | eff) a -> Eff eff a
82+
```
83+
84+
This handler function unsafely removes the `Ref` effect from an
85+
effectful action.
86+
87+
This function might be used when it is impossible to prove to the
88+
typechecker that a particular mutable reference does not escape
89+
its scope.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"private": true,
33
"dependencies": {
44
"grunt": "~0.4.4",
5-
"grunt-purescript": "~0.5.1",
5+
"grunt-purescript": "~0.6.0",
66
"grunt-contrib-clean": "~0.5.0"
77
}
88
}

src/Control/Monad/Eff/Ref.purs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
1+
-- | This module defines an effect and actions for working with
2+
-- | global mutable variables.
3+
-- |
4+
-- | _Note_: The `Control.Monad.ST` provides a _safe_ alternative
5+
-- | to global mutable variables when mutation is restricted to a
6+
-- | local scope.
7+
18
module Control.Monad.Eff.Ref where
29

310
import Control.Monad.Eff
411

12+
-- | The effect associated with the use of global mutable variables.
513
foreign import data Ref :: !
614

15+
-- | A value of type `RefVal a` represents a mutable reference
16+
-- | which holds a value of type `a`.
717
foreign import data RefVal :: * -> *
818

19+
-- | Create a new mutable reference containing the specified value.
920
foreign import newRef """
1021
function newRef(val) {
1122
return function () {
@@ -14,6 +25,7 @@ foreign import newRef """
1425
}
1526
""" :: forall s r. s -> Eff (ref :: Ref | r) (RefVal s)
1627

28+
-- | Read the current value of a mutable reference
1729
foreign import readRef """
1830
function readRef(ref) {
1931
return function() {
@@ -22,7 +34,8 @@ foreign import readRef """
2234
}
2335
""" :: forall s r. RefVal s -> Eff (ref :: Ref | r) s
2436

25-
37+
-- | Update the value of a mutable reference by applying a function
38+
-- | to the current value.
2639
foreign import modifyRef' """
2740
function modifyRef$prime(ref) {
2841
return function(f) {
@@ -35,9 +48,12 @@ foreign import modifyRef' """
3548
}
3649
""" :: forall s b r. RefVal s -> (s -> {newState :: s, retVal :: b}) -> Eff (ref :: Ref | r) b
3750

51+
-- | Update the value of a mutable reference by applying a function
52+
-- | to the current value.
3853
modifyRef :: forall s r. RefVal s -> (s -> s) -> Eff (ref :: Ref | r) Unit
3954
modifyRef ref f = modifyRef' ref (\s -> {newState: f s, retVal: unit})
4055

56+
-- | Update the value of a mutable reference to the specified value.
4157
foreign import writeRef """
4258
function writeRef(ref) {
4359
return function(val) {

src/Control/Monad/Eff/Ref/Unsafe.purs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1+
-- | Unsafe functions for working with mutable references.
2+
13
module Control.Monad.Eff.Ref.Unsafe where
24

35
import Control.Monad.Eff
46
import Control.Monad.Eff.Ref
57

8+
-- | This handler function unsafely removes the `Ref` effect from an
9+
-- | effectful action.
10+
-- |
11+
-- | This function might be used when it is impossible to prove to the
12+
-- | typechecker that a particular mutable reference does not escape
13+
-- | its scope.
614
foreign import unsafeRunRef
715
"function unsafeRunRef(f) {\
816
\ return f;\

0 commit comments

Comments
 (0)