-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatom.xml
2258 lines (1858 loc) · 179 KB
/
atom.xml
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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title><![CDATA[while true live]]></title>
<link href="http://sleepomeno.github.io/atom.xml" rel="self"/>
<link href="http://sleepomeno.github.io/"/>
<updated>2018-01-15T22:14:21+01:00</updated>
<id>http://sleepomeno.github.io/</id>
<author>
<name><![CDATA[Gregor Riegler]]></name>
</author>
<generator uri="http://octopress.org/">Octopress</generator>
<entry>
<title type="html"><![CDATA[Rolling the dice using random Enum values]]></title>
<link href="http://sleepomeno.github.io/blog/2017/04/02/Generating-random-Enum-values/"/>
<updated>2017-04-02T00:00:00+02:00</updated>
<id>http://sleepomeno.github.io/blog/2017/04/02/Generating-random-Enum-values</id>
<content type="html"><![CDATA[<p>Every wanted to roll the dice in Haskell? Let’s say you have a data type like</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='haskell'><span class='line'><span class="kr">data</span> <span class="kt">Number</span> <span class="ow">=</span> <span class="kt">One</span> <span class="o">|</span> <span class="kt">Two</span> <span class="o">|</span> <span class="kt">Three</span> <span class="o">|</span> <span class="kt">Four</span> <span class="o">|</span> <span class="kt">Five</span> <span class="o">|</span> <span class="kt">Six</span>
</span><span class='line'> <span class="kr">deriving</span> <span class="p">(</span><span class="kt">Enum</span><span class="p">,</span> <span class="kt">Bounded</span><span class="p">,</span> <span class="kt">Eq</span><span class="p">,</span> <span class="kt">Show</span><span class="p">)</span>
</span></code></pre></td></tr></table></div></figure>
<p>How do you generate a random <code>Number</code> value? There are several ways to do it, usually in an <code>IO</code> context, obviously. In order to use it in a
common monad transformer stack, the primitives of the <code>MonadRandom</code> type class come to my mind. So it would be most convenient to get a
random value using <code>getRandom</code>. Anyway, as much fun as rolling the dice is, let’s derive a solution working for all bounded Enums.</p>
<!-- more -->
<p>Anyway, import <strong>Control.Monad.Random</strong> as we want to use <code>getRandom</code> of the <code>MonadRandom</code> class which looks like:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
</pre></td><td class='code'><pre><code class='haskell'><span class='line'><span class="kr">class</span> <span class="kt">Monad</span> <span class="n">m</span> <span class="ow">=></span> <span class="kt">MonadRandom</span> <span class="p">(</span><span class="n">m</span> <span class="ow">::</span> <span class="o">*</span> <span class="ow">-></span> <span class="o">*</span><span class="p">)</span> <span class="kr">where</span>
</span><span class='line'> <span class="n">getRandom</span> <span class="ow">::</span> <span class="kt">Random</span> <span class="n">a</span> <span class="ow">=></span> <span class="n">m</span> <span class="n">a</span>
</span><span class='line'><span class="c1">-- other functions we don't need</span>
</span><span class='line'>
</span><span class='line'><span class="kr">class</span> <span class="kt">Random</span> <span class="n">a</span> <span class="kr">where</span>
</span><span class='line'><span class="c1">-- needs to provide:</span>
</span><span class='line'> <span class="n">randomR</span> <span class="ow">::</span> <span class="kt">RandomGen</span> <span class="n">g</span> <span class="ow">=></span> <span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">a</span><span class="p">)</span> <span class="ow">-></span> <span class="n">g</span> <span class="ow">-></span> <span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">g</span><span class="p">)</span>
</span><span class='line'> <span class="n">random</span> <span class="ow">::</span> <span class="kt">RandomGen</span> <span class="n">g</span> <span class="ow">=></span> <span class="n">g</span> <span class="ow">-></span> <span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">g</span><span class="p">)</span>
</span></code></pre></td></tr></table></div></figure>
<p>Shortly, <code>randomR</code> needs to be able to provide a random <code>Number</code> value in the specified interval, given a random number generator. So the idea is about mapping the Enum values to <code>Int</code> values
and deriving a random Enum value from a randomly generated number.</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
</pre></td><td class='code'><pre><code class='haskell'><span class='line'><span class="c1">-- :t fromEnum</span>
</span><span class='line'><span class="c1">-- fromEnum :: Enum a => a -> Int</span>
</span><span class='line'><span class="c1">-- :t toEnum</span>
</span><span class='line'><span class="c1">-- toEnum :: Enum a => Int -> a</span>
</span><span class='line'>
</span><span class='line'><span class="c1">-- 1)</span>
</span><span class='line'><span class="kr">instance</span> <span class="kt">Random</span> <span class="kt">Number</span> <span class="kr">where</span>
</span><span class='line'> <span class="n">randomR</span> <span class="p">(</span><span class="n">a</span><span class="p">,</span><span class="n">b</span><span class="p">)</span> <span class="n">g</span> <span class="ow">=</span>
</span><span class='line'> <span class="kr">case</span> <span class="n">randomR</span> <span class="p">(</span><span class="n">fromEnum</span> <span class="n">a</span><span class="p">,</span> <span class="n">fromEnum</span> <span class="n">b</span><span class="p">)</span> <span class="n">g</span> <span class="kr">of</span>
</span><span class='line'> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">g'</span><span class="p">)</span> <span class="ow">-></span> <span class="p">(</span><span class="n">toEnum</span> <span class="n">x</span><span class="p">,</span> <span class="n">g'</span><span class="p">)</span>
</span><span class='line'> <span class="n">random</span> <span class="n">g</span> <span class="ow">=</span> <span class="n">randomR</span> <span class="p">(</span><span class="kt">One</span><span class="p">,</span> <span class="kt">Six</span><span class="p">)</span> <span class="n">g</span>
</span><span class='line'>
</span><span class='line'><span class="c1">-- 2) - more general solution making use of Bounded</span>
</span><span class='line'><span class="kr">instance</span> <span class="kt">Random</span> <span class="kt">Number</span> <span class="kr">where</span>
</span><span class='line'> <span class="n">randomR</span> <span class="ow">=</span> <span class="n">enumRandomR</span>
</span><span class='line'> <span class="n">random</span> <span class="n">g</span> <span class="ow">=</span> <span class="n">randomR</span> <span class="p">(</span><span class="n">minBound</span><span class="p">,</span> <span class="n">maxBound</span><span class="p">)</span> <span class="n">g</span>
</span><span class='line'>
</span><span class='line'><span class="nf">enumRandomR</span> <span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span> <span class="n">g</span> <span class="ow">=</span>
</span><span class='line'> <span class="kr">case</span> <span class="n">randomR</span> <span class="p">(</span><span class="n">fromEnum</span> <span class="n">a</span><span class="p">,</span> <span class="n">fromEnum</span> <span class="n">b</span><span class="p">)</span> <span class="n">g</span> <span class="kr">of</span>
</span><span class='line'> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">g'</span><span class="p">)</span> <span class="ow">-></span> <span class="p">(</span><span class="n">toEnum</span> <span class="n">x</span><span class="p">,</span> <span class="n">g'</span><span class="p">)</span>
</span></code></pre></td></tr></table></div></figure>
<p>While we still used the explicit <code>Number</code> interval values in <strong>1)</strong>, we get a more general solution in <strong>2)</strong> using the fact that we had auto-derived an instance of <code>Bounded</code> for <code>Number</code> and thus have <code>minBound</code> and <code>maxBound</code> at our disposal.</p>
<p>At last, we can generate a random <code>Number</code> value:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='haskell'><span class='line'><span class="err">λ</span><span class="o">></span> <span class="n">getRandom</span> <span class="ow">::</span> <span class="kt">IO</span> <span class="kt">Number</span>
</span><span class='line'><span class="kt">Two</span>
</span></code></pre></td></tr></table></div></figure>
<p>Anyway, our generated <code>Number</code> values are uniformly distributed, every value occurs with equal probability. What if you want to tamper with the die at little, e.g.
when your opponent throws the dice they should not get a <code>Six</code> quite so often. You could do that providing a respective <code>Random</code> instance for a newtype wrapper:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
</pre></td><td class='code'><pre><code class='haskell'><span class='line'><span class="c1">-- you need GeneralizedNewtypeDeriving pragma to derive Enum</span>
</span><span class='line'><span class="kr">newtype</span> <span class="kt">MaxBoundLessLikely</span> <span class="n">a</span> <span class="ow">=</span> <span class="kt">MaxLessLikely</span> <span class="p">{</span>
</span><span class='line'> <span class="n">getValue</span> <span class="ow">::</span> <span class="n">a</span> <span class="p">}</span> <span class="kr">deriving</span> <span class="p">(</span><span class="kt">Bounded</span><span class="p">,</span> <span class="kt">Eq</span><span class="p">,</span> <span class="kt">Enum</span><span class="p">,</span> <span class="kt">Show</span><span class="p">)</span>
</span><span class='line'>
</span><span class='line'><span class="kr">instance</span> <span class="p">(</span><span class="kt">Enum</span> <span class="n">a</span><span class="p">,</span> <span class="kt">Eq</span> <span class="n">a</span><span class="p">,</span> <span class="kt">Bounded</span> <span class="n">a</span><span class="p">)</span> <span class="ow">=></span> <span class="kt">Random</span> <span class="p">(</span><span class="kt">MaxBoundLessLikely</span> <span class="n">a</span><span class="p">)</span> <span class="kr">where</span>
</span><span class='line'> <span class="n">randomR</span> <span class="p">(</span><span class="n">a</span><span class="p">,</span><span class="n">b</span><span class="p">)</span> <span class="n">g</span> <span class="ow">=</span> <span class="kr">case</span> <span class="n">enumRandomR</span> <span class="p">(</span><span class="n">a</span><span class="p">,</span><span class="n">b</span><span class="p">)</span> <span class="n">g</span> <span class="kr">of</span>
</span><span class='line'> <span class="n">result</span><span class="o">@</span><span class="p">(</span><span class="kt">MaxLessLikely</span> <span class="n">value</span><span class="p">,</span> <span class="n">g'</span><span class="p">)</span> <span class="ow">-></span>
</span><span class='line'> <span class="kr">if</span> <span class="n">value</span> <span class="o">==</span> <span class="n">maxBound</span> <span class="kr">then</span>
</span><span class='line'> <span class="n">enumRandomR</span> <span class="p">(</span><span class="n">a</span><span class="p">,</span><span class="n">b</span><span class="p">)</span> <span class="n">g'</span>
</span><span class='line'> <span class="kr">else</span> <span class="n">result</span>
</span><span class='line'> <span class="n">random</span> <span class="n">g</span> <span class="ow">=</span> <span class="n">randomR</span> <span class="p">(</span><span class="n">minBound</span><span class="p">,</span> <span class="n">maxBound</span><span class="p">)</span> <span class="n">g</span>
</span></code></pre></td></tr></table></div></figure>
<p>Your <code>rollDice</code> function then looks so inconspicuous, your opponent might not even notice:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
</pre></td><td class='code'><pre><code class='haskell'><span class='line'><span class="kr">data</span> <span class="kt">Player</span> <span class="ow">=</span> <span class="kt">Me</span> <span class="o">|</span> <span class="kt">Opponent</span>
</span><span class='line'>
</span><span class='line'><span class="nf">rollDice</span> <span class="kt">Me</span> <span class="ow">=</span> <span class="n">getRandom</span>
</span><span class='line'><span class="nf">rollDice</span> <span class="kt">Opponent</span> <span class="ow">=</span> <span class="n">fmap</span> <span class="n">getValue</span> <span class="n">getRandom</span>
</span><span class='line'>
</span><span class='line'><span class="nf">howManySixes</span> <span class="ow">::</span> <span class="kt">MonadRandom</span> <span class="n">m</span> <span class="ow">=></span> <span class="kt">Player</span> <span class="ow">-></span> <span class="kt">Int</span> <span class="ow">-></span> <span class="n">m</span> <span class="kt">Int</span>
</span><span class='line'><span class="nf">howManySixes</span> <span class="n">player</span> <span class="n">nrThrows</span> <span class="ow">=</span> <span class="kr">do</span>
</span><span class='line'> <span class="n">results</span> <span class="ow"><-</span> <span class="n">replicateM</span> <span class="n">nrThrows</span> <span class="p">(</span><span class="n">rollDice</span> <span class="n">player</span><span class="p">)</span>
</span><span class='line'> <span class="n">return</span> <span class="o">$</span> <span class="n">length</span> <span class="o">.</span> <span class="n">filter</span> <span class="p">(</span><span class="o">==</span> <span class="kt">Six</span><span class="p">)</span> <span class="o">$</span> <span class="n">results</span>
</span></code></pre></td></tr></table></div></figure>
<p>They might actually think that they are just unlucky:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class='haskell'><span class='line'><span class="err">λ</span><span class="o">></span> <span class="n">howManySixes</span> <span class="kt">Me</span> <span class="mi">1000</span>
</span><span class='line'><span class="mi">170</span>
</span><span class='line'><span class="err">λ</span><span class="o">></span> <span class="n">howManySixes</span> <span class="kt">Opponent</span> <span class="mi">1000</span>
</span><span class='line'><span class="mi">46</span>
</span></code></pre></td></tr></table></div></figure>
<p>You can find the source <a href="http://sleepomeno.github.io/enum/RandomEnum.hs" target="_blank">here</a>.</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Toying with Racket]]></title>
<link href="http://sleepomeno.github.io/blog/2015/09/13/Toying-with-Racket/"/>
<updated>2015-09-13T00:00:00+02:00</updated>
<id>http://sleepomeno.github.io/blog/2015/09/13/Toying-with-Racket</id>
<content type="html"><![CDATA[<p>2 hours to go… I’ve been waiting for the men’s tennis US Open final
to start. What should I do? In the end, I’ve been killing time listening to <a href="http://www.functionalgeekery.com/episode-24-matthew-flatt/" target="_blank">that</a> Functional Geekery podcast episode
which features Matthew Flatt talking about the <a href="http://racket-lang.org/" target="_blank">Racket</a> programming
language. Realizing the irony, my thoughts went something like: “Racket, tennis?! Can’t be a coincidence! Still
some time to burn, so I will programm something tennis-like in
Racket!” So let’s open the Racket <a href="http://docs.racket-lang.org/quick/" target="_blank">quickstart</a> to somehow learn Racket
and get an idea what the tennis-like thing should be.</p>
<!-- more -->
<p><img class="left" src="http://sleepomeno.github.io/images/court.png" width="200"></p>
<p>The idea came instantly when I saw that Racket offers quite
newbie-friendly picture drawing examples in its tutorial. Now, it’s
obvious what I would do, isn’t it? Exactly, I would draw a tennis
court! So I <a href="http://download.racket-lang.org/" target="_blank">downloaded</a> Racket and found the executable
for the Racket IDE DrRacket in the <strong>bin</strong> folder of the resulting
directory. Given the examples of the <a href="http://docs.racket-lang.org/quick/" target="_blank">quickstart</a> tutorial I could come
up with that code which got the job done. And it even has (kind of) the blue
color of the US Open hard court ;)</p>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>(let* ([color "blue"]
</span><span class='line'> [blue (lambda (pict) (colorize pict color))]
</span><span class='line'> [double (blue (filled-rectangle 203 30))]
</span><span class='line'> [base (blue (filled-rectangle 90 133))]
</span><span class='line'> [margin 3]
</span><span class='line'> [doubles (hc-append margin double double)]
</span><span class='line'> [service (blue (filled-rectangle 110 65))]
</span><span class='line'> [services (vc-append margin service service)]
</span><span class='line'> [middle1 (hc-append margin base services)]
</span><span class='line'> [middle2 (hc-append margin services base)]
</span><span class='line'> [middles (hc-append margin middle1 middle2)])
</span><span class='line'> (frame (frame (vc-append margin doubles middles doubles) #:color "white" #:line-width 18) #:color color #:line-width 12))</span></code></pre></td></tr></table></div></figure>
<p>The code can also be found in that <a href="https://gist.github.com/sleepomeno/f8f0af59b19324166619" target="_blank">gist</a>.</p>
<p>Anyway, now the final is about to start, so only a few impressions of
using Racket for the first time: DrRacket proved easy to use and the
<a href="http://docs.racket-lang.org/pict/Basic_Pict_Constructors.html" target="_blank">documentation</a> made it easy to find the right functions for drawing. It
was quite pleasant to see that I could get things done in Racket even
under severe time pressure ;)</p>
<p>Go, Federer!</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Historical Elo Tennis Rating]]></title>
<link href="http://sleepomeno.github.io/blog/2015/09/08/Historical-ELO-Tennis-Rating/"/>
<updated>2015-09-08T00:00:00+02:00</updated>
<id>http://sleepomeno.github.io/blog/2015/09/08/Historical-ELO-Tennis-Rating</id>
<content type="html"><![CDATA[<p>Recently I’ve come across <a href="http://fivethirtyeight.com/features/serena-williams-and-the-difference-between-all-time-great-and-greatest-of-all-time/" target="_blank">that fivethirtyeight article</a> comparing the
female tennis all-time greats by means of an <a href="https://en.wikipedia.org/wiki/Elo_rating_system" target="_blank">Elo rating variant</a> (originally known from chess). It concludes that Serena Williams does
<strong>not</strong> have the highest rating in history, although she is frequently
considered as the greatest player of all time nowadays. Obviously, I
wondered what’s the situation like in the men’s tennis world. Have
Roger Federer’s record 17 Grand Slam wins led to the highest Elo
rating as well? What about players like Borg and McEnroe? Anyway, I
have found surprising results.</p>
<!-- more -->
<h2>Technical approach</h2>
<p><a href="https://github.com/JeffSackmann/tennis_atp" target="_blank">This</a> is where I got the match data on ATP matches from 1968
onwards providing the source of the Elo evaluation in yearly CSV
files. I have adopted the mathematical details of the computation from
<a href="https://en.wikipedia.org/wiki/Elo_rating_system#Mathematical_details" target="_blank">the Elo rating Wikipedia page</a>, while I took the recommendation for the
computation of the <strong>K-factor</strong> from <a href="http://fivethirtyeight.com/features/serena-williams-and-the-difference-between-all-time-great-and-greatest-of-all-time/#fn-3" target="_blank">fivethirtyeight</a>. In addition, I
valued Grand Slam tournament matches higher than other matches
(because of the longer and more challenging best-of-5-sets distance) by
increasing the rating changes resulting from those matches by 10%.
Anyway, I wrote an R script which can be found <a href="https://github.com/sleepomeno/tennis_atp/blob/master/examples/elo.R" target="_blank">here</a>.</p>
<h2>The top 10 highest tennis Elo ratings</h2>
<p>Obviously, the main question is: Who has acquired the highest Elo
rating? The answer is: <span class="underline">Novak Djokovic</span> in May 2015! That’s the top 10:</p>
<table class="stat"><thead><tr><th>Rank</th><th>Rating</th><th>Player</th></tr></thead><tbody> <tr><td>1</td><td>2335</td><td>Novak Djokovic</td></tr> <tr><td>2</td><td>2310</td><td>Bjorn Borg</td></tr> <tr><td>3</td><td>2304</td><td>John McEnroe</td></tr> <tr><td>4</td><td>2274</td><td>Rafael Nadal</td></tr> <tr><td>5</td><td>2254</td><td>Roger Federer</td></tr> <tr><td>6</td><td>2253</td><td>Ivan Lendl</td></tr> <tr><td>7</td><td>2191</td><td>Jimmy Connors</td></tr> <tr><td>8</td><td>2168</td><td>Boris Becker</td></tr> <tr><td>9</td><td>2159</td><td>Andy Murray</td></tr> <tr><td>10</td><td>2132</td><td>Pete Sampras</td></tr></tbody></table>
<p>Interesting to see that Borg, McEnroe and Lendl (dominating the 1980s) rank in between the likes of
Djokovic, Nadal and Federer who have dominated the last decade.</p>
<p>Anyway, you might be surprised to see 14-time Grand Slam winner Pete
Sampras only in 10th place. In my opinion, his case demonstrates a <strong>practical</strong>
requirement to get to the top of the above list – or rather
a lack thereof: High-ranked opponents.</p>
<div style="clear:both"> </div>
<h2>Everything is relative – being the best, too!?</h2>
<p>No matter how good a professional tennis player you are, you will lose
sooner or later “because you are human” (this is obviously
controversial and Elo does not account for this). When the defeat happens it is
better to lose against higher Elo-rated opponents since you then lose
less points. To put it bluntly: When you have an hypothetical Elo advantage of 1000
points with regard to the next-best player at the start of the season and you win
99 of 100 matches, you will most likely have a worse rating in the end
of that wonderful season due to that one devastating loss!
Consequently, it could be said that Sampras might have lacked high-valued contemporaries to
make an even deeper run. In contrast, Djokovic has benefited from the
high ratings of Nadal and Federer to get to the very top. (Apart from
that, <a href="https://en.wikipedia.org/wiki/Elo_rating_system#Ratings_inflation_and_deflation" target="_blank">Elo inflation</a> might be a reason for higher ratings nowadays, too.) Similarly,
Borg, McEnroe and Lendl have benefited from the strong competition in
boosting their respective peaks. That’s why I have looked for a way to
abstract the performance from absolute ratings: I have compared the
margins that the above best players could amass in comparison to the
next-best player at their ratings’ peaks. Thus, it can be analyzed by
what margin a player has been able to set oneself apart from the
competition, which I consider as an indicator as significant as the
maximal Elo rating.</p>
<table class="stat"><thead><tr><th>Gap</th><th>Player</th></tr></thead><tbody> <tr><td>225</td><td>Roger Federer</td></tr> <tr><td>194</td><td>Ivan Lendl</td></tr> <tr><td>181</td><td>Bjorn Borg</td></tr> <tr><td>172</td><td>Novak Djokovic</td></tr> <tr><td>154</td><td>Pete Sampras</td></tr> <tr><td>148</td><td>John McEnroe</td></tr> <tr><td>61</td><td>Rafael Nadal</td></tr> </tbody></table>
<p>In February 2007 Federer reached his rating peak and the next-best
player at that time, Rafael Nadal, trailed 225 Elo points. That event
has marked the biggest gap of the Elo rating’s leader and the rest
of the world; a difference of 225 Elo points means a winning chance of
78% for the higher-ranked player. Well, two months later Federer lost to Nadal in the 2007 French
Open final, nevertheless.</p>
<div style="clear:both"> </div>
<h2>Conclusion</h2>
<p>No matter whether you ‘prefer’ the first or the second table – both
tables shows the current top players count among the best of all
times, however, they don’t really outperform the likes of Borg,
McEnroe and Lendl! The R source code for my analysis can be found <a href="https://github.com/sleepomeno/tennis_atp/blob/master/examples/elo.R" target="_blank">here</a>.</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Approximating PI with PureScript]]></title>
<link href="http://sleepomeno.github.io/blog/2015/03/14/Approximating-PI-with-PureScript/"/>
<updated>2015-03-14T00:00:00+01:00</updated>
<id>http://sleepomeno.github.io/blog/2015/03/14/Approximating-PI-with-PureScript</id>
<content type="html"><![CDATA[<p>Oh, it is Pi day! To be honest, I had not known about it until today
but it somehow made it into my Twitter stream. Well, after some relaxed Saturday morning browsing I stumbled across the <a href="http://demonstrations.wolfram.com/ApproximatingPiWithInscribedPolygons/" target="_blank">Wolfram Pi approximation demonstration</a>. It looks like this:</p>
<script type='text/javascript' src='http://demonstrations.wolfram.com/javascript/embed.js' ></script>
<script type='text/javascript'>var demoObj = new DEMOEMBED(); demoObj.run('ApproximatingPiWithInscribedPolygons', '', '389', '613');</script>
<div id='DEMO_ApproximatingPiWithInscribedPolygons'><a class='demonstrationHyperlink' href='http://demonstrations.wolfram.com/ApproximatingPiWithInscribedPolygons/' target='_blank'>Approximating Pi with Inscribed Polygons</a> from the <a class='demonstrationHyperlink' href='http://demonstrations.wolfram.com/' target='_blank'>Wolfram Demonstrations Project</a> by Rob Morris</div>
<br />
<p>Pi is approximated by computing the area of the inscribed
polygon and by dividing that area by the square of the circle radius –
after all, the area of a circle is <strong>r²π</strong>. Obviously, that idea is
that beautiful and so simple that Pi has thus been approximated thousands of
years ago (of course, there are many better and faster ways!), so
I decided to implement it myself.</p>
<!-- more -->
<h2>PureScript</h2>
<p>Some days ago I stumbled across <strong>PureScript</strong> which compiles to
JavaScript. It is heavily influenced by Haskell and shares its quality
of static typing. However, it has been designed to target JavaScript
from the getgo such that it incorporates the strict evaluation
semantics of JavaScript. In addition, it provides a syntax similar to
native JavaScript for accessing object properties. Given some Haskell knowledge,
PureScript seems to be a decent alternative to Fay or Haste for
creating Javascript code! So I thought I would give
it a try and implement something similar to the above Wolfram
demonstration! So this is the result I accomplished after one day’s
work on a <a href="http://sleepomeno.github.io/pi/html/index.html" target="_blank">PureScript clone</a>:</p>
<iframe src="http://sleepomeno.github.io/pi/html/index.html" width="500" height="720" style="margin:auto;display:block"></iframe>
<h3>PureScript learning resources</h3>
<p>First of all these are the best resources on PureScript development that I found:</p>
<ul><li>
<a href="https://gist.github.com/paf31/8e9177b20ee920480fbc" target="_blank">24 days of PureScript</a>
</li><li>
<a href="https://leanpub.com/purescript" target="_blank">PureScript by Example</a> - very detailed but excellent!
</li><li>
<a href="https://github.com/purescript/purescript/wiki" target="_blank">PureScript Wiki</a>
</li></ul>
<p><a href="https://gist.github.com/paf31/8e9177b20ee920480fbc" target="_blank">24 days of PureScript</a> gives a very good overview of the PureScript
library landscape. Above all, running code for every introduced
library is given which is crucial to getting quickly started. In
addition, there is a project called <a href="http://pursuit.purescript.org/" target="_blank">Pursuit</a> which provides a search
engine for functions of PureScript packages. It is still far from
being as useful as Hoogle or Hayoo for Haskell development, though.</p>
<h2>PureScript libraries and building process</h2>
<p>PureScript libraries are managed by <strong>bower</strong> which has worked
surprisingly well for me. However, at the beginning I had problems getting the interpreter <code>psci</code> running with
all dependencies as I’m not used to <strong>grunt</strong> (and <strong>npm</strong>) which are
typically needed in the whole building process. Anyway, when I decided
to use certain PureScript libraries for my implementation their
integration worked like a charm!</p>
<h2>HTML5 Canvas bindings</h2>
<p>PureScript has very decent wrappers of the HTML5 Canvas API in form
of <code>purescript-canvas</code> and <code>purescript-free-canvas</code>. Obviously, I made
heavy use of those to get the circle and the polygon drawn.</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class='haskell'><span class='line'><span class="nf">center</span> <span class="ow">=</span> <span class="p">{</span> <span class="n">x</span> <span class="kt">:</span> <span class="mi">210</span><span class="p">,</span> <span class="n">y</span> <span class="kt">:</span> <span class="mi">210</span> <span class="p">}</span>
</span><span class='line'><span class="nf">drawCircle</span> <span class="ow">=</span> <span class="kr">do</span>
</span><span class='line'> <span class="n">arc</span> <span class="p">{</span> <span class="n">x</span><span class="kt">:</span> <span class="n">center</span><span class="o">.</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="kt">:</span> <span class="n">center</span><span class="o">.</span><span class="n">y</span><span class="p">,</span> <span class="n">r</span><span class="kt">:</span> <span class="n">radius</span><span class="p">,</span> <span class="n">start</span><span class="kt">:</span> <span class="mi">0</span><span class="p">,</span> <span class="n">end</span><span class="kt">:</span> <span class="kt">Math</span><span class="o">.</span><span class="n">pi</span> <span class="o">*</span> <span class="mi">2</span> <span class="p">}</span>
</span><span class='line'> <span class="n">setFillStyle</span> <span class="s">"#000000"</span>
</span><span class='line'> <span class="n">fill</span>
</span></code></pre></td></tr></table></div></figure>
<p>As an argument to <code>arc</code> we actually have an example of the <em>Object</em>
syntax of PureScript which is just like native JavaScript.</p>
<h2>Angular, React or something else?</h2>
<p>PureScript does have bindings to AngularJS and React (find PureScript
libraries by <a href="http://bower.io/search/?q=purescript" target="_blank">searching bower</a>), however, they are both still
experimental and alpha. So I somehow didn’t want to commit to something
half-working which could be very hard to understand for a PureScript
newbie like me. Anyway, I decided that the JQuery binding of
<code>purescript-jquery</code> should be enough for my Pi approximation application; in the end, I
also used <code>purescript-rx</code> (also mentioned on <a href="https://gist.github.com/paf31/8e9177b20ee920480fbc" target="_blank">24 days of PureScript)</a>
but I only scratched the surface of reactive PureScript UI modelling.</p>
<h2>What about the slider?</h2>
<p>I definitely wanted a fancy slider for setting the number of vertices
of the polygon like in the Wolfram demo – without
too much ado, I immediately decided on using the vanilla <a href="http://jqueryui.com/slider/" target="_blank">JQuery-UI
slider</a>. Copy-Paste. That however means that my PureScript has to
somehow interact with the native slider JavaScript.</p>
<h2>The main function</h2>
<p>The first few lines are about getting representations of the HTML
elements with <code>purescript-jquery</code>. Then I define event handlers for
changing the number of vertices and for toggling the checkbox to
show/hide the triangles. <code>onAsObservable</code> actually is from the
<code>purescript-rx</code> binding to the reactive <a href="https://github.com/Reactive-Extensions/RxJS" target="_blank">RxJS</a> libraries which could be
used to define complex event handling.</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
</pre></td><td class='code'><pre><code class='haskell'><span class='line'><span class="nf">main</span> <span class="ow">=</span> <span class="kr">do</span>
</span><span class='line'> <span class="n">canvas</span> <span class="ow"><-</span> <span class="n">getCanvasElementById</span> <span class="s">"canvas"</span>
</span><span class='line'> <span class="n">context</span> <span class="ow"><-</span> <span class="n">getContext2D</span> <span class="n">canvas</span>
</span><span class='line'> <span class="n">verticesInput</span> <span class="ow"><-</span> <span class="n">select</span> <span class="s">"#vertices"</span>
</span><span class='line'> <span class="n">polygonArea</span> <span class="ow"><-</span> <span class="n">select</span> <span class="s">"#polygonArea"</span>
</span><span class='line'> <span class="n">pi</span> <span class="ow"><-</span> <span class="n">select</span> <span class="s">"#pi"</span>
</span><span class='line'> <span class="n">triangles</span> <span class="ow"><-</span> <span class="n">select</span> <span class="s">"#triangles"</span>
</span><span class='line'>
</span><span class='line'> <span class="kr">let</span> <span class="n">updateUI</span> <span class="n">num</span> <span class="n">showTriangles</span> <span class="ow">=</span> <span class="kr">do</span>
</span><span class='line'> <span class="p">{</span> <span class="n">pArea</span> <span class="kt">:</span> <span class="n">polygonAreaPercent</span><span class="p">,</span> <span class="n">pi</span> <span class="kt">:</span> <span class="n">piApprox</span> <span class="p">}</span> <span class="ow"><-</span> <span class="n">showPolygon</span> <span class="n">canvas</span> <span class="n">context</span> <span class="n">num</span> <span class="n">showTriangles</span>
</span><span class='line'> <span class="n">setText</span> <span class="p">(</span><span class="n">show</span> <span class="n">polygonAreaPercent</span> <span class="o"><></span> <span class="s">"%"</span><span class="p">)</span> <span class="n">polygonArea</span>
</span><span class='line'> <span class="n">setText</span> <span class="p">(</span><span class="n">show</span> <span class="n">piApprox</span><span class="p">)</span> <span class="n">pi</span>
</span><span class='line'> <span class="kr">let</span> <span class="n">updateUI'</span> <span class="ow">=</span> <span class="kr">do</span>
</span><span class='line'> <span class="n">showTriangles</span> <span class="ow"><-</span> <span class="p">((</span><span class="o">==</span> <span class="s">"true"</span><span class="p">)</span> <span class="o"><<<</span> <span class="n">stringify</span><span class="p">)</span> <span class="o"><$></span> <span class="n">getProp</span> <span class="s">"checked"</span> <span class="n">triangles</span>
</span><span class='line'> <span class="n">num</span> <span class="ow"><-</span> <span class="p">(</span><span class="n">stringify</span> <span class="o">>>></span> <span class="n">readInt</span> <span class="mi">10</span><span class="p">)</span> <span class="o"><$></span> <span class="n">getValue</span> <span class="n">verticesInput</span>
</span><span class='line'> <span class="n">updateUI</span> <span class="n">num</span> <span class="n">showTriangles</span>
</span><span class='line'>
</span><span class='line'> <span class="n">trianglesChange</span> <span class="ow"><-</span> <span class="s">"click"</span> <span class="p">`</span><span class="n">onAsObservable</span><span class="p">`</span> <span class="n">triangles</span>
</span><span class='line'> <span class="n">trianglesChange</span> <span class="p">`</span><span class="n">subscribe</span><span class="p">`</span> <span class="nf">\</span><span class="kr">_</span> <span class="ow">-></span> <span class="n">void</span> <span class="n">updateUI'</span>
</span><span class='line'>
</span><span class='line'> <span class="n">verticesChange</span> <span class="ow"><-</span> <span class="s">"focus"</span> <span class="p">`</span><span class="n">onAsObservable</span><span class="p">`</span> <span class="n">verticesInput</span>
</span><span class='line'> <span class="n">verticesChange</span> <span class="p">`</span><span class="n">subscribe</span><span class="p">`</span> <span class="nf">\</span><span class="kr">_</span> <span class="ow">-></span> <span class="n">void</span> <span class="n">updateUI'</span>
</span><span class='line'>
</span><span class='line'> <span class="n">updateUI</span> <span class="n">defaultVertices</span> <span class="n">defaultShowTriangles</span>
</span></code></pre></td></tr></table></div></figure>
<h2>The Foreign Function Interface</h2>
<p>In the above code I accessed the current value of the checkbox and the
slider value with the <code>purescript-jquery</code> functions <code>getValue</code> and
<code>getProp</code>. However, it was surprisingly difficult to use those values
as they were not of type <code>String</code> but <code>Foreign</code> and I got those
dragged into the field of the Foreign Function Interface for
communicating with JavaScript code. Anyway, after some digging in I
ended up writing the function <code>stringify</code> which trivially transforms the
incoming Javascript value to a <code>String</code>.</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class='haskell'><span class='line'><span class="nf">foreign</span> <span class="kr">import</span> <span class="nn">stringify</span>
</span><span class='line'> <span class="s">"function stringify(x) {</span><span class="se">\</span>
</span><span class='line'><span class="se"> \</span><span class="s"> return x+</span><span class="se">\"\"</span><span class="s">;</span><span class="se">\</span>
</span><span class='line'><span class="se"> \</span><span class="s">}"</span> <span class="ow">::</span> <span class="kt">Foreign</span> <span class="ow">-></span> <span class="kt">String</span>
</span></code></pre></td></tr></table></div></figure>
<p>That’s an example of how you can integrate JavaScript functions in
PureScript. It is a little bit of a joke as of now sice you need to add all
those backslashes, however, things might get easier in case PureScript
gets a meta programming facility like <strong>TemplateHaskell</strong> in the Haskell
world in the future.</p>
<h2>Conclusion</h2>
<p>All in all, PureScript really makes a nice impression. There is already
a surprising number of libraries available; decent, mature bindings to
Angular or React would be crucial for getting easy web development
adoption, though. Meta programming integration of JavaScript code would
also prove very nice as would be Source Map support… anyway, I’m
looking forward to using it again and might get into improving it myself.</p>
<p>PS: You find the code for the PureScript application on <a href="https://github.com/sleepomeno/InscribePolygons" target="_blank">my GitHub</a>.</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Partial matching in R]]></title>
<link href="http://sleepomeno.github.io/blog/2015/02/20/Partial-matching-in-R/"/>
<updated>2015-02-20T00:00:00+01:00</updated>
<id>http://sleepomeno.github.io/blog/2015/02/20/Partial-matching-in-R</id>
<content type="html"><![CDATA[<p>I’ve not been too exposed to statistics programming in the last few
year, however, sometimes it couldn’t be avoided – and R couldn’t be
avoided! (I still have too much self-esteem to think about
falling back to Excel, even for the simplest things.)</p>
<p>I don’t hate R and I don’t like R; it just strikes me as very
<strong>strange</strong>. Often, the syntax strikes me as odd and above all, the
multitude of ways to express the same thing reminds of my little Perl
experience. Anyway, I have subscribed to the Coursera R course for fun
and in hope to somehow “get the better of R”, to grok in on a deep
level or to at least get a more profound idea as to why I don’t like it ;)</p>
<p>Anyway, here is a language construct which is very <strong>strange</strong> and a
little bit absurd, no whatever how often I think about it. It’s called
<span class="underline">partial matching</span>. To put it bluntly, partial matching makes it
possible to avoid spelling out the whole name of an element of a list
in oder to access it. Let’s have a look.</p>
<!-- more -->
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='r'><span class='line'>x <span class="o"><-</span> list<span class="p">(</span>a_is_the_first_letter <span class="o">=</span> <span class="m">1</span> <span class="o">:</span> <span class="m">5</span><span class="p">)</span>
</span></code></pre></td></tr></table></div></figure>
<p>Now let’s access <code>a_is_the_first_letter</code>! That’s the normal way:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='r'><span class='line'>x<span class="o">$</span>a_is_the_first_letter
</span><span class='line'><span class="c1"># 1 2 3 4 5</span>
</span></code></pre></td></tr></table></div></figure>
<p>However, you could make your life a lot “easier”:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='r'><span class='line'>x<span class="o">$</span>a
</span><span class='line'><span class="c1"># 1 2 3 4 5</span>
</span></code></pre></td></tr></table></div></figure>
<p>Well, the crucial question is: what happens if the prefix of your
partial matching is not unique?</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class='r'><span class='line'>x <span class="o"><-</span> list<span class="p">(</span>a_is_the_first_letter <span class="o">=</span> <span class="m">1</span> <span class="o">:</span> <span class="m">5</span><span class="p">,</span>
</span><span class='line'> a_is_my_first_letter_too <span class="o">=</span> <span class="m">6</span> <span class="o">:</span> <span class="m">10</span><span class="p">)</span>
</span><span class='line'>x<span class="o">$</span>a
</span><span class='line'><span class="c1"># NULL</span>
</span></code></pre></td></tr></table></div></figure>
<p>The result is <code>NULL</code>!</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class='r'><span class='line'>x <span class="o"><-</span> list<span class="p">(</span>a_is_the_first_letter <span class="o">=</span> <span class="m">1</span> <span class="o">:</span> <span class="m">5</span><span class="p">,</span>
</span><span class='line'> a_is_my_first_letter_too <span class="o">=</span> <span class="m">6</span> <span class="o">:</span> <span class="m">10</span><span class="p">)</span>
</span><span class='line'>x<span class="o">$</span>a_is_m
</span><span class='line'><span class="c1"># 6 7 8 9 10</span>
</span></code></pre></td></tr></table></div></figure>
<p>Here the prefix is unique again. Hooray!</p>
<p>Funny, isn’t it? I don’t like it, though. Why? Because it’s not ‘obvious’.
You need to know that feature beforehand, otherwise the fact that an
accidentally misspelled field is handled the same way as a non-unique
field prefix (both returning <code>NULL</code>) is awkward, to say the least.
It’s nearly as though I said to the R interpreter: ‘Give me field
xy or any field that is somehow similar… or just do what you fucking
want (= return NULL)!’ Anyway, it introduces complexity and indeterminism into the code.</p>
<p>There is another twist to partial matching. Of course, there is more
than one way to access a field of a list. Making use of the double bracket
syntax, that feature of partial matching is handled differently.</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='r'><span class='line'>x <span class="o"><-</span> list<span class="p">(</span>a_is_the_first_letter <span class="o">=</span> <span class="m">1</span> <span class="o">:</span> <span class="m">5</span><span class="p">)</span>
</span><span class='line'>x<span class="p">[[</span><span class="s">"a"</span><span class="p">]]</span>
</span><span class='line'><span class="c1"># NULL</span>
</span></code></pre></td></tr></table></div></figure>
<p>Using the double bracket field accessing method, partial matching is
not the default. But R is perly so you still have a way to get that
behavior in a different way:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='r'><span class='line'>x<span class="p">[[</span><span class="s">"a"</span><span class="p">,</span> exact <span class="o">=</span> <span class="kc">FALSE</span><span class="p">]]</span>
</span><span class='line'><span class="c1"># 1 2 3 4 5</span>
</span></code></pre></td></tr></table></div></figure>
<p>At least I now have a better idea why I don’t really like R. It
introduces a sort of laisser-faire programming which I consider too
“inexact”. I mean, would you really want something like the following to be the
future of programming:</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
</pre></td><td class='code'><pre><code class='java'><span class='line'><span class="kd">interface</span> <span class="nc">God</span> <span class="o">{</span>
</span><span class='line'> <span class="kt">void</span> <span class="nf">killMankind</span><span class="o">();</span>
</span><span class='line'> <span class="kt">void</span> <span class="nf">keepUpTheGoodWork</span><span class="o">();</span>
</span><span class='line'><span class="o">}</span>
</span><span class='line'>
</span><span class='line'><span class="c1">// ...</span>
</span><span class='line'><span class="n">god</span><span class="o">.</span><span class="na">k</span><span class="o">()</span> <span class="c1">// What the hell happens? Who cares.</span>
</span></code></pre></td></tr></table></div></figure>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Preview your Github Markdown before committing!]]></title>
<link href="http://sleepomeno.github.io/blog/2015/01/19/Preview-your-Github-Markdown-before-committing/"/>
<updated>2015-01-19T00:00:00+01:00</updated>
<id>http://sleepomeno.github.io/blog/2015/01/19/Preview-your-Github-Markdown-before-committing</id>
<content type="html"><![CDATA[<p>Writing software documentation can be a pretty dull task and is
neglected too often (at least by me). But what purpose does the best program
serve if nobody knows how to use it? None.</p>
<p>Looking at Github, the Markdown formatted <strong>README.md</strong> is the front
page of every repository and the first (and mostly only) source of
documentation.
Until recently, I have treated my <strong>README.md</strong> files rather shabbily; I
would have thought that this lack of motivation originates from a
general dislike of writing documentation, however, I might have
changed my opinion. This <a href="http://increasinglyfunctional.com/2014/12/18/github-flavored-markdown-previews-emacs/" target="_blank">blog post</a> has opened my eyes to an
alternative explanation: writing Github Markdown documentation is not
trivial when you don’t have a chance to preview the resulting
markdown before committing! In that case the output will look
not as expected more often than not – which makes the committer angry
as s/he needs to push another commit just for improving the Markdown.
Anyway, I remember feeling annoyed quite frequently by that procedure in
retrospective. It does not need a stretch of imagination to foresee
the negative influence that annoyance has on my willingness to
provide <strong>README.md</strong> documentation… ;)</p>
<p>The solution is obvious but not that trivial. Obviously, there surely
are plugins for various IDEs which can parse Markdown and output HTML
markup. I remember having once installed such an Eclipse plugin. But things get trickier as Github does not use vanilla
Markdown but its own brand of Markdown – it is not that easy to find a
way to display Github Markdown with good confidence in its conformity;
in addition it shouldn’t force me to use any special IDE as I do most
stuff in Emacs.</p>
<p>The script that I use now was mentioned in the referenced blog post
above: <a href="https://gist.github.com/joshuamiller/6d58f8bd239df56cabe8" target="_blank">flavor.rb</a>. It is a ruby script which actually asks the Github API (!) to do the hard
work, namely providing the HTML output! That looks stupid at first
glance but it is actually the only way to be really sure of the
preview’s congruence with the actual display on the Github page…</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[else return null]]></title>
<link href="http://sleepomeno.github.io/blog/2015/01/05/else-return-null/"/>
<updated>2015-01-05T00:00:00+01:00</updated>
<id>http://sleepomeno.github.io/blog/2015/01/05/else-return-null</id>
<content type="html"><![CDATA[<p>I guess everybody has a story or two in store about Nullpointer
exceptions in Java (or in any language with nullable values). Sooner or later you will make the acquaintance of the dreaded stacktrace line
denoting that you did something terribly wrong, demanding a value
where none exists, and you just wonder <em>why, how the hell can that
object be null?!</em> during an hour of painful debugging… you know
that? Good. Well, I won’t ponder over how to avoid it, how to apply
proper error handling etc. (that’s way too complicated, I’m tired) but I’d just like to point out my personal
favourite, the
famous <code>else return null</code> idiom.</p>
<!-- more -->
<p>Anyway, the below snippet shows what I actually mean by that.</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
</pre></td><td class='code'><pre><code class='java'><span class='line'><span class="c1">// Version 1</span>
</span><span class='line'><span class="k">if</span> <span class="o">(</span><span class="n">password</span> <span class="o">==</span> <span class="s">"12345"</span><span class="o">)</span>
</span><span class='line'> <span class="k">return</span> <span class="n">valuableTreasure</span><span class="o">;</span>
</span><span class='line'><span class="k">else</span>
</span><span class='line'> <span class="k">return</span> <span class="kc">null</span><span class="o">;</span>
</span><span class='line'>
</span><span class='line'><span class="c1">// or, equivalently</span>
</span><span class='line'><span class="c1">// Version 2</span>
</span><span class='line'><span class="k">if</span> <span class="o">(</span><span class="n">password</span> <span class="o">==</span> <span class="s">"12345"</span><span class="o">)</span>
</span><span class='line'> <span class="k">return</span> <span class="n">valuableTreasure</span><span class="o">;</span>
</span><span class='line'><span class="k">return</span> <span class="kc">null</span><span class="o">;</span>
</span></code></pre></td></tr></table></div></figure>
<p>To make things more familiar, in Version 2 you could imagine multiple <code>return null</code> lines hidden in
various control structures in an endless method and you surely get an idea
how people feel when they try to reason about an object being <em>null</em>
or not.
Anyway, spotting an <code>else return null</code> I always get a bad gut feeling
saying that things are not what they are supposed to be. I’m aware
that this obviously touches upon the question if you should avoid
<em>null</em> values altogether. Anyway, I can’t help my bad gut feeling
whenever I see it ;)</p>
<p>The funny thing is that I recently wrote similar code myself; that
alone would not be a surprise yet, but I actually wrote it in
Haskell which does not have that notion of <em>null</em> values and the
corresponding Nullpointer exception. In Haskell, there is the <a href="https://www.haskell.org/haskellwiki/Maybe" target="_blank">Maybe monad</a> which facilitates chaining “partial” computations together without
the risk of a Nullpointer exception. Here is the snippet of that code
(obviously, only the <code>else Nothing</code> is ‘important’).</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class='haskell'><span class='line'><span class="nf">newState</span> <span class="ow">=</span>
</span><span class='line'> <span class="kr">if</span> <span class="n">not</span> <span class="n">shouldBeCompiled</span> <span class="o">&&</span> <span class="n">w'</span> <span class="o">==</span> <span class="n">view</span> <span class="kt">T</span><span class="o">.</span><span class="n">word</span> <span class="kt">W</span><span class="o">.</span><span class="n">immediate'</span> <span class="kr">then</span>
</span><span class='line'> <span class="p">(</span><span class="n">oldState</span> <span class="o">^.</span> <span class="n">lastColonDefinition</span> <span class="p">)</span> <span class="o">>>=</span>
</span><span class='line'> <span class="p">(</span><span class="nf">\</span><span class="n">x</span> <span class="ow">-></span> <span class="n">return</span> <span class="o">$</span> <span class="n">oldState</span> <span class="o">&</span> <span class="n">definedWords</span> <span class="o">%~</span> <span class="p">(</span><span class="n">ix</span> <span class="n">x</span> <span class="o">%~</span> <span class="n">set</span> <span class="n">isImmediate</span> <span class="kt">True</span><span class="p">))</span>
</span><span class='line'> <span class="kr">else</span>
</span><span class='line'> <span class="kt">Nothing</span>
</span></code></pre></td></tr></table></div></figure>
<p>Anyway, believe me, if you ever write such an <code>else Nothing</code> in Haskell, that should
be the trigger – take a deep breath, take a coffee and think about your
problem again. At the least, you are overcomplicating things as using
the <em>Monad</em> or <em>MonadPlus</em> nature of <em>Maybe</em> would make life easier
but probably it’s an indication that your thoughts are about to go
astray and you get lost in old <code>else return null</code> habits or worse – so better
stop it and take a break!</p>
<p>How would the <em>MonadPlus</em> and <em>Monad</em> instances make life better? Look
at the below version. In any case, it’s functionally equivalent, so
how would it be ‘better’? In my opinion, it conveys much
more the impression that the programmer actually knows what they are doing.</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class='haskell'><span class='line'><span class="nf">newState</span> <span class="ow">=</span> <span class="kr">do</span>
</span><span class='line'> <span class="n">guard</span> <span class="o">$</span> <span class="n">not</span> <span class="n">shouldBeCompiled</span> <span class="o">&&</span> <span class="n">w'</span> <span class="o">==</span> <span class="p">(</span><span class="n">view</span> <span class="kt">T</span><span class="o">.</span><span class="n">word</span> <span class="kt">W</span><span class="o">.</span><span class="n">immediate'</span><span class="p">)</span>
</span><span class='line'>
</span><span class='line'> <span class="n">x</span> <span class="ow"><-</span> <span class="n">oldState</span> <span class="o">^.</span> <span class="n">lastColonDefinition</span>
</span><span class='line'> <span class="n">return</span> <span class="o">$</span> <span class="n">oldState</span> <span class="o">&</span> <span class="n">definedWords</span> <span class="o">%~</span> <span class="p">(</span><span class="n">ix</span> <span class="n">x</span> <span class="o">%~</span> <span class="n">set</span> <span class="n">isImmediate</span> <span class="kt">True</span><span class="p">)</span>
</span></code></pre></td></tr></table></div></figure>
<p>Essentially, the <code>guard</code> function does the trick. <code>guard</code>, which has the type
<em>guard :: MonadPlus m => Bool –> m ()</em>, makes the containing <em>do</em>
block evaluate to <code>Nothing</code> if the <code>Bool</code> argument evaluates to
<code>False</code>. In that sense, the <code>guard</code> expression actually looks like an
assertion! The whole <em>MonadPlus</em> magic can be further explored <a href="http://en.wikibooks.org/wiki/Haskell/MonadPlus" target="_blank">here</a>.</p>
<p>In my case, I finally ended up removing those lines altogether. As suspected, the
good old <code>else Nothing</code> was the symptom that I had lost track of
what I was coding at all – completely lost in nothingness – and I really needed a
break.</p>
<p>So what is your typical ‘silly code’ that you typically start writing when
you should rather take a break?</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Using XMonad with a projector]]></title>
<link href="http://sleepomeno.github.io/blog/2014/11/07/Using-XMonad-with-a-projector/"/>
<updated>2014-11-07T00:00:00+01:00</updated>
<id>http://sleepomeno.github.io/blog/2014/11/07/Using-XMonad-with-a-projector</id>
<content type="html"><![CDATA[<p>I’ve been using XMonad for a few years now (lately in combination with
GNOME) but just recently I have found a way to make it work in a useful way
in the context of a presentation with a projector as a second screen.</p>
<p>In general, XMonad does have decent multi-screen support. Building on
Xinerama, the default configuration provides key-binding support for
three screens; how workspaces are mapped to the screens and how this
mapping can change, respectively, can be pretty confusing at first, though –
it is best explained in <a href="http://www.reddit.com/r/xmonad/comments/ndww5/dual_screens_multi_monitors_tips_and_tricks/c38dsfx" target="_blank">here</a>. Whenever I want to use a projector
things get pretty tricky, however.</p>
<!-- more -->
<p>The thing is: Using a projector as a second screen, I want to have
exactly the same workspace (accordingly the same windows, same layout,
obviously) on both screens. Apparently, I could do that by ‘mirroring’
the screens and thus circumventing XMonad multi-screen support. I’m
not too happy with it, though, as, for some reason, I can’t get <em>xrandr</em>
make show a reasonable resolution on both screens in that scenario –
part of what is shown on own screen is hidden on the other. Disabling
mirroring, however, it is <strong>impossible</strong> for XMonad to show exactly the
same on both screens – obviously, this is a restriction imposed by
Xinerama as it manages all workspaces across screens as <em>one</em>
large workspace under the hood.</p>
<p>The cure for that disease is the trick I found in another reddit
thread:
<a href="http://www.reddit.com/r/xmonad/comments/2ha25r/same_workspaces_on_multiple_monitors_without/ckrobfj" target="_blank">same workspaces on multiple monitors</a>.
So let’s assume the following setup: Workspace 1 is shown on your
projector screen, Workspace 2 is shown on your internal screen. You
start a VNC server on workspace 1 on localhost:</p>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>x11vnc -usepw -clip xinerama0 -noxdamage -geometry 1920x1080</span></code></pre></td></tr></table></div></figure>
<p>(You might need to replace ‘xinerama0’ by ‘xinerama1’. ‘1920x1080’
conforms to the resolution of my internal screen. ‘-noxdamage’ is
optional but seems to be recommended.)</p>
<p>On Workspace 2 you start a VNC client:</p>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>vncviewer ViewOnly=1 UseLocalCursor=0 localhost:0</span></code></pre></td></tr></table></div></figure>
<p>(Again you might need to replace ‘localhost:0’ by ‘localhost:1’.)</p>
<p>Well, now you get to see your projected presentation on your internal screen,
too, showing the X display of your VNC server screen! Move to Workspace 1 and start your presentation (or your live
coding, for example) while you actually watch your presentation on your internal screen on Workspace
2! As a bonus, during your presentation you could easily do things
which are not intended to be shown by the projector and/or move
windows from an internal workspace to Workspace 1 when they need to be shown.</p>
<p>Starting the vncviewer with the ‘ViewOnly’ option makes it necessary
that you actually make your live in-presentation changes on Workspace
1, as I said (while watching your own changes on Workspace 2 on your
internal screen). That’s my recommendation anyway, in my experience the viewer setup thus works more
stable and some keyboard inputs wouldn’t be translated correctly from
the viewer to the server using a non-ViewOnly mode.</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[Using Google Universal Analytics with Octopress]]></title>
<link href="http://sleepomeno.github.io/blog/2014/08/16/Using-Google-Universal-Analytics-with-Octopress/"/>
<updated>2014-08-16T00:00:00+02:00</updated>
<id>http://sleepomeno.github.io/blog/2014/08/16/Using-Google-Universal-Analytics-with-Octopress</id>
<content type="html"><![CDATA[<p>When I first set up my Github pages Octopress blog I followed <a href="http://stefanalfbo.github.io/blog/2013/04/17/octopress-google-analytics-github-pages/" target="_blank">those
instructions</a> to set Google Analytics tracking up – and it worked. However, in May Google
Analytics somehow decided to move my account to <em>Universal
Analytics</em> – maybe I had approved it without really knowing what it
meant…</p>
<p>Well, what is <em>Universal Analytics</em>? I have no idea! The
important thing to notice is, though, that you need to change your
JavaScript <strong>tracking code</strong> if you make that transition; obviously, I
didn’t know that. Otherwise tracking wouldn’t work any longer; would
it? As a matter of fact, it <em>somehow</em> did.</p>
<blockquote><p>It is not only not right, it is not even wrong.</p><footer><strong>Wolfgang Pauli</strong></footer></blockquote>
<p>Actually, my Analytics dashboard <strong>did</strong> show some visits and hits, that’s
why I didn’t notice the problem for a long time, however, I guess it
only mentioned 10% of them! Anyway, after a long
debugging session with <a href="https://www.google.at/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0CCAQFjAA&url=https%3A%2F%2Fchrome.google.com%2Fwebstore%2Fdetail%2Ftag-assistant-by-google%2Fkejbdjndbnbjgmefkgdddjlbokphdefk&ei=xivvU6rFCoTE7AbJ54GgBw&usg=AFQjCNHiOEtvqJl1-RFk6_Q6oVWZTGRFPw&sig2=cuQ2UpUVHzSDJBg77fP0hw&bvm=bv.73231344,d.ZGU" target="_blank">Google Tag Assistant</a> and <a href="https://www.google.at/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0CCAQFjAA&url=https%3A%2F%2Fchrome.google.com%2Fwebstore%2Fdetail%2Fgoogle-analytics-debugger%2Fjnkmfdileelhofjcijamephohjechhna&ei=NizvU-u2Nef17AaSp4CIAg&usg=AFQjCNHR1yQN0Rdzn4xwMA1bTPZkNEGK_Q&sig2=CEZMIArRE6i7HVQLoSVTiQ&bvm=bv.73231344,d.ZGU" target="_blank">Google Analytics Debugger</a> I figured out the necessity to change the code, finally.</p>
<p>Shortly, you just need to change your
<code>source/_includes/google_analytics.html</code> to this code:</p>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>{% if site.google_analytics_tracking_id %}
</span><span class='line'> <script type="text/javascript">
</span><span class='line'> (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
</span><span class='line'>(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
</span><span class='line'>m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
</span><span class='line'>})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
</span><span class='line'>
</span><span class='line'>ga('create', '{{ site.google_analytics_tracking_id }}', 'auto');
</span><span class='line'>ga('send', 'pageview');
</span><span class='line'> </script>
</span><span class='line'>{% endif %}</span></code></pre></td></tr></table></div></figure>
<p>Concerning Github pages, it’s not necessary to include a call to set your domain to
<strong>github.io</strong> any longer. It just works out of the box – what a
progress! It is not only right, it is not even wrong now!</p>
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[The notoriously point-free "((x.).)" trick]]></title>
<link href="http://sleepomeno.github.io/blog/2014/08/14/Composing-two-argument-functions/"/>
<updated>2014-08-14T00:00:00+02:00</updated>
<id>http://sleepomeno.github.io/blog/2014/08/14/Composing-two-argument-functions</id>
<content type="html"><![CDATA[<p><a href="http://www.haskell.org/haskellwiki/Pointfree" target="_blank">Point-free</a> code is ubiquitous in every well-polished Hackage library.
It’s more concise than its pointed counterparts and feels more
“hygienic” as function composition immediately translates to its
mathematical background.</p>
<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>