Skip to content

Commit 36270ad

Browse files
committed
Updates for 0.7
1 parent cc084e1 commit 36270ad

File tree

3 files changed

+47
-45
lines changed

3 files changed

+47
-45
lines changed

src/Control/Monad/Eff/Ref.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/* global exports */
2+
"use strict";
3+
4+
// module Control.Monad.Eff.Ref
5+
6+
exports.newRef = function(val) {
7+
return function () {
8+
return { value: val };
9+
};
10+
};
11+
12+
exports.readRef = function(ref) {
13+
return function() {
14+
return ref.value;
15+
};
16+
};
17+
18+
exports.modifyRef$prime = function(ref) {
19+
return function(f) {
20+
return function() {
21+
var t = f(ref.value);
22+
ref.value = t.state;
23+
return t.value;
24+
};
25+
};
26+
};
27+
28+
exports.writeRef = function(ref) {
29+
return function(val) {
30+
return function() {
31+
ref.value = val;
32+
return {};
33+
};
34+
};
35+
};

src/Control/Monad/Eff/Ref.purs

Lines changed: 6 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
module Control.Monad.Eff.Ref where
99

10+
import Prelude
11+
1012
import Control.Monad.Eff (Eff())
1113

1214
-- | The effect associated with the use of global mutable variables.
@@ -17,54 +19,19 @@ foreign import data REF :: !
1719
foreign import data Ref :: * -> *
1820

1921
-- | Create a new mutable reference containing the specified value.
20-
foreign import newRef
21-
"""
22-
function newRef(val) {
23-
return function () {
24-
return { value: val };
25-
};
26-
}
27-
""" :: forall s r. s -> Eff (ref :: REF | r) (Ref s)
22+
foreign import newRef :: forall s r. s -> Eff (ref :: REF | r) (Ref s)
2823

2924
-- | Read the current value of a mutable reference
30-
foreign import readRef
31-
"""
32-
function readRef(ref) {
33-
return function() {
34-
return ref.value;
35-
};
36-
}
37-
""" :: forall s r. Ref s -> Eff (ref :: REF | r) s
25+
foreign import readRef :: forall s r. Ref s -> Eff (ref :: REF | r) s
3826

3927
-- | Update the value of a mutable reference by applying a function
4028
-- | to the current value.
41-
foreign import modifyRef'
42-
"""
43-
function modifyRef$prime(ref) {
44-
return function(f) {
45-
return function() {
46-
var t = f(ref.value);
47-
ref.value = t.state;
48-
return t.value;
49-
};
50-
};
51-
}
52-
""" :: forall s b r. Ref s -> (s -> { state :: s, value :: b }) -> Eff (ref :: REF | r) b
29+
foreign import modifyRef' :: forall s b r. Ref s -> (s -> { state :: s, value :: b }) -> Eff (ref :: REF | r) b
5330

5431
-- | Update the value of a mutable reference by applying a function
5532
-- | to the current value.
5633
modifyRef :: forall s r. Ref s -> (s -> s) -> Eff (ref :: REF | r) Unit
5734
modifyRef ref f = modifyRef' ref (\s -> { state: f s, value: unit })
5835

5936
-- | Update the value of a mutable reference to the specified value.
60-
foreign import writeRef
61-
"""
62-
function writeRef(ref) {
63-
return function(val) {
64-
return function() {
65-
ref.value = val;
66-
return {};
67-
};
68-
};
69-
}
70-
""" :: forall s r. Ref s -> s -> Eff (ref :: REF | r) Unit
37+
foreign import writeRef :: forall s r. Ref s -> s -> Eff (ref :: REF | r) Unit

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33
module Control.Monad.Eff.Ref.Unsafe where
44

5+
import Prelude
6+
57
import Control.Monad.Eff (Eff())
68
import Control.Monad.Eff.Ref
79

10+
import Control.Monad.Eff.Unsafe (unsafeInterleaveEff)
11+
812
-- | This handler function unsafely removes the `Ref` effect from an
913
-- | effectful action.
1014
-- |
1115
-- | This function might be used when it is impossible to prove to the
1216
-- | typechecker that a particular mutable reference does not escape
1317
-- | its scope.
14-
foreign import unsafeRunRef
15-
"""
16-
function unsafeRunRef(f) {
17-
return f;
18-
}
19-
""" :: forall eff a. Eff (ref :: REF | eff) a -> Eff eff a
18+
unsafeRunRef :: forall eff a. Eff (ref :: REF | eff) a -> Eff eff a
19+
unsafeRunRef = unsafeInterleaveEff

0 commit comments

Comments
 (0)