Skip to content

Commit 8273fed

Browse files
author
Mike Solomon
authored
Adds uncurried ST functions (#52)
* Adds uncurried ST functions * Runs eslint * Adds changelog entry
1 parent 2cc7ae1 commit 8273fed

File tree

3 files changed

+331
-0
lines changed

3 files changed

+331
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Notable changes to this project are documented in this file. The format is based
77
Breaking changes:
88

99
New features:
10+
- Adds uncurried ST functions with similar signatures and purposes as effect uncurried functions.
1011

1112
Bugfixes:
1213

src/Control/Monad/ST/Uncurried.js

Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
export const mkSTFn1 = function mkSTFn1(fn) {
2+
return function(x) {
3+
return fn(x)();
4+
};
5+
};
6+
7+
export const mkSTFn2 = function mkSTFn2(fn) {
8+
return function(a, b) {
9+
return fn(a)(b)();
10+
};
11+
};
12+
13+
export const mkSTFn3 = function mkSTFn3(fn) {
14+
return function(a, b, c) {
15+
return fn(a)(b)(c)();
16+
};
17+
};
18+
19+
export const mkSTFn4 = function mkSTFn4(fn) {
20+
return function(a, b, c, d) {
21+
return fn(a)(b)(c)(d)();
22+
};
23+
};
24+
25+
export const mkSTFn5 = function mkSTFn5(fn) {
26+
return function(a, b, c, d, e) {
27+
return fn(a)(b)(c)(d)(e)();
28+
};
29+
};
30+
31+
export const mkSTFn6 = function mkSTFn6(fn) {
32+
return function(a, b, c, d, e, f) {
33+
return fn(a)(b)(c)(d)(e)(f)();
34+
};
35+
};
36+
37+
export const mkSTFn7 = function mkSTFn7(fn) {
38+
return function(a, b, c, d, e, f, g) {
39+
return fn(a)(b)(c)(d)(e)(f)(g)();
40+
};
41+
};
42+
43+
export const mkSTFn8 = function mkSTFn8(fn) {
44+
return function(a, b, c, d, e, f, g, h) {
45+
return fn(a)(b)(c)(d)(e)(f)(g)(h)();
46+
};
47+
};
48+
49+
export const mkSTFn9 = function mkSTFn9(fn) {
50+
return function(a, b, c, d, e, f, g, h, i) {
51+
return fn(a)(b)(c)(d)(e)(f)(g)(h)(i)();
52+
};
53+
};
54+
55+
export const mkSTFn10 = function mkSTFn10(fn) {
56+
return function(a, b, c, d, e, f, g, h, i, j) {
57+
return fn(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)();
58+
};
59+
};
60+
61+
export const runSTFn1 = function runSTFn1(fn) {
62+
return function(a) {
63+
return function() {
64+
return fn(a);
65+
};
66+
};
67+
};
68+
69+
export const runSTFn2 = function runSTFn2(fn) {
70+
return function(a) {
71+
return function(b) {
72+
return function() {
73+
return fn(a, b);
74+
};
75+
};
76+
};
77+
};
78+
79+
export const runSTFn3 = function runSTFn3(fn) {
80+
return function(a) {
81+
return function(b) {
82+
return function(c) {
83+
return function() {
84+
return fn(a, b, c);
85+
};
86+
};
87+
};
88+
};
89+
};
90+
91+
export const runSTFn4 = function runSTFn4(fn) {
92+
return function(a) {
93+
return function(b) {
94+
return function(c) {
95+
return function(d) {
96+
return function() {
97+
return fn(a, b, c, d);
98+
};
99+
};
100+
};
101+
};
102+
};
103+
};
104+
105+
export const runSTFn5 = function runSTFn5(fn) {
106+
return function(a) {
107+
return function(b) {
108+
return function(c) {
109+
return function(d) {
110+
return function(e) {
111+
return function() {
112+
return fn(a, b, c, d, e);
113+
};
114+
};
115+
};
116+
};
117+
};
118+
};
119+
};
120+
121+
export const runSTFn6 = function runSTFn6(fn) {
122+
return function(a) {
123+
return function(b) {
124+
return function(c) {
125+
return function(d) {
126+
return function(e) {
127+
return function(f) {
128+
return function() {
129+
return fn(a, b, c, d, e, f);
130+
};
131+
};
132+
};
133+
};
134+
};
135+
};
136+
};
137+
};
138+
139+
export const runSTFn7 = function runSTFn7(fn) {
140+
return function(a) {
141+
return function(b) {
142+
return function(c) {
143+
return function(d) {
144+
return function(e) {
145+
return function(f) {
146+
return function(g) {
147+
return function() {
148+
return fn(a, b, c, d, e, f, g);
149+
};
150+
};
151+
};
152+
};
153+
};
154+
};
155+
};
156+
};
157+
};
158+
159+
export const runSTFn8 = function runSTFn8(fn) {
160+
return function(a) {
161+
return function(b) {
162+
return function(c) {
163+
return function(d) {
164+
return function(e) {
165+
return function(f) {
166+
return function(g) {
167+
return function(h) {
168+
return function() {
169+
return fn(a, b, c, d, e, f, g, h);
170+
};
171+
};
172+
};
173+
};
174+
};
175+
};
176+
};
177+
};
178+
};
179+
};
180+
181+
export const runSTFn9 = function runSTFn9(fn) {
182+
return function(a) {
183+
return function(b) {
184+
return function(c) {
185+
return function(d) {
186+
return function(e) {
187+
return function(f) {
188+
return function(g) {
189+
return function(h) {
190+
return function(i) {
191+
return function() {
192+
return fn(a, b, c, d, e, f, g, h, i);
193+
};
194+
};
195+
};
196+
};
197+
};
198+
};
199+
};
200+
};
201+
};
202+
};
203+
};
204+
205+
export const runSTFn10 = function runSTFn10(fn) {
206+
return function(a) {
207+
return function(b) {
208+
return function(c) {
209+
return function(d) {
210+
return function(e) {
211+
return function(f) {
212+
return function(g) {
213+
return function(h) {
214+
return function(i) {
215+
return function(j) {
216+
return function() {
217+
return fn(a, b, c, d, e, f, g, h, i, j);
218+
};
219+
};
220+
};
221+
};
222+
};
223+
};
224+
};
225+
};
226+
};
227+
};
228+
};
229+
};

src/Control/Monad/ST/Uncurried.purs

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
-- | This module defines types for STf uncurried functions, as well as
2+
-- | functions for converting back and forth between them.
3+
-- |
4+
-- | The general naming scheme for functions and types in this module is as
5+
-- | follows:
6+
-- |
7+
-- | * `STFn{N}` means, an uncurried function which accepts N arguments and
8+
-- | performs some STs. The first N arguments are the actual function's
9+
-- | argument. The last type argument is the return type.
10+
-- | * `runSTFn{N}` takes an `STFn` of N arguments, and converts it into
11+
-- | the normal PureScript form: a curried function which returns an ST
12+
-- | action.
13+
-- | * `mkSTFn{N}` is the inverse of `runSTFn{N}`. It can be useful for
14+
-- | callbacks.
15+
-- |
16+
17+
module Control.Monad.ST.Uncurried where
18+
19+
import Control.Monad.ST.Internal (ST, Region)
20+
21+
foreign import data STFn1 :: Type -> Region -> Type -> Type
22+
23+
type role STFn1 representational nominal representational
24+
25+
foreign import data STFn2 :: Type -> Type -> Region -> Type -> Type
26+
27+
type role STFn2 representational representational nominal representational
28+
29+
foreign import data STFn3 :: Type -> Type -> Type -> Region -> Type -> Type
30+
31+
type role STFn3 representational representational representational nominal representational
32+
33+
foreign import data STFn4 :: Type -> Type -> Type -> Type -> Region -> Type -> Type
34+
35+
type role STFn4 representational representational representational representational nominal representational
36+
37+
foreign import data STFn5 :: Type -> Type -> Type -> Type -> Type -> Region -> Type -> Type
38+
39+
type role STFn5 representational representational representational representational representational nominal representational
40+
41+
foreign import data STFn6 :: Type -> Type -> Type -> Type -> Type -> Type -> Region -> Type -> Type
42+
43+
type role STFn6 representational representational representational representational representational representational nominal representational
44+
45+
foreign import data STFn7 :: Type -> Type -> Type -> Type -> Type -> Type -> Type -> Region -> Type -> Type
46+
47+
type role STFn7 representational representational representational representational representational representational representational nominal representational
48+
49+
foreign import data STFn8 :: Type -> Type -> Type -> Type -> Type -> Type -> Type -> Type -> Region -> Type -> Type
50+
51+
type role STFn8 representational representational representational representational representational representational representational representational nominal representational
52+
53+
foreign import data STFn9 :: Type -> Type -> Type -> Type -> Type -> Type -> Type -> Type -> Type -> Region -> Type -> Type
54+
55+
type role STFn9 representational representational representational representational representational representational representational representational representational nominal representational
56+
57+
foreign import data STFn10 :: Type -> Type -> Type -> Type -> Type -> Type -> Type -> Type -> Type -> Type -> Region -> Type -> Type
58+
59+
type role STFn10 representational representational representational representational representational representational representational representational representational representational nominal representational
60+
61+
foreign import mkSTFn1 :: forall a t r.
62+
(a -> ST t r) -> STFn1 a t r
63+
foreign import mkSTFn2 :: forall a b t r.
64+
(a -> b -> ST t r) -> STFn2 a b t r
65+
foreign import mkSTFn3 :: forall a b c t r.
66+
(a -> b -> c -> ST t r) -> STFn3 a b c t r
67+
foreign import mkSTFn4 :: forall a b c d t r.
68+
(a -> b -> c -> d -> ST t r) -> STFn4 a b c d t r
69+
foreign import mkSTFn5 :: forall a b c d e t r.
70+
(a -> b -> c -> d -> e -> ST t r) -> STFn5 a b c d e t r
71+
foreign import mkSTFn6 :: forall a b c d e f t r.
72+
(a -> b -> c -> d -> e -> f -> ST t r) -> STFn6 a b c d e f t r
73+
foreign import mkSTFn7 :: forall a b c d e f g t r.
74+
(a -> b -> c -> d -> e -> f -> g -> ST t r) -> STFn7 a b c d e f g t r
75+
foreign import mkSTFn8 :: forall a b c d e f g h t r.
76+
(a -> b -> c -> d -> e -> f -> g -> h -> ST t r) -> STFn8 a b c d e f g h t r
77+
foreign import mkSTFn9 :: forall a b c d e f g h i t r.
78+
(a -> b -> c -> d -> e -> f -> g -> h -> i -> ST t r) -> STFn9 a b c d e f g h i t r
79+
foreign import mkSTFn10 :: forall a b c d e f g h i j t r.
80+
(a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> ST t r) -> STFn10 a b c d e f g h i j t r
81+
82+
foreign import runSTFn1 :: forall a t r.
83+
STFn1 a t r -> a -> ST t r
84+
foreign import runSTFn2 :: forall a b t r.
85+
STFn2 a b t r -> a -> b -> ST t r
86+
foreign import runSTFn3 :: forall a b c t r.
87+
STFn3 a b c t r -> a -> b -> c -> ST t r
88+
foreign import runSTFn4 :: forall a b c d t r.
89+
STFn4 a b c d t r -> a -> b -> c -> d -> ST t r
90+
foreign import runSTFn5 :: forall a b c d e t r.
91+
STFn5 a b c d e t r -> a -> b -> c -> d -> e -> ST t r
92+
foreign import runSTFn6 :: forall a b c d e f t r.
93+
STFn6 a b c d e f t r -> a -> b -> c -> d -> e -> f -> ST t r
94+
foreign import runSTFn7 :: forall a b c d e f g t r.
95+
STFn7 a b c d e f g t r -> a -> b -> c -> d -> e -> f -> g -> ST t r
96+
foreign import runSTFn8 :: forall a b c d e f g h t r.
97+
STFn8 a b c d e f g h t r -> a -> b -> c -> d -> e -> f -> g -> h -> ST t r
98+
foreign import runSTFn9 :: forall a b c d e f g h i t r.
99+
STFn9 a b c d e f g h i t r -> a -> b -> c -> d -> e -> f -> g -> h -> i -> ST t r
100+
foreign import runSTFn10 :: forall a b c d e f g h i j t r.
101+
STFn10 a b c d e f g h i j t r -> a -> b -> c -> d -> e -> f -> g -> h -> i -> j -> ST t r

0 commit comments

Comments
 (0)