@@ -6,37 +6,45 @@ foreign import data Ref :: !
6
6
7
7
foreign import data RefVal :: * -> *
8
8
9
- foreign import newRef
10
- " function newRef(val) {\
11
- \ return function () {\
12
- \ return { value: val };\
13
- \ };\
14
- \}" :: forall s r . s -> Eff (ref :: Ref | r ) (RefVal s )
15
-
16
- foreign import readRef
17
- " function readRef(ref) {\
18
- \ return function() {\
19
- \ return ref.value;\
20
- \ };\
21
- \}" :: forall s r . RefVal s -> Eff (ref :: Ref | r ) s
22
-
23
-
24
- foreign import modifyRef
25
- " function modifyRef(ref) {\
26
- \ return function(f) {\
27
- \ return function() {\
28
- \ ref.value = f(ref.value);\
29
- \ return {};\
30
- \ };\
31
- \ };\
32
- \}" :: forall s r . RefVal s -> (s -> s ) -> Eff (ref :: Ref | r ) Unit
33
-
34
- foreign import writeRef
35
- " function writeRef(ref) {\
36
- \ return function(val) {\
37
- \ return function() {\
38
- \ ref.value = val;\
39
- \ return {};\
40
- \ };\
41
- \ };\
42
- \}" :: forall s r . RefVal s -> s -> Eff (ref :: Ref | r ) Unit
9
+ foreign import newRef " " "
10
+ function newRef(val) {
11
+ return function () {
12
+ return { value: val };
13
+ };
14
+ }
15
+ " " " :: forall s r . s -> Eff (ref :: Ref | r ) (RefVal s )
16
+
17
+ foreign import readRef " " "
18
+ function readRef(ref) {
19
+ return function() {
20
+ return ref.value;
21
+ };
22
+ }
23
+ " " " :: forall s r . RefVal s -> Eff (ref :: Ref | r ) s
24
+
25
+
26
+ foreign import modifyRef' " " "
27
+ function modifyRef$prime(ref) {
28
+ return function(f) {
29
+ return function() {
30
+ var t = f(ref.value);
31
+ ref.value = t.newState;
32
+ return t.retVal;
33
+ };
34
+ };
35
+ }
36
+ " " " :: forall s b r . RefVal s -> (s -> { newState :: s , retVal :: b } ) -> Eff (ref :: Ref | r ) b
37
+
38
+ modifyRef :: forall s r . RefVal s -> (s -> s ) -> Eff (ref :: Ref | r ) Unit
39
+ modifyRef ref f = modifyRef' ref (\s -> {newState: f s, retVal: unit})
40
+
41
+ foreign import writeRef " " "
42
+ function writeRef(ref) {
43
+ return function(val) {
44
+ return function() {
45
+ ref.value = val;
46
+ return {};
47
+ };
48
+ };
49
+ }
50
+ " " " :: forall s r . RefVal s -> s -> Eff (ref :: Ref | r ) Unit
0 commit comments