ruff 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 91f24bc9d41ba7b08fe795a8dd52ec1cc76b9eb3d9a510310f2eea826627b839
4
- data.tar.gz: a749e0b9e91d890a905f905a02c85981050b1cc557c73d2d8a34fe221cde9283
3
+ metadata.gz: b3a199e337fbcc9469889603567d9c3367d58ce429fd3a486f4fa5b801cd6e1c
4
+ data.tar.gz: faed13c325a06943194fe5d717569793e229dc1ce11dd04cf5fb4d812794de19
5
5
  SHA512:
6
- metadata.gz: 6e902920988c2efb254d735425a2484728a236001d2caa8bdd23adcf6eacca5bc36f848865dac5c58f84dae7a105efe9143b211f2c7e70fd4b7a5edafdd9b386
7
- data.tar.gz: 43c685ac4c07cb91df80e361bc8d3e38e317915f129265bc84866d3133192b73f42e76c09a4aace19296c30781102fbaae8810114d1b46f6c7227dcfa5bcaf49
6
+ metadata.gz: 310c7eb41d54e788c18172bde693d1af6a09cd246e5ebf95fcf7fec03dcce77f9f74750730573327ed8ab928add19b844c92e969e757035ee879da6213b7f44f
7
+ data.tar.gz: b56af686894b243c13b030b4c50aea7575d26d29d8d93d8c6326baff08307b75c4cfea35865d6c498780fbedabbe16bd207dc95bd1a0704cf631cb071bf6e67e
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  ruff
2
2
  ==
3
3
 
4
+ [![Gem Version](https://badge.fury.io/rb/ruff.svg)](https://badge.fury.io/rb/ruff)
5
+
4
6
  ONE-SHOT Algebraic Effects Library for Ruby!
5
7
 
6
8
  ```ruby
@@ -31,8 +33,5 @@ h1.run{
31
33
  # logger: 6
32
34
  ```
33
35
 
34
- # Documentation
35
- See [here](https://nymphium.github.io/ruff/).
36
-
37
36
  # LICENSE
38
37
  MIT
data/docs/Ruff.html CHANGED
@@ -312,7 +312,7 @@ include &quot;../../version.h&quot;</p>
312
312
  </div>
313
313
 
314
314
  <div id="footer">
315
- Generated on Wed Oct 2 22:42:03 2019 by
315
+ Generated on Thu Oct 3 00:38:48 2019 by
316
316
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
317
317
  0.9.20 (ruby-2.6.4).
318
318
  </div>
@@ -404,7 +404,7 @@
404
404
  </div>
405
405
 
406
406
  <div id="footer">
407
- Generated on Wed Oct 2 22:42:03 2019 by
407
+ Generated on Thu Oct 3 00:38:48 2019 by
408
408
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
409
409
  0.9.20 (ruby-2.6.4).
410
410
  </div>
@@ -104,7 +104,17 @@
104
104
 
105
105
  </div>
106
106
 
107
+ <h2>Overview</h2><div class="docstring">
108
+ <div class="discussion">
109
+ <p>In algebraic effects, handler is an first-class object.</p>
110
+
111
+
112
+ </div>
113
+ </div>
114
+ <div class="tags">
115
+
107
116
 
117
+ </div>
108
118
 
109
119
 
110
120
 
@@ -138,7 +148,7 @@
138
148
 
139
149
 
140
150
 
141
- <span class="summary_desc"><div class='inline'><p>In algebraic effects, handler is an first-class object.</p>
151
+ <span class="summary_desc"><div class='inline'><p>makes a new handler, internally having fresh empty hash.</p>
142
152
  </div></span>
143
153
 
144
154
  </li>
@@ -147,7 +157,7 @@
147
157
  <li class="public ">
148
158
  <span class="summary_signature">
149
159
 
150
- <a href="#on-instance_method" title="#on (instance method)">#<strong>on</strong>(eff, &amp;prc) &#x21d2; Handler{Effect&lt;Arg, Ret&gt;, e} </a>
160
+ <a href="#on-instance_method" title="#on (instance method)">#<strong>on</strong>(eff, &amp;fun) &#x21d2; Handler&lt;A!{Effect&lt;Arg, Ret&gt;, e}, B!{e}&gt; </a>
151
161
 
152
162
 
153
163
 
@@ -161,7 +171,7 @@
161
171
 
162
172
 
163
173
 
164
- <span class="summary_desc"><div class='inline'><p>sets effec handler <code>&amp;prc</code> for <code>eff</code>.</p>
174
+ <span class="summary_desc"><div class='inline'><p>sets effec handler <code>&amp;fun</code> for <code>eff</code>.</p>
165
175
  </div></span>
166
176
 
167
177
  </li>
@@ -170,7 +180,7 @@
170
180
  <li class="public ">
171
181
  <span class="summary_signature">
172
182
 
173
- <a href="#run-instance_method" title="#run (instance method)">#<strong>run</strong>(&amp;prc) &#x21d2; T </a>
183
+ <a href="#run-instance_method" title="#run (instance method)">#<strong>run</strong>(&amp;prc) &#x21d2; B </a>
174
184
 
175
185
 
176
186
 
@@ -187,6 +197,29 @@
187
197
  <span class="summary_desc"><div class='inline'><p>handles the computation.</p>
188
198
  </div></span>
189
199
 
200
+ </li>
201
+
202
+
203
+ <li class="public ">
204
+ <span class="summary_signature">
205
+
206
+ <a href="#to-instance_method" title="#to (instance method)">#<strong>to</strong>(&amp;fun) &#x21d2; Handler&lt;A!{e}, B!{e&#39;}&gt; </a>
207
+
208
+
209
+
210
+ </span>
211
+
212
+
213
+
214
+
215
+
216
+
217
+
218
+
219
+
220
+ <span class="summary_desc"><div class='inline'><p>sets value handler <code>&amp;fun</code>.</p>
221
+ </div></span>
222
+
190
223
  </li>
191
224
 
192
225
 
@@ -213,9 +246,10 @@
213
246
 
214
247
  </h3><div class="docstring">
215
248
  <div class="discussion">
216
- <p>In algebraic effects, handler is an first-class object.
217
- makes a new handler, internally having fresh empty hash.
218
- This is a effect-handler store and when handliong it is looked up.</p>
249
+ <p>makes a new handler, internally having fresh empty hash.</p>
250
+
251
+ <p>This is a effect-handler store and when handliong it is looked up.
252
+ Value handler is set <code>id</code> function to by default.</p>
219
253
 
220
254
 
221
255
  </div>
@@ -237,15 +271,17 @@ This is a effect-handler store and when handliong it is looked up.</p>
237
271
  <pre class="lines">
238
272
 
239
273
 
240
- 8
241
- 9
242
- 10</pre>
274
+ 17
275
+ 18
276
+ 19
277
+ 20</pre>
243
278
  </td>
244
279
  <td>
245
- <pre class="code"><span class="info file"># File 'lib/ruff/handler.rb', line 8</span>
280
+ <pre class="code"><span class="info file"># File 'lib/ruff/handler.rb', line 17</span>
246
281
 
247
282
  <span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span>
248
283
  <span class='ivar'>@handlers</span> <span class='op'>=</span> <span class='const'>Hash</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
284
+ <span class='ivar'>@handlers</span><span class='lbracket'>[</span><span class='ivar'>@valh_id</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='tlambda'>-&gt;</span><span class='lparen'>(</span><span class='id identifier rubyid_x'>x</span><span class='rparen'>)</span> <span class='tlambeg'>{</span> <span class='id identifier rubyid_x'>x</span> <span class='rbrace'>}</span>
249
285
  <span class='kw'>end</span></pre>
250
286
  </td>
251
287
  </tr>
@@ -262,7 +298,7 @@ This is a effect-handler store and when handliong it is looked up.</p>
262
298
  <div class="method_details first">
263
299
  <h3 class="signature first" id="on-instance_method">
264
300
 
265
- #<strong>on</strong>(eff, &amp;prc) &#x21d2; <tt><span class='object_link'><a href="" title="Ruff::Handler (class)">Handler</a></span>{<span class='object_link'><a href="Effect.html" title="Ruff::Effect (class)">Effect</a></span>&lt;Arg, Ret&gt;, e}</tt>
301
+ #<strong>on</strong>(eff, &amp;fun) &#x21d2; <tt><span class='object_link'><a href="" title="Ruff::Handler (class)">Handler</a></span>&lt;A!{<span class='object_link'><a href="Effect.html" title="Ruff::Effect (class)">Effect</a></span>&lt;Arg, Ret&gt;, e}, B!{e}&gt;</tt>
266
302
 
267
303
 
268
304
 
@@ -270,7 +306,7 @@ This is a effect-handler store and when handliong it is looked up.</p>
270
306
 
271
307
  </h3><div class="docstring">
272
308
  <div class="discussion">
273
- <p>sets effec handler <code>&amp;prc</code> for <code>eff</code></p>
309
+ <p>sets effec handler <code>&amp;fun</code> for <code>eff</code></p>
274
310
 
275
311
 
276
312
  </div>
@@ -307,7 +343,7 @@ This is a effect-handler store and when handliong it is looked up.</p>
307
343
 
308
344
  <li>
309
345
 
310
- <span class='name'>prc</span>
346
+ <span class='name'>fun</span>
311
347
 
312
348
 
313
349
  <span class='type'>(<tt>Proc&lt;Arg, Ret =&gt; A&gt;</tt>)</span>
@@ -316,7 +352,7 @@ This is a effect-handler store and when handliong it is looked up.</p>
316
352
 
317
353
  &mdash;
318
354
  <div class='inline'><p>a handler to handle <code>eff</code>;
319
- First argument of <code>&amp;prc</code> is <em>continuation</em>, proc object
355
+ First argument of <code>&amp;fun</code> is <em>continuation</em>, proc object
320
356
  to go back to the handled computation.</p>
321
357
  </div>
322
358
 
@@ -330,7 +366,7 @@ to go back to the handled computation.</p>
330
366
  <li>
331
367
 
332
368
 
333
- <span class='type'>(<tt><span class='object_link'><a href="" title="Ruff::Handler (class)">Handler</a></span>{<span class='object_link'><a href="Effect.html" title="Ruff::Effect (class)">Effect</a></span>&lt;Arg, Ret&gt;, e}</tt>)</span>
369
+ <span class='type'>(<tt><span class='object_link'><a href="" title="Ruff::Handler (class)">Handler</a></span>&lt;A!{<span class='object_link'><a href="Effect.html" title="Ruff::Effect (class)">Effect</a></span>&lt;Arg, Ret&gt;, e}, B!{e}&gt;</tt>)</span>
334
370
 
335
371
 
336
372
 
@@ -348,17 +384,17 @@ to go back to the handled computation.</p>
348
384
  <pre class="lines">
349
385
 
350
386
 
351
- 27
352
- 28
353
- 29
354
- 30
355
- 31</pre>
387
+ 79
388
+ 80
389
+ 81
390
+ 82
391
+ 83</pre>
356
392
  </td>
357
393
  <td>
358
- <pre class="code"><span class="info file"># File 'lib/ruff/handler.rb', line 27</span>
394
+ <pre class="code"><span class="info file"># File 'lib/ruff/handler.rb', line 79</span>
359
395
 
360
- <span class='kw'>def</span> <span class='id identifier rubyid_on'>on</span><span class='lparen'>(</span><span class='id identifier rubyid_eff'>eff</span><span class='comma'>,</span> <span class='op'>&amp;</span><span class='id identifier rubyid_prc'>prc</span><span class='rparen'>)</span>
361
- <span class='ivar'>@handlers</span><span class='lbracket'>[</span><span class='id identifier rubyid_eff'>eff</span><span class='period'>.</span><span class='id identifier rubyid_id'>id</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_prc'>prc</span>
396
+ <span class='kw'>def</span> <span class='id identifier rubyid_on'>on</span><span class='lparen'>(</span><span class='id identifier rubyid_eff'>eff</span><span class='comma'>,</span> <span class='op'>&amp;</span><span class='id identifier rubyid_fun'>fun</span><span class='rparen'>)</span>
397
+ <span class='ivar'>@handlers</span><span class='lbracket'>[</span><span class='id identifier rubyid_eff'>eff</span><span class='period'>.</span><span class='id identifier rubyid_id'>id</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_fun'>fun</span>
362
398
 
363
399
  <span class='kw'>self</span>
364
400
  <span class='kw'>end</span></pre>
@@ -370,7 +406,7 @@ to go back to the handled computation.</p>
370
406
  <div class="method_details ">
371
407
  <h3 class="signature " id="run-instance_method">
372
408
 
373
- #<strong>run</strong>(&amp;prc) &#x21d2; <tt>T</tt>
409
+ #<strong>run</strong>(&amp;prc) &#x21d2; <tt>B</tt>
374
410
 
375
411
 
376
412
 
@@ -416,9 +452,13 @@ to go back to the handled computation.</p>
416
452
  <span class='name'>prc</span>
417
453
 
418
454
 
419
- <span class='type'>(<tt>Proc&lt;(), T&gt;</tt>)</span>
455
+ <span class='type'>(<tt>Proc&lt;(), A&gt;</tt>)</span>
456
+
420
457
 
421
458
 
459
+ &mdash;
460
+ <div class='inline'><p>a thunk to be handled and returns <code>A</code></p>
461
+ </div>
422
462
 
423
463
  </li>
424
464
 
@@ -430,10 +470,14 @@ to go back to the handled computation.</p>
430
470
  <li>
431
471
 
432
472
 
433
- <span class='type'>(<tt>T</tt>)</span>
473
+ <span class='type'>(<tt>B</tt>)</span>
434
474
 
435
475
 
436
476
 
477
+ &mdash;
478
+ <div class='inline'><p>a value modified by value handler <code>Proc&lt;A, B&gt;</code> , or returned from the effect handler throwing continuation away</p>
479
+ </div>
480
+
437
481
  </li>
438
482
 
439
483
  </ul>
@@ -444,61 +488,61 @@ to go back to the handled computation.</p>
444
488
  <pre class="lines">
445
489
 
446
490
 
447
- 53
448
- 54
449
- 55
450
- 56
451
- 57
452
- 58
453
- 59
454
- 60
455
- 61
456
- 62
457
- 63
458
- 64
459
- 65
460
- 66
461
- 67
462
- 68
463
- 69
464
- 70
465
- 71
466
- 72
467
- 73
468
- 74
469
- 75
470
- 76
471
- 77
472
- 78
473
- 79
474
- 80
475
- 81
476
- 82
477
- 83
478
- 84
479
- 85
480
- 86
481
- 87
482
- 88
483
- 89
484
- 90
485
- 91
486
- 92
487
- 93
488
- 94
489
- 95
490
- 96
491
- 97
492
- 98
493
- 99
494
- 100
495
- 101
496
- 102
497
- 103
498
- 104</pre>
491
+ 108
492
+ 109
493
+ 110
494
+ 111
495
+ 112
496
+ 113
497
+ 114
498
+ 115
499
+ 116
500
+ 117
501
+ 118
502
+ 119
503
+ 120
504
+ 121
505
+ 122
506
+ 123
507
+ 124
508
+ 125
509
+ 126
510
+ 127
511
+ 128
512
+ 129
513
+ 130
514
+ 131
515
+ 132
516
+ 133
517
+ 134
518
+ 135
519
+ 136
520
+ 137
521
+ 138
522
+ 139
523
+ 140
524
+ 141
525
+ 142
526
+ 143
527
+ 144
528
+ 145
529
+ 146
530
+ 147
531
+ 148
532
+ 149
533
+ 150
534
+ 151
535
+ 152
536
+ 153
537
+ 154
538
+ 155
539
+ 156
540
+ 157
541
+ 158
542
+ 159</pre>
499
543
  </td>
500
544
  <td>
501
- <pre class="code"><span class="info file"># File 'lib/ruff/handler.rb', line 53</span>
545
+ <pre class="code"><span class="info file"># File 'lib/ruff/handler.rb', line 108</span>
502
546
 
503
547
  <span class='kw'>def</span> <span class='id identifier rubyid_run'>run</span><span class='lparen'>(</span><span class='op'>&amp;</span><span class='id identifier rubyid_prc'>prc</span><span class='rparen'>)</span>
504
548
  <span class='id identifier rubyid_co'>co</span> <span class='op'>=</span> <span class='const'>Fiber</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span> <span class='op'>&amp;</span><span class='id identifier rubyid_prc'>prc</span>
@@ -519,7 +563,7 @@ to go back to the handled computation.</p>
519
563
  <span class='const'>Fiber</span><span class='period'>.</span><span class='id identifier rubyid_yield'>yield</span> <span class='lparen'>(</span><span class='const'><span class='object_link'><a href="Throws/Resend.html" title="Ruff::Throws::Resend (class)">Resend</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="Throws/Resend.html#initialize-instance_method" title="Ruff::Throws::Resend#initialize (method)">new</a></span></span> <span class='id identifier rubyid_r'>r</span><span class='comma'>,</span> <span class='id identifier rubyid_rehandles'>rehandles</span><span class='lbracket'>[</span><span class='id identifier rubyid_r'>r</span><span class='period'>.</span><span class='id identifier rubyid_k'>k</span><span class='rbracket'>]</span><span class='rparen'>)</span>
520
564
  <span class='kw'>end</span>
521
565
  <span class='kw'>else</span>
522
- <span class='id identifier rubyid_r'>r</span>
566
+ <span class='ivar'>@handlers</span><span class='lbracket'>[</span><span class='ivar'>@valh_id</span><span class='rbracket'>]</span><span class='period'>.</span><span class='lparen'>(</span><span class='id identifier rubyid_r'>r</span><span class='rparen'>)</span>
523
567
  <span class='kw'>end</span>
524
568
  <span class='rbrace'>}</span>
525
569
 
@@ -555,6 +599,115 @@ to go back to the handled computation.</p>
555
599
  </td>
556
600
  </tr>
557
601
  </table>
602
+ </div>
603
+
604
+ <div class="method_details ">
605
+ <h3 class="signature " id="to-instance_method">
606
+
607
+ #<strong>to</strong>(&amp;fun) &#x21d2; <tt><span class='object_link'><a href="" title="Ruff::Handler (class)">Handler</a></span>&lt;A!{e}, B!{e'}&gt;</tt>
608
+
609
+
610
+
611
+
612
+
613
+ </h3><div class="docstring">
614
+ <div class="discussion">
615
+ <p>sets value handler <code>&amp;fun</code>.</p>
616
+
617
+ <p>Value handler is the handler for <em>the result value of the computation</em>.
618
+ For example, <code>Handler.new.to{|_x| 0}.run { value }</code> results in <code>0</code> .</p>
619
+
620
+ <p>The value handler modifies the result of the call of continuation in effect handlers of the handler.</p>
621
+
622
+
623
+ </div>
624
+ </div>
625
+ <div class="tags">
626
+
627
+ <div class="examples">
628
+ <p class="tag_title">Examples:</p>
629
+
630
+
631
+ <pre class="example code"><code><span class='id identifier rubyid_logs'>logs</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
632
+ <span class='id identifier rubyid_handler'>handler</span><span class='period'>.</span><span class='id identifier rubyid_on'>on</span><span class='lparen'>(</span><span class='const'>Log</span><span class='rparen'>)</span> <span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_k'>k</span><span class='comma'>,</span> <span class='id identifier rubyid_msg'>msg</span><span class='op'>|</span>
633
+ <span class='id identifier rubyid_logs'>logs</span> <span class='op'>&lt;&lt;</span> <span class='id identifier rubyid_msg'>msg</span>
634
+ <span class='id identifier rubyid_k'>k</span><span class='lbracket'>[</span><span class='rbracket'>]</span>
635
+ <span class='rbrace'>}</span><span class='period'>.</span><span class='id identifier rubyid_to'>to</span> <span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_x'>x</span><span class='op'>|</span>
636
+ <span class='id identifier rubyid_logs'>logs</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_log'>log</span><span class='op'>|</span>
637
+ <span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>Logger: </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_log'>log</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span>
638
+ <span class='rbrace'>}</span>
639
+
640
+ <span class='id identifier rubyid_puts'>puts</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>returns </span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_x'>x</span><span class='embexpr_end'>}</span><span class='tstring_end'>&quot;</span></span>
641
+ <span class='rbrace'>}</span>
642
+ <span class='period'>.</span><span class='id identifier rubyid_run'>run</span> <span class='lbrace'>{</span>
643
+ <span class='const'>Log</span><span class='period'>.</span><span class='id identifier rubyid_perform'>perform</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>hello</span><span class='tstring_end'>&quot;</span></span>
644
+ <span class='const'>Log</span><span class='period'>.</span><span class='id identifier rubyid_perform'>perform</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>world</span><span class='tstring_end'>&quot;</span></span>
645
+ <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>!</span><span class='tstring_end'>&quot;</span></span>
646
+ <span class='rbrace'>}</span>
647
+
648
+ <span class='comment'>## ==&gt;
649
+ </span><span class='comment'># msg&gt;&gt; hello
650
+ </span><span class='comment'># msg&gt;&gt; world
651
+ </span><span class='comment'># returns !</span></code></pre>
652
+
653
+ </div>
654
+ <p class="tag_title">Parameters:</p>
655
+ <ul class="param">
656
+
657
+ <li>
658
+
659
+ <span class='name'>fun</span>
660
+
661
+
662
+ <span class='type'>(<tt>Proc&lt;A, B&gt;</tt>)</span>
663
+
664
+
665
+
666
+ &mdash;
667
+ <div class='inline'><p>value handler</p>
668
+ </div>
669
+
670
+ </li>
671
+
672
+ </ul>
673
+
674
+ <p class="tag_title">Returns:</p>
675
+ <ul class="return">
676
+
677
+ <li>
678
+
679
+
680
+ <span class='type'>(<tt><span class='object_link'><a href="" title="Ruff::Handler (class)">Handler</a></span>&lt;A!{e}, B!{e'}&gt;</tt>)</span>
681
+
682
+
683
+
684
+ </li>
685
+
686
+ </ul>
687
+
688
+ </div><table class="source_code">
689
+ <tr>
690
+ <td>
691
+ <pre class="lines">
692
+
693
+
694
+ 57
695
+ 58
696
+ 59
697
+ 60
698
+ 61</pre>
699
+ </td>
700
+ <td>
701
+ <pre class="code"><span class="info file"># File 'lib/ruff/handler.rb', line 57</span>
702
+
703
+ <span class='kw'>def</span> <span class='id identifier rubyid_to'>to</span><span class='lparen'>(</span><span class='op'>&amp;</span><span class='id identifier rubyid_fun'>fun</span><span class='rparen'>)</span>
704
+ <span class='ivar'>@handlers</span><span class='lbracket'>[</span><span class='ivar'>@valh_id</span><span class='rbracket'>]</span> <span class='op'>=</span> <span class='id identifier rubyid_fun'>fun</span>
705
+
706
+ <span class='kw'>self</span>
707
+ <span class='kw'>end</span></pre>
708
+ </td>
709
+ </tr>
710
+ </table>
558
711
  </div>
559
712
 
560
713
  </div>
@@ -562,7 +715,7 @@ to go back to the handled computation.</p>
562
715
  </div>
563
716
 
564
717
  <div id="footer">
565
- Generated on Wed Oct 2 22:42:03 2019 by
718
+ Generated on Thu Oct 3 00:38:48 2019 by
566
719
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
567
720
  0.9.20 (ruby-2.6.4).
568
721
  </div>
@@ -110,7 +110,7 @@
110
110
  </div>
111
111
 
112
112
  <div id="footer">
113
- Generated on Wed Oct 2 22:42:03 2019 by
113
+ Generated on Thu Oct 3 00:38:48 2019 by
114
114
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
115
115
  0.9.20 (ruby-2.6.4).
116
116
  </div>
@@ -353,7 +353,7 @@
353
353
  </div>
354
354
 
355
355
  <div id="footer">
356
- Generated on Wed Oct 2 22:42:03 2019 by
356
+ Generated on Thu Oct 3 00:38:48 2019 by
357
357
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
358
358
  0.9.20 (ruby-2.6.4).
359
359
  </div>
@@ -353,7 +353,7 @@
353
353
  </div>
354
354
 
355
355
  <div id="footer">
356
- Generated on Wed Oct 2 22:42:03 2019 by
356
+ Generated on Thu Oct 3 00:38:48 2019 by
357
357
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
358
358
  0.9.20 (ruby-2.6.4).
359
359
  </div>
data/docs/_index.html CHANGED
@@ -156,7 +156,7 @@
156
156
  </div>
157
157
 
158
158
  <div id="footer">
159
- Generated on Wed Oct 2 22:42:03 2019 by
159
+ Generated on Thu Oct 3 00:38:48 2019 by
160
160
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
161
161
  0.9.20 (ruby-2.6.4).
162
162
  </div>
@@ -59,6 +59,8 @@
59
59
 
60
60
  <div id="content"><div id='filecontents'><h1>ruff</h1>
61
61
 
62
+ <p><a href="https://badge.fury.io/rb/ruff"><img src="https://badge.fury.io/rb/ruff.svg" alt="Gem Version"></a></p>
63
+
62
64
  <p>ONE-SHOT Algebraic Effects Library for Ruby!</p>
63
65
 
64
66
  <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>ruff</span><span class='tstring_end'>&quot;</span></span>
@@ -98,7 +100,7 @@
98
100
  </div></div>
99
101
 
100
102
  <div id="footer">
101
- Generated on Wed Oct 2 22:42:03 2019 by
103
+ Generated on Thu Oct 3 00:38:48 2019 by
102
104
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
103
105
  0.9.20 (ruby-2.6.4).
104
106
  </div>
data/docs/index.html CHANGED
@@ -59,6 +59,8 @@
59
59
 
60
60
  <div id="content"><div id='filecontents'><h1>ruff</h1>
61
61
 
62
+ <p><a href="https://badge.fury.io/rb/ruff"><img src="https://badge.fury.io/rb/ruff.svg" alt="Gem Version"></a></p>
63
+
62
64
  <p>ONE-SHOT Algebraic Effects Library for Ruby!</p>
63
65
 
64
66
  <pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>&quot;</span><span class='tstring_content'>ruff</span><span class='tstring_end'>&quot;</span></span>
@@ -98,7 +100,7 @@
98
100
  </div></div>
99
101
 
100
102
  <div id="footer">
101
- Generated on Wed Oct 2 22:42:03 2019 by
103
+ Generated on Thu Oct 3 00:38:48 2019 by
102
104
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
103
105
  0.9.20 (ruby-2.6.4).
104
106
  </div>
@@ -156,6 +156,14 @@
156
156
  </li>
157
157
 
158
158
 
159
+ <li class="odd ">
160
+ <div class="item">
161
+ <span class='object_link'><a href="Ruff/Handler.html#to-instance_method" title="Ruff::Handler#to (method)">#to</a></span>
162
+ <small>Ruff::Handler</small>
163
+ </div>
164
+ </li>
165
+
166
+
159
167
 
160
168
  </ul>
161
169
  </div>
@@ -100,7 +100,7 @@
100
100
  </div>
101
101
 
102
102
  <div id="footer">
103
- Generated on Wed Oct 2 22:42:03 2019 by
103
+ Generated on Thu Oct 3 00:38:48 2019 by
104
104
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
105
105
  0.9.20 (ruby-2.6.4).
106
106
  </div>
data/lib/ruff/handler.rb CHANGED
@@ -1,40 +1,94 @@
1
+ require 'securerandom'
2
+
3
+ # In algebraic effects, handler is an first-class object.
1
4
  class Ruff::Handler
2
5
  include Ruff::Throws
3
- # In algebraic effects, handler is an first-class object.
6
+
7
+ @valh_id = SecureRandom.uuid
8
+
4
9
  # makes a new handler, internally having fresh empty hash.
10
+ #
5
11
  # This is a effect-handler store and when handliong it is looked up.
12
+ # Value handler is set `id` function to by default.
13
+ #
6
14
  # @example
7
15
  # handler = Handler.new
16
+
8
17
  def initialize
9
18
  @handlers = Hash.new
19
+ @handlers[@valh_id] = ->(x) { x }
20
+ end
21
+
22
+
23
+ # sets value handler `&fun`.
24
+ #
25
+ # Value handler is the handler for *the result value of the computation*.
26
+ # For example, `Handler.new.to{|_x| 0}.run { value }` results in `0` .
27
+ #
28
+ # The value handler modifies the result of the call of continuation in effect handlers of the handler.
29
+ #
30
+ # @param [Proc<A, B>] fun
31
+ # value handler
32
+ # @return [Handler<A!{e}, B!{e'}>]
33
+ #
34
+ # @example
35
+ # logs = []
36
+ # handler.on(Log) {|k, msg|
37
+ # logs << msg
38
+ # k[]
39
+ # }.to {|x|
40
+ # logs.each {|log|
41
+ # puts "Logger: #{log}"
42
+ # }
43
+ #
44
+ # puts "returns #{x}"
45
+ # }
46
+ # .run {
47
+ # Log.perform "hello"
48
+ # Log.perform "world"
49
+ # "!"
50
+ # }
51
+ #
52
+ # ## ==>
53
+ # # msg>> hello
54
+ # # msg>> world
55
+ # # returns !
56
+
57
+ def to(&fun)
58
+ @handlers[@valh_id] = fun
59
+
60
+ self
10
61
  end
11
62
 
12
- # sets effec handler `&prc` for `eff`
63
+ # sets effec handler `&fun` for `eff`
13
64
  #
14
65
  # @param [Effect<Arg, Ret>] eff
15
66
  # the effect instance to be handled
16
- # @param [Proc<Arg, Ret => A>] prc
67
+ # @param [Proc<Arg, Ret => A>] fun
17
68
  # a handler to handle `eff`;
18
- # First argument of `&prc` is *continuation*, proc object
69
+ # First argument of `&fun` is *continuation*, proc object
19
70
  # to go back to the handled computation.
20
- # @return [Handler{Effect<Arg, Ret>, e}] itself updated with handling `Effect<Arg, Ret>`
71
+ # @return [Handler<A!{Effect<Arg, Ret>, e}, B!{e}>] itself updated with handling `Effect<Arg, Ret>`
21
72
  #
22
73
  # @example
23
74
  # handler.on(Log) {|k, msg|
24
75
  # puts "Logger: #{msg}"
25
76
  # k[]
26
77
  # }
27
- def on(eff, &prc)
28
- @handlers[eff.id] = prc
78
+
79
+ def on(eff, &fun)
80
+ @handlers[eff.id] = fun
29
81
 
30
82
  self
31
83
  end
32
84
 
33
- # @param [Proc<(), T>] prc
34
- # @return [T]
35
- #
36
85
  # handles the computation.
37
86
  #
87
+ # @param [Proc<(), A>] prc
88
+ # a thunk to be handled and returns `A`
89
+ # @return [B]
90
+ # a value modified by value handler `Proc<A, B>` , or returned from the effect handler throwing continuation away
91
+ #
38
92
  # @example
39
93
  # handler.run {
40
94
  # Log.perform "hello"
@@ -50,6 +104,7 @@ class Ruff::Handler
50
104
  # Log.perform 3
51
105
  # }
52
106
  # }
107
+
53
108
  def run(&prc)
54
109
  co = Fiber.new &prc
55
110
  continue = nil
@@ -69,7 +124,7 @@ class Ruff::Handler
69
124
  Fiber.yield (Resend.new r, rehandles[r.k])
70
125
  end
71
126
  else
72
- r
127
+ @handlers[@valh_id].(r)
73
128
  end
74
129
  }
75
130
 
data/lib/ruff/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ruff
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
data/ruff.gemspec CHANGED
@@ -24,6 +24,6 @@ Gem::Specification.new{|spec|
24
24
  spec.add_development_dependency "rake", "~> 10.0"
25
25
 
26
26
  spec.metadata = {
27
- "documentation_url" => "https://nymphium.github.io/ruff"
27
+ "documentation_uri" => "https://nymphium.github.io/ruff"
28
28
  }
29
29
  }
data/version.h CHANGED
@@ -1 +1 @@
1
- #define RUFF_VERSION "0.0.6"
1
+ #define RUFF_VERSION "0.0.7"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - nymphium
@@ -83,7 +83,7 @@ homepage: https://github.com/nymphium/ruff
83
83
  licenses:
84
84
  - MIT
85
85
  metadata:
86
- documentation_url: https://nymphium.github.io/ruff
86
+ documentation_uri: https://nymphium.github.io/ruff
87
87
  post_install_message:
88
88
  rdoc_options: []
89
89
  require_paths: