-
Notifications
You must be signed in to change notification settings - Fork 2
/
Examples.html
362 lines (338 loc) · 36.7 KB
/
Examples.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<!--
The Resumable monad examples
parameters will be replaced with the
document title extracted from the <h1> element or
file name, if there is no <h1> heading
-->
<title>Resumable monad examples
</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Resumable monad with F#">
<meta name="author" content="William Blum">
<script src="http://code.jquery.com/jquery-1.8.0.js"></script>
<script src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.1/js/bootstrap.min.js"></script>
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.2.1/css/bootstrap-combined.min.css" rel="stylesheet">
<link type="text/css" rel="stylesheet" href="content/style.css" />
<script src="content/tips.js" type="text/javascript"></script>
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<div class="container">
<div class="masthead">
<ul class="nav nav-pills pull-right">
<li><a href="http://fsharp.org">fsharp.org</a></li>
<li><a href="https://github.com/blumu/ResumableMonad/">github page</a></li>
</ul>
<h3 class="muted">Resumable Monad</h3>
</div>
<hr />
<div class="row">
<div class="span9" id="main">
<h1>Resumable monad examples</h1>
<table class="pre"><tr><td class="lines"><pre class="fssnip"><span class="l">1: </span>
</pre></td>
<td class="snippet"><pre class="fssnip highlighted"><code lang="fsharp"><span class="k">module</span> <span onmouseout="hideTip(event, 'fs1', 1)" onmouseover="showTip(event, 'fs1', 1)" class="t">Example</span>
</code></pre></td>
</tr>
</table>
<h2>Simple resumable calculations</h2>
<table class="pre"><tr><td class="lines"><pre class="fssnip"><span class="l"> 1: </span>
<span class="l"> 2: </span>
<span class="l"> 3: </span>
<span class="l"> 4: </span>
<span class="l"> 5: </span>
<span class="l"> 6: </span>
<span class="l"> 7: </span>
<span class="l"> 8: </span>
<span class="l"> 9: </span>
<span class="l">10: </span>
<span class="l">11: </span>
<span class="l">12: </span>
<span class="l">13: </span>
<span class="l">14: </span>
<span class="l">15: </span>
<span class="l">16: </span>
<span class="l">17: </span>
<span class="l">18: </span>
<span class="l">19: </span>
<span class="l">20: </span>
<span class="l">21: </span>
<span class="l">22: </span>
<span class="l">23: </span>
<span class="l">24: </span>
<span class="l">25: </span>
<span class="l">26: </span>
<span class="l">27: </span>
<span class="l">28: </span>
<span class="l">29: </span>
</pre></td>
<td class="snippet"><pre class="fssnip highlighted"><code lang="fsharp"><span class="k">open</span> <span onmouseout="hideTip(event, 'fs2', 2)" onmouseover="showTip(event, 'fs2', 2)" class="i">Zero</span>
<span class="k">open</span> <span onmouseout="hideTip(event, 'fs3', 3)" onmouseover="showTip(event, 'fs3', 3)" class="i">ResumableMonad</span><span class="o">.</span><span onmouseout="hideTip(event, 'fs4', 4)" onmouseover="showTip(event, 'fs4', 4)" class="i">Multipstep</span>
<span class="k">let</span> <span onmouseout="hideTip(event, 'fs5', 5)" onmouseover="showTip(event, 'fs5', 5)" class="i">x1</span> <span class="o">=</span> <span onmouseout="hideTip(event, 'fs6', 6)" onmouseover="showTip(event, 'fs6', 6)" class="i">resumable</span> { <span class="k">return</span> <span class="n">1</span> }
<span class="k">let</span> <span onmouseout="hideTip(event, 'fs7', 7)" onmouseover="showTip(event, 'fs7', 7)" class="i">x2</span> <span class="o">=</span> <span onmouseout="hideTip(event, 'fs6', 8)" onmouseover="showTip(event, 'fs6', 8)" class="i">resumable</span> {
<span class="k">let!</span> <span onmouseout="hideTip(event, 'fs8', 9)" onmouseover="showTip(event, 'fs8', 9)" class="i">y</span> <span class="o">=</span> <span onmouseout="hideTip(event, 'fs5', 10)" onmouseover="showTip(event, 'fs5', 10)" class="i">x1</span>
<span class="k">return</span> <span onmouseout="hideTip(event, 'fs8', 11)" onmouseover="showTip(event, 'fs8', 11)" class="i">y</span>
}
<span class="k">let</span> <span onmouseout="hideTip(event, 'fs9', 12)" onmouseover="showTip(event, 'fs9', 12)" class="i">example</span> <span class="o">=</span> <span onmouseout="hideTip(event, 'fs6', 13)" onmouseover="showTip(event, 'fs6', 13)" class="i">resumable</span> {
<span class="k">let!</span> <span onmouseout="hideTip(event, 'fs10', 14)" onmouseover="showTip(event, 'fs10', 14)" class="i">x</span> <span class="o">=</span> <span onmouseout="hideTip(event, 'fs6', 15)" onmouseover="showTip(event, 'fs6', 15)" class="i">resumable</span> { <span class="k">return</span> <span class="n">1</span> }
<span class="k">let!</span> <span onmouseout="hideTip(event, 'fs8', 16)" onmouseover="showTip(event, 'fs8', 16)" class="i">y</span> <span class="o">=</span> <span onmouseout="hideTip(event, 'fs6', 17)" onmouseover="showTip(event, 'fs6', 17)" class="i">resumable</span> { <span class="k">return</span> <span class="n">2</span> }
<span class="k">return</span> <span onmouseout="hideTip(event, 'fs10', 18)" onmouseover="showTip(event, 'fs10', 18)" class="i">x</span> <span class="o">+</span> <span onmouseout="hideTip(event, 'fs8', 19)" onmouseover="showTip(event, 'fs8', 19)" class="i">y</span>
}
<span class="k">let</span> <span onmouseout="hideTip(event, 'fs11', 20)" onmouseover="showTip(event, 'fs11', 20)" class="i">example2</span> <span class="o">=</span> <span onmouseout="hideTip(event, 'fs6', 21)" onmouseover="showTip(event, 'fs6', 21)" class="i">resumable</span> {
<span class="k">let!</span> <span onmouseout="hideTip(event, 'fs10', 22)" onmouseover="showTip(event, 'fs10', 22)" class="i">x</span> <span class="o">=</span> <span onmouseout="hideTip(event, 'fs9', 23)" onmouseover="showTip(event, 'fs9', 23)" class="i">example</span>
<span class="k">let!</span> <span onmouseout="hideTip(event, 'fs8', 24)" onmouseover="showTip(event, 'fs8', 24)" class="i">y</span> <span class="o">=</span> <span onmouseout="hideTip(event, 'fs6', 25)" onmouseover="showTip(event, 'fs6', 25)" class="i">resumable</span> { <span class="k">return</span> <span class="n">3</span> }
<span class="k">return</span> <span onmouseout="hideTip(event, 'fs10', 26)" onmouseover="showTip(event, 'fs10', 26)" class="i">x</span> <span class="o">+</span> <span onmouseout="hideTip(event, 'fs8', 27)" onmouseover="showTip(event, 'fs8', 27)" class="i">y</span>
}
<span onmouseout="hideTip(event, 'fs9', 28)" onmouseover="showTip(event, 'fs9', 28)" class="i">example</span><span class="o">.</span><span onmouseout="hideTip(event, 'fs12', 29)" onmouseover="showTip(event, 'fs12', 29)" class="f">resume</span> <span class="o"><|</span> (<span onmouseout="hideTip(event, 'fs13', 30)" onmouseover="showTip(event, 'fs13', 30)" class="p">None</span>, <span onmouseout="hideTip(event, 'fs13', 31)" onmouseover="showTip(event, 'fs13', 31)" class="p">None</span>)
<span onmouseout="hideTip(event, 'fs9', 32)" onmouseover="showTip(event, 'fs9', 32)" class="i">example</span><span class="o">.</span><span onmouseout="hideTip(event, 'fs12', 33)" onmouseover="showTip(event, 'fs12', 33)" class="f">resume</span> <span class="o"><|</span> (<span onmouseout="hideTip(event, 'fs13', 34)" onmouseover="showTip(event, 'fs13', 34)" class="p">None</span>, <span onmouseout="hideTip(event, 'fs14', 35)" onmouseover="showTip(event, 'fs14', 35)" class="p">Some</span> <span class="n">4</span>)
<span onmouseout="hideTip(event, 'fs11', 36)" onmouseover="showTip(event, 'fs11', 36)" class="i">example2</span><span class="o">.</span><span onmouseout="hideTip(event, 'fs12', 37)" onmouseover="showTip(event, 'fs12', 37)" class="f">resume</span> <span class="o"><|</span> (<span onmouseout="hideTip(event, 'fs13', 38)" onmouseover="showTip(event, 'fs13', 38)" class="p">None</span>, (<span onmouseout="hideTip(event, 'fs13', 39)" onmouseover="showTip(event, 'fs13', 39)" class="p">None</span>,<span onmouseout="hideTip(event, 'fs13', 40)" onmouseover="showTip(event, 'fs13', 40)" class="p">None</span>), <span onmouseout="hideTip(event, 'fs13', 41)" onmouseover="showTip(event, 'fs13', 41)" class="p">None</span>)
<span onmouseout="hideTip(event, 'fs11', 42)" onmouseover="showTip(event, 'fs11', 42)" class="i">example2</span><span class="o">.</span><span onmouseout="hideTip(event, 'fs12', 43)" onmouseover="showTip(event, 'fs12', 43)" class="f">resume</span> <span class="o"><|</span> (<span onmouseout="hideTip(event, 'fs14', 44)" onmouseover="showTip(event, 'fs14', 44)" class="p">Some</span> <span class="n">3</span>, (<span onmouseout="hideTip(event, 'fs13', 45)" onmouseover="showTip(event, 'fs13', 45)" class="p">None</span>,<span onmouseout="hideTip(event, 'fs13', 46)" onmouseover="showTip(event, 'fs13', 46)" class="p">None</span>), <span onmouseout="hideTip(event, 'fs14', 47)" onmouseover="showTip(event, 'fs14', 47)" class="p">Some</span> <span class="n">4</span>)
<span onmouseout="hideTip(event, 'fs9', 48)" onmouseover="showTip(event, 'fs9', 48)" class="i">example</span><span class="o">.</span><span onmouseout="hideTip(event, 'fs12', 49)" onmouseover="showTip(event, 'fs12', 49)" class="f">resume</span> <span class="o"><|</span> <span onmouseout="hideTip(event, 'fs2', 50)" onmouseover="showTip(event, 'fs2', 50)" class="t">Zero</span><span class="o">.</span><span onmouseout="hideTip(event, 'fs15', 51)" onmouseover="showTip(event, 'fs15', 51)" class="i">getZeroTyped</span><span class="o"><</span>_<span class="o">></span>
</code></pre></td>
</tr>
</table>
<h2>While loop</h2>
<table class="pre"><tr><td class="lines"><pre class="fssnip"><span class="l"> 1: </span>
<span class="l"> 2: </span>
<span class="l"> 3: </span>
<span class="l"> 4: </span>
<span class="l"> 5: </span>
<span class="l"> 6: </span>
<span class="l"> 7: </span>
<span class="l"> 8: </span>
<span class="l"> 9: </span>
<span class="l">10: </span>
<span class="l">11: </span>
<span class="l">12: </span>
<span class="l">13: </span>
</pre></td>
<td class="snippet"><pre class="fssnip highlighted"><code lang="fsharp"><span class="k">module</span> <span class="t">WhileTest</span> <span class="o">=</span>
<span class="k">let</span> <span onmouseout="hideTip(event, 'fs16', 52)" onmouseover="showTip(event, 'fs16', 52)" class="v">x</span> <span class="o">=</span> <span onmouseout="hideTip(event, 'fs17', 53)" onmouseover="showTip(event, 'fs17', 53)" class="f">ref</span> <span class="n">0</span>
<span class="k">let</span> <span onmouseout="hideTip(event, 'fs18', 54)" onmouseover="showTip(event, 'fs18', 54)" class="i">m</span> <span class="o">=</span>
<span onmouseout="hideTip(event, 'fs6', 55)" onmouseover="showTip(event, 'fs6', 55)" class="i">resumable</span> {
<span onmouseout="hideTip(event, 'fs19', 56)" onmouseover="showTip(event, 'fs19', 56)" class="f">printfn</span> <span class="s">"Start"</span>
<span class="k">while</span> <span class="o">!</span><span onmouseout="hideTip(event, 'fs16', 57)" onmouseover="showTip(event, 'fs16', 57)" class="v">x</span><span class="o"><</span><span class="n">3</span> <span class="k">do</span>
<span onmouseout="hideTip(event, 'fs19', 58)" onmouseover="showTip(event, 'fs19', 58)" class="f">printfn</span> <span class="s">"x = </span><span class="pf">%d</span><span class="s">"</span> <span class="o">!</span><span onmouseout="hideTip(event, 'fs16', 59)" onmouseover="showTip(event, 'fs16', 59)" class="v">x</span>
<span onmouseout="hideTip(event, 'fs20', 60)" onmouseover="showTip(event, 'fs20', 60)" class="f">incr</span> <span onmouseout="hideTip(event, 'fs16', 61)" onmouseover="showTip(event, 'fs16', 61)" class="v">x</span>
<span onmouseout="hideTip(event, 'fs19', 62)" onmouseover="showTip(event, 'fs19', 62)" class="f">printfn</span> <span class="s">"end"</span>
<span class="k">return</span> <span class="o">!</span><span onmouseout="hideTip(event, 'fs16', 63)" onmouseover="showTip(event, 'fs16', 63)" class="v">x</span> , <span class="k">true</span>
}
<span class="k">let</span> <span onmouseout="hideTip(event, 'fs21', 64)" onmouseover="showTip(event, 'fs21', 64)" class="i">s1</span> <span class="o">=</span> <span onmouseout="hideTip(event, 'fs18', 65)" onmouseover="showTip(event, 'fs18', 65)" class="i">m</span><span class="o">.</span><span onmouseout="hideTip(event, 'fs22', 66)" onmouseover="showTip(event, 'fs22', 66)" class="f">resume</span> (<span onmouseout="hideTip(event, 'fs2', 67)" onmouseover="showTip(event, 'fs2', 67)" class="t">Zero</span><span class="o">.</span><span onmouseout="hideTip(event, 'fs15', 68)" onmouseover="showTip(event, 'fs15', 68)" class="i">getZeroTyped</span><span class="o"><</span>_<span class="o">></span>)
</code></pre></td>
</tr>
</table>
<h2>Another while loop</h2>
<table class="pre"><tr><td class="lines"><pre class="fssnip"><span class="l"> 1: </span>
<span class="l"> 2: </span>
<span class="l"> 3: </span>
<span class="l"> 4: </span>
<span class="l"> 5: </span>
<span class="l"> 6: </span>
<span class="l"> 7: </span>
<span class="l"> 8: </span>
<span class="l"> 9: </span>
<span class="l">10: </span>
<span class="l">11: </span>
</pre></td>
<td class="snippet"><pre class="fssnip highlighted"><code lang="fsharp"><span class="k">module</span> <span class="t">WhileTest2</span> <span class="o">=</span>
<span class="k">let</span> <span onmouseout="hideTip(event, 'fs23', 69)" onmouseover="showTip(event, 'fs23', 69)" class="i">m2</span> <span class="o">=</span>
<span onmouseout="hideTip(event, 'fs6', 70)" onmouseover="showTip(event, 'fs6', 70)" class="i">resumable</span> {
<span onmouseout="hideTip(event, 'fs19', 71)" onmouseover="showTip(event, 'fs19', 71)" class="f">printfn</span> <span class="s">"Start m2"</span>
<span class="k">let!</span> <span onmouseout="hideTip(event, 'fs24', 72)" onmouseover="showTip(event, 'fs24', 72)" class="i">z</span>, <span onmouseout="hideTip(event, 'fs25', 73)" onmouseover="showTip(event, 'fs25', 73)" class="i">f</span> <span class="o">=</span> <span onmouseout="hideTip(event, 'fs26', 74)" onmouseover="showTip(event, 'fs26', 74)" class="t">WhileTest</span><span class="o">.</span><span onmouseout="hideTip(event, 'fs18', 75)" onmouseover="showTip(event, 'fs18', 75)" class="i">m</span>
<span onmouseout="hideTip(event, 'fs19', 76)" onmouseover="showTip(event, 'fs19', 76)" class="f">printfn</span> <span class="s">"end m2"</span>
<span class="k">return</span> <span onmouseout="hideTip(event, 'fs24', 77)" onmouseover="showTip(event, 'fs24', 77)" class="i">z</span><span class="o">+</span> <span class="n">100</span>
}
<span class="k">let</span> <span onmouseout="hideTip(event, 'fs27', 78)" onmouseover="showTip(event, 'fs27', 78)" class="i">s1</span> <span class="o">=</span> <span onmouseout="hideTip(event, 'fs23', 79)" onmouseover="showTip(event, 'fs23', 79)" class="i">m2</span><span class="o">.</span><span onmouseout="hideTip(event, 'fs12', 80)" onmouseover="showTip(event, 'fs12', 80)" class="f">resume</span> (<span onmouseout="hideTip(event, 'fs2', 81)" onmouseover="showTip(event, 'fs2', 81)" class="t">Zero</span><span class="o">.</span><span onmouseout="hideTip(event, 'fs15', 82)" onmouseover="showTip(event, 'fs15', 82)" class="i">getZeroTyped</span><span class="o"><</span>_<span class="o">></span>)
<span class="k">let</span> <span onmouseout="hideTip(event, 'fs28', 83)" onmouseover="showTip(event, 'fs28', 83)" class="i">s2</span> <span class="o">=</span> <span onmouseout="hideTip(event, 'fs23', 84)" onmouseover="showTip(event, 'fs23', 84)" class="i">m2</span><span class="o">.</span><span onmouseout="hideTip(event, 'fs12', 85)" onmouseover="showTip(event, 'fs12', 85)" class="f">resume</span> (<span onmouseout="hideTip(event, 'fs14', 86)" onmouseover="showTip(event, 'fs14', 86)" class="p">Some</span> (<span class="n">54</span>,<span class="k">true</span>))
</code></pre></td>
</tr>
</table>
<h2>Resumable service request handler</h2>
<table class="pre"><tr><td class="lines"><pre class="fssnip"><span class="l"> 1: </span>
<span class="l"> 2: </span>
<span class="l"> 3: </span>
<span class="l"> 4: </span>
<span class="l"> 5: </span>
<span class="l"> 6: </span>
<span class="l"> 7: </span>
<span class="l"> 8: </span>
<span class="l"> 9: </span>
<span class="l">10: </span>
<span class="l">11: </span>
<span class="l">12: </span>
<span class="l">13: </span>
<span class="l">14: </span>
<span class="l">15: </span>
<span class="l">16: </span>
<span class="l">17: </span>
<span class="l">18: </span>
<span class="l">19: </span>
<span class="l">20: </span>
<span class="l">21: </span>
<span class="l">22: </span>
<span class="l">23: </span>
<span class="l">24: </span>
<span class="l">25: </span>
<span class="l">26: </span>
<span class="l">27: </span>
<span class="l">28: </span>
<span class="l">29: </span>
<span class="l">30: </span>
<span class="l">31: </span>
<span class="l">32: </span>
<span class="l">33: </span>
<span class="l">34: </span>
<span class="l">35: </span>
<span class="l">36: </span>
<span class="l">37: </span>
<span class="l">38: </span>
<span class="l">39: </span>
<span class="l">40: </span>
<span class="l">41: </span>
<span class="l">42: </span>
<span class="l">43: </span>
<span class="l">44: </span>
<span class="l">45: </span>
<span class="l">46: </span>
<span class="l">47: </span>
<span class="l">48: </span>
<span class="l">49: </span>
<span class="l">50: </span>
<span class="l">51: </span>
<span class="l">52: </span>
<span class="l">53: </span>
<span class="l">54: </span>
<span class="l">55: </span>
</pre></td>
<td class="snippet"><pre class="fssnip highlighted"><code lang="fsharp"><span class="k">module</span> <span onmouseout="hideTip(event, 'fs32', 106)" onmouseover="showTip(event, 'fs32', 106)" class="t">MyResumableService</span> <span class="o">=</span>
<span class="k">module</span> <span class="t">Environment</span> <span class="o">=</span>
<span class="c">(**</span>
<span class="c"> First we need a function called by our service to</span>
<span class="c"> retrieve the details of the request (such as machine name, type of the machine, ...)</span>
<span class="c"> For simplicity here we will assume it's just a machine name.</span>
<span class="c"> *)</span>
<span class="k">let</span> <span onmouseout="hideTip(event, 'fs33', 107)" onmouseover="showTip(event, 'fs33', 107)" class="f">getMachineName</span> () <span class="o">=</span>
<span onmouseout="hideTip(event, 'fs19', 108)" onmouseover="showTip(event, 'fs19', 108)" class="f">printfn</span> <span class="s">"Enter name of machine: "</span>
<span class="k">let</span> <span onmouseout="hideTip(event, 'fs34', 109)" onmouseover="showTip(event, 'fs34', 109)" class="i">machineName</span> <span class="o">=</span> <span onmouseout="hideTip(event, 'fs35', 110)" onmouseover="showTip(event, 'fs35', 110)" class="i">System</span><span class="o">.</span><span onmouseout="hideTip(event, 'fs36', 111)" onmouseover="showTip(event, 'fs36', 111)" class="t">Console</span><span class="o">.</span><span onmouseout="hideTip(event, 'fs37', 112)" onmouseover="showTip(event, 'fs37', 112)" class="f">ReadLine</span>()
<span onmouseout="hideTip(event, 'fs34', 113)" onmouseover="showTip(event, 'fs34', 113)" class="i">machineName</span>
<span class="c">(**</span>
<span class="c"> Now let's define a simple model of the cloud service API used to</span>
<span class="c"> provision new virtual machines. The function below is just a mockup for the real API: it returns</span>
<span class="c"> a random number representing the request ID created by the cloud VM provider.</span>
<span class="c"> *)</span>
<span class="k">let</span> <span onmouseout="hideTip(event, 'fs38', 114)" onmouseover="showTip(event, 'fs38', 114)" class="f">provisionVM</span> <span onmouseout="hideTip(event, 'fs34', 115)" onmouseover="showTip(event, 'fs34', 115)" class="i">machineName</span> <span class="o">=</span>
<span class="k">let</span> <span onmouseout="hideTip(event, 'fs39', 116)" onmouseover="showTip(event, 'fs39', 116)" class="i">requestId</span> <span class="o">=</span> <span onmouseout="hideTip(event, 'fs35', 117)" onmouseover="showTip(event, 'fs35', 117)" class="i">System</span><span class="o">.</span><span onmouseout="hideTip(event, 'fs40', 118)" onmouseover="showTip(event, 'fs40', 118)" class="t">Random</span>()<span class="o">.</span><span class="f">Next</span>()
<span onmouseout="hideTip(event, 'fs19', 119)" onmouseover="showTip(event, 'fs19', 119)" class="f">printfn</span> <span class="s">"Provisioning new VM </span><span class="pf">%s</span><span class="s"> in the cloud...."</span> <span onmouseout="hideTip(event, 'fs34', 120)" onmouseover="showTip(event, 'fs34', 120)" class="i">machineName</span>
<span onmouseout="hideTip(event, 'fs19', 121)" onmouseover="showTip(event, 'fs19', 121)" class="f">printfn</span> <span class="s">"Request ID returned from API is: </span><span class="pf">%d</span><span class="s">"</span> <span onmouseout="hideTip(event, 'fs39', 122)" onmouseover="showTip(event, 'fs39', 122)" class="i">requestId</span>
<span onmouseout="hideTip(event, 'fs39', 123)" onmouseover="showTip(event, 'fs39', 123)" class="i">requestId</span>
<span class="c">(**</span>
<span class="c"> Last we model the cloud API that checks the status of a previously issued request.</span>
<span class="c"> To simulate the processing time normally required for such operation to complete</span>
<span class="c"> we count how many times the function was called and after 5 attempts we return 'success'.</span>
<span class="c"> *)</span>
<span class="k">let</span> <span onmouseout="hideTip(event, 'fs41', 124)" onmouseover="showTip(event, 'fs41', 124)" class="f">vmRequestSucceeded</span> <span class="o">=</span>
<span class="k">let</span> <span onmouseout="hideTip(event, 'fs42', 125)" onmouseover="showTip(event, 'fs42', 125)" class="v">waitTime</span> <span class="o">=</span> <span onmouseout="hideTip(event, 'fs17', 126)" onmouseover="showTip(event, 'fs17', 126)" class="f">ref</span> <span class="n">0</span>
<span class="k">let</span> <span class="k">rec</span> <span onmouseout="hideTip(event, 'fs43', 127)" onmouseover="showTip(event, 'fs43', 127)" class="f">aux</span> <span onmouseout="hideTip(event, 'fs39', 128)" onmouseover="showTip(event, 'fs39', 128)" class="i">requestId</span> <span class="o">=</span>
<span onmouseout="hideTip(event, 'fs19', 129)" onmouseover="showTip(event, 'fs19', 129)" class="f">printfn</span> <span class="s">"checking status of request </span><span class="pf">%d</span><span class="s"> (waitTime: </span><span class="pf">%d</span><span class="s">)"</span> <span onmouseout="hideTip(event, 'fs39', 130)" onmouseover="showTip(event, 'fs39', 130)" class="i">requestId</span> <span class="o">!</span><span onmouseout="hideTip(event, 'fs42', 131)" onmouseover="showTip(event, 'fs42', 131)" class="v">waitTime</span>
<span onmouseout="hideTip(event, 'fs42', 132)" onmouseover="showTip(event, 'fs42', 132)" class="v">waitTime</span> <span class="o">:=</span> (<span class="o">!</span><span onmouseout="hideTip(event, 'fs42', 133)" onmouseover="showTip(event, 'fs42', 133)" class="v">waitTime</span> <span class="o">+</span> <span class="n">1</span>) <span class="o">%</span> <span class="n">5</span>
<span class="o">!</span><span onmouseout="hideTip(event, 'fs42', 134)" onmouseover="showTip(event, 'fs42', 134)" class="v">waitTime</span> <span class="o">=</span> <span class="n">0</span>
<span onmouseout="hideTip(event, 'fs43', 135)" onmouseover="showTip(event, 'fs43', 135)" class="f">aux</span>
<span class="k">let</span> <span onmouseout="hideTip(event, 'fs44', 136)" onmouseover="showTip(event, 'fs44', 136)" class="i">myServiceApi</span> <span class="o">=</span>
<span onmouseout="hideTip(event, 'fs6', 137)" onmouseover="showTip(event, 'fs6', 137)" class="i">resumable</span> {
<span class="k">let!</span> <span onmouseout="hideTip(event, 'fs34', 138)" onmouseover="showTip(event, 'fs34', 138)" class="i">machineName</span> <span class="o">=</span> <span onmouseout="hideTip(event, 'fs6', 139)" onmouseover="showTip(event, 'fs6', 139)" class="i">resumable</span> { <span class="k">return</span> <span onmouseout="hideTip(event, 'fs45', 140)" onmouseover="showTip(event, 'fs45', 140)" class="t">Environment</span><span class="o">.</span><span onmouseout="hideTip(event, 'fs33', 141)" onmouseover="showTip(event, 'fs33', 141)" class="f">getMachineName</span> () }
<span class="k">let!</span> <span onmouseout="hideTip(event, 'fs39', 142)" onmouseover="showTip(event, 'fs39', 142)" class="i">requestId</span> <span class="o">=</span> <span onmouseout="hideTip(event, 'fs6', 143)" onmouseover="showTip(event, 'fs6', 143)" class="i">resumable</span> { <span class="k">return</span> <span onmouseout="hideTip(event, 'fs45', 144)" onmouseover="showTip(event, 'fs45', 144)" class="t">Environment</span><span class="o">.</span><span onmouseout="hideTip(event, 'fs38', 145)" onmouseover="showTip(event, 'fs38', 145)" class="f">provisionVM</span> <span onmouseout="hideTip(event, 'fs34', 146)" onmouseover="showTip(event, 'fs34', 146)" class="i">machineName</span> }
<span class="k">let!</span> <span onmouseout="hideTip(event, 'fs46', 147)" onmouseover="showTip(event, 'fs46', 147)" class="i">vmready</span> <span class="o">=</span> <span onmouseout="hideTip(event, 'fs6', 148)" onmouseover="showTip(event, 'fs6', 148)" class="i">resumable</span> {
<span class="k">while</span> <span onmouseout="hideTip(event, 'fs47', 149)" onmouseover="showTip(event, 'fs47', 149)" class="f">not</span> <span class="o"><|</span> <span onmouseout="hideTip(event, 'fs45', 150)" onmouseover="showTip(event, 'fs45', 150)" class="t">Environment</span><span class="o">.</span><span onmouseout="hideTip(event, 'fs41', 151)" onmouseover="showTip(event, 'fs41', 151)" class="f">vmRequestSucceeded</span> <span onmouseout="hideTip(event, 'fs39', 152)" onmouseover="showTip(event, 'fs39', 152)" class="i">requestId</span> <span class="k">do</span>
<span onmouseout="hideTip(event, 'fs19', 153)" onmouseover="showTip(event, 'fs19', 153)" class="f">printfn</span> <span class="s">"Waiting for cloud request to complete..."</span>
<span onmouseout="hideTip(event, 'fs35', 154)" onmouseover="showTip(event, 'fs35', 154)" class="i">System</span><span class="o">.</span><span onmouseout="hideTip(event, 'fs48', 155)" onmouseover="showTip(event, 'fs48', 155)" class="i">Threading</span><span class="o">.</span><span onmouseout="hideTip(event, 'fs49', 156)" onmouseover="showTip(event, 'fs49', 156)" class="t">Thread</span><span class="o">.</span><span onmouseout="hideTip(event, 'fs50', 157)" onmouseover="showTip(event, 'fs50', 157)" class="f">Sleep</span>(<span class="n">1000</span>)
<span class="k">return</span> <span class="k">true</span>
}
<span onmouseout="hideTip(event, 'fs19', 158)" onmouseover="showTip(event, 'fs19', 158)" class="f">printfn</span> <span class="s">"Request completed for machine </span><span class="pf">%s</span><span class="s">!"</span> <span onmouseout="hideTip(event, 'fs34', 159)" onmouseover="showTip(event, 'fs34', 159)" class="i">machineName</span>
<span class="k">return</span> <span onmouseout="hideTip(event, 'fs34', 160)" onmouseover="showTip(event, 'fs34', 160)" class="i">machineName</span>, <span onmouseout="hideTip(event, 'fs39', 161)" onmouseover="showTip(event, 'fs39', 161)" class="i">requestId</span>, <span class="i">vmready</span>
}
<span onmouseout="hideTip(event, 'fs44', 162)" onmouseover="showTip(event, 'fs44', 162)" class="i">myServiceApi</span><span class="o">.</span><span onmouseout="hideTip(event, 'fs12', 163)" onmouseover="showTip(event, 'fs12', 163)" class="f">resume</span> <span class="o"><|</span> <span onmouseout="hideTip(event, 'fs44', 164)" onmouseover="showTip(event, 'fs44', 164)" class="i">myServiceApi</span><span class="o">.</span><span onmouseout="hideTip(event, 'fs51', 165)" onmouseover="showTip(event, 'fs51', 165)" class="i">initial</span>
</code></pre></td>
</tr>
</table>
<div class="tip" id="fs1">module Example</div>
<div class="tip" id="fs2">module Zero</div>
<div class="tip" id="fs3">namespace ResumableMonad</div>
<div class="tip" id="fs4">module Multipstep<br /><br />from ResumableMonad<br /><em><br /><br /> Multistep resumable monad where a resumable expression is encoded as a <br /> mapping from the trace history type 'h to the expression's return type 't.</em></div>
<div class="tip" id="fs5">val x1 : Resumable<int><br /><br />Full name: Example.x1</div>
<div class="tip" id="fs6">val resumable : ResumableBuilder<br /><br />Full name: ResumableMonad.Multipstep.resumable</div>
<div class="tip" id="fs7">val x2 : Resumable<int option,int><br /><br />Full name: Example.x2</div>
<div class="tip" id="fs8">val y : int</div>
<div class="tip" id="fs9">val example : Resumable<(int option * int option),int><br /><br />Full name: Example.example</div>
<div class="tip" id="fs10">val x : int</div>
<div class="tip" id="fs11">val example2 : Resumable<(int option * (int option * int option) * int option),int><br /><br />Full name: Example.example2</div>
<div class="tip" id="fs12">member Resumable.resume : h:'h -> 't</div>
<div class="tip" id="fs13">union case Option.None: Option<'T></div>
<div class="tip" id="fs14">union case Option.Some: Value: 'T -> Option<'T></div>
<div class="tip" id="fs15">val getZeroTyped<'X> : 'X<br /><br />Full name: Zero.getZeroTyped</div>
<div class="tip" id="fs16">val x : int ref<br /><br />Full name: Example.WhileTest.x</div>
<div class="tip" id="fs17">Multiple items<br />val ref : value:'T -> 'T ref<br /><br />Full name: Microsoft.FSharp.Core.Operators.ref<br /><br />--------------------<br />type 'T ref = Ref<'T><br /><br />Full name: Microsoft.FSharp.Core.ref<_></div>
<div class="tip" id="fs18">val m : Resumable<int * bool><br /><br />Full name: Example.WhileTest.m</div>
<div class="tip" id="fs19">val printfn : format:Printf.TextWriterFormat<'T> -> 'T<br /><br />Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn</div>
<div class="tip" id="fs20">val incr : cell:int ref -> unit<br /><br />Full name: Microsoft.FSharp.Core.Operators.incr</div>
<div class="tip" id="fs21">val s1 : int * bool<br /><br />Full name: Example.WhileTest.s1</div>
<div class="tip" id="fs22">property Resumable.resume: unit -> int * bool</div>
<div class="tip" id="fs23">val m2 : Resumable<(int * bool) option,int><br /><br />Full name: Example.WhileTest2.m2</div>
<div class="tip" id="fs24">val z : int</div>
<div class="tip" id="fs25">val f : bool</div>
<div class="tip" id="fs26">module WhileTest<br /><br />from Example</div>
<div class="tip" id="fs27">val s1 : int<br /><br />Full name: Example.WhileTest2.s1</div>
<div class="tip" id="fs28">val s2 : int<br /><br />Full name: Example.WhileTest2.s2</div>
<div class="tip" id="fs29">val y : int ref<br /><br />Full name: Example.IfTest.y</div>
<div class="tip" id="fs30">val iftest : Resumable<int * bool><br /><br />Full name: Example.IfTest.iftest</div>
<div class="tip" id="fs31">val s1 : int * bool<br /><br />Full name: Example.IfTest.s1</div>
<div class="tip" id="fs32">module MyResumableService<br /><br />from Example</div>
<div class="tip" id="fs33">val getMachineName : unit -> string<br /><br />Full name: Example.MyResumableService.Environment.getMachineName</div>
<div class="tip" id="fs34">val machineName : string</div>
<div class="tip" id="fs35">namespace System</div>
<div class="tip" id="fs36">type Console =<br />  static member BackgroundColor : ConsoleColor with get, set<br />  static member Beep : unit -> unit + 1 overload<br />  static member BufferHeight : int with get, set<br />  static member BufferWidth : int with get, set<br />  static member CapsLock : bool<br />  static member Clear : unit -> unit<br />  static member CursorLeft : int with get, set<br />  static member CursorSize : int with get, set<br />  static member CursorTop : int with get, set<br />  static member CursorVisible : bool with get, set<br />  ...<br /><br />Full name: System.Console</div>
<div class="tip" id="fs37">System.Console.ReadLine() : string</div>
<div class="tip" id="fs38">val provisionVM : machineName:string -> int<br /><br />Full name: Example.MyResumableService.Environment.provisionVM</div>
<div class="tip" id="fs39">val requestId : int</div>
<div class="tip" id="fs40">Multiple items<br />type Random =<br />  new : unit -> Random + 1 overload<br />  member Next : unit -> int + 2 overloads<br />  member NextBytes : buffer:byte[] -> unit<br />  member NextDouble : unit -> float<br /><br />Full name: System.Random<br /><br />--------------------<br />System.Random() : unit<br />System.Random(Seed: int) : unit</div>
<div class="tip" id="fs41">val vmRequestSucceeded : (int -> bool)<br /><br />Full name: Example.MyResumableService.Environment.vmRequestSucceeded</div>
<div class="tip" id="fs42">val waitTime : int ref</div>
<div class="tip" id="fs43">val aux : (int -> bool)</div>
<div class="tip" id="fs44">val myServiceApi : Resumable<(string option * (int option * bool option)),(string * int * bool)><br /><br />Full name: Example.MyResumableService.myServiceApi</div>
<div class="tip" id="fs45">module Environment<br /><br />from Example.MyResumableService</div>
<div class="tip" id="fs46">val vmready : bool</div>
<div class="tip" id="fs47">val not : value:bool -> bool<br /><br />Full name: Microsoft.FSharp.Core.Operators.not</div>
<div class="tip" id="fs48">namespace System.Threading</div>
<div class="tip" id="fs49">Multiple items<br />type Thread =<br />  inherit CriticalFinalizerObject<br />  new : start:ThreadStart -> Thread + 3 overloads<br />  member Abort : unit -> unit + 1 overload<br />  member ApartmentState : ApartmentState with get, set<br />  member CurrentCulture : CultureInfo with get, set<br />  member CurrentUICulture : CultureInfo with get, set<br />  member DisableComObjectEagerCleanup : unit -> unit<br />  member ExecutionContext : ExecutionContext<br />  member GetApartmentState : unit -> ApartmentState<br />  member GetCompressedStack : unit -> CompressedStack<br />  member GetHashCode : unit -> int<br />  ...<br /><br />Full name: System.Threading.Thread<br /><br />--------------------<br />System.Threading.Thread(start: System.Threading.ThreadStart) : unit<br />System.Threading.Thread(start: System.Threading.ParameterizedThreadStart) : unit<br />System.Threading.Thread(start: System.Threading.ThreadStart, maxStackSize: int) : unit<br />System.Threading.Thread(start: System.Threading.ParameterizedThreadStart, maxStackSize: int) : unit</div>
<div class="tip" id="fs50">System.Threading.Thread.Sleep(timeout: System.TimeSpan) : unit<br />System.Threading.Thread.Sleep(millisecondsTimeout: int) : unit</div>
<div class="tip" id="fs51">property Resumable.initial: string option * (int option * bool option)<br /><em><br /><br /> Returns the empty history (no caching point are initialized)</em></div>
</div>
<div class="span3">
<ul class="nav nav-list" id="menu">
<li class="nav-header">Resumable Monad</li>
<li><a href="TheResumableMonad.html">The Resumable Monad</a></li>
<li><a href="Examples.html">Examples</a></li>
<li><a href="ResumableMonad.Multistep.html">ResumableMonad.Multistep</a></li>
<li><a href="ResumableMonad.Multistep.Persisted.html">ResumableMonad.Multistep.Persisted</a></li>
<!--
Here you can add links to other pages of the documentation
The 'divider' element creates a separator and additional
'nav-header' can be used to add sub-headings in the menu:
* <li class="divider"></li>
* <li><a href="...">...</a></li>
* <li class="nav-header">Sub-heading</li>
-->
</ul>
</div>
</div>
</div>
<a href="https://github.com/blumu/ResumableMonad/"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_orange_ff7600.png" alt="Fork me on GitHub"></a>
</body>
</html>