77
88module Control.Monad.Eff.Ref where
99
10+ import Prelude
11+
1012import Control.Monad.Eff (Eff ())
1113
1214-- | The effect associated with the use of global mutable variables.
@@ -17,54 +19,19 @@ foreign import data REF :: !
1719foreign 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.
5633modifyRef :: forall s r . Ref s -> (s -> s ) -> Eff (ref :: REF | r ) Unit
5734modifyRef 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
0 commit comments