Source

stl-roy / index.htm

  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
<!doctype html>
<html>
  <head>
    <title>Roy</title>
    <meta charset="utf-8" />
    <!-- http://www.colourlovers.com/palette/292482/Terra -->
    <style>
      html, body {
        font-family: Puritan;
        background: #E8DDCB;
        background: -webkit-radial-gradient(center, ellipse cover, #FFF8ED 0%, #E8DDCB 100%);
        background: -moz-radial-gradient(center, ellipse cover, #FFF8ED 0%, #E8DDCB 100%);
        background: radial-gradient(center, ellipse cover, #FFF8ED 0%, #E8DDCB 100%);
        color: #031634;
        overflow: hidden;
      }
      a {
        color: #033649;
      }
      h1, h2, h3, h4, h5 {
        line-height: 1em;
      }
      h1, h2, h3, h4, h5, strong {
        color: #033649;
      }
      h2 {
        text-shadow: #CCC2B3 3px 3px 0;
        padding-bottom: 0.25em;
      }
      strong {
        background: #036564;
        color: #E8DDCB;
      }
      body.dark {
        background: #036564;
      }
      .dark a {
        font-family: 'Droid Sans';
        color: #FFF;
      }
      .dark {
        font-family: 'Droid Sans';
        color: #E8DDCB;
      }
      div.image {
        background-repeat: no-repeat;
        background-position: center center;
        background-size: contain;
      }
      div.wide {
        width: 90%;
      }
      div.sixty {
        width: 60%;
      }
      div.fifty {
        width: 50%;
      }
      div.forty {
        width: 40%;
      }
      .blackout {
        color: transparent;
        text-shadow: #000 0 10px 20px;
      }
      .without {
        -webkit-transform: rotate(-2deg);
      }
      .title {
        color: #FFF;
        font-family: Pacifico;
      }
      .end div {
        line-height: 1em;
      }
      body.logo {
        background: -webkit-radial-gradient(center, ellipse cover, #333 0%, #000 100%);
        background: -moz-radial-gradient(center, ellipse cover, #333 0%, #000 100%);
      }
      div.logo {
        background-image: url(roy-large.png);
        -webkit-animation-timing-function: ease-in-out;
        -webkit-animation-iteration-count: infinite;
        -webkit-animation-duration: 3s;
        -webkit-animation-name: rotate-logo;
      }
      div.try-roy {
        background-image: url(try-roy.png);
      }
      div.bilby {
        background-image: url(bilby.png);
      }
      body.precog, body.billcat {
        background: #000;
      }
      div.precog {
        background-image: url(http://a0.twimg.com/profile_images/1884544266/facebook-logo.png);
      }
      div.quirrel {
        background-image: url(quirrel.png);
      }
      div.billcat {
        background-image: url(billcat-big.png);
      }
      .community a {
        font-family: 'Droid Sans';
      }
      .check {
        color: #036564;
        -webkit-animation-iteration-count: infinite;
        -webkit-animation-duration: 3s;
        -webkit-animation-name: green-check-shadow;
      }
      @-webkit-keyframes green-check-shadow {
        0% {
          text-shadow: #036564 0 0 0;
        }
        50% {
          text-shadow: #036564 0 0 50px;
        }
        100% {
          text-shadow: #036564 0 0 0;
        }
      }
      @-webkit-keyframes rotate-logo {
        0% {
          -webkit-transform: rotate(-2deg);
        }
        50% {
          -webkit-transform: rotate(2deg);
        }
        100% {
          -webkit-transform: rotate(-2deg);
        }
      }
    </style>
    <link rel="stylesheet" href="bigtext-slideshow.css" />
    <link rel="stylesheet" href="code.css" />
    <script src="http://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js"></script>
    <script src="jquery.min.js"></script>
    <script src="bigtext.js"></script>
    <script>
      // Change these fonts and reference them in the CSS above.
      var fonts = ['Paytone One', 'Pacifico', 'Droid Sans', 'Puritan'];
    </script>
    <script src="bigtext-slideshow.js"></script>
  </head>
  <body>
    <div class="logo image current">
    </div>
    <div class="dark title fifty">
      <div>Roy</div>
    </div>
    <div>
      <div><h2>altJS language</h2></div>
      <div>CoffeeScript, ClojureScript, Objective-J,<br />
        HaXe, Emscripten, Fantom, JSIL,<br />
        Opa, Pit, Pyjamas...</div>
    </div>
    <div>
      <div><h1>motivation</h1></div>
    </div>
    <div>
      <div>writing correct JavaScript is hard</div>
    </div>
    <div>
      <div>everything in JavaScript is mutable</div>
    </div>
    <div>
      <div><h2>Simon Peyton-Jones</h2></div>
      <div><blockquote>"Types are, the world's<br/> most used formal method,<br/>
          by... 6 orders of magnitude..."</blockquote></div>
    </div>
    <div>
      <div><h1>inspirations</h1></div>
    </div>
    <div>
      <div>CoffeeScript<br />
        <strong>&nbsp;&times;&nbsp;</strong><br />
        OCaml, Haskell</div>
    </div>
    <div>
      <div><pre><code><span class="keyword">let</span> <span class="variable-name">hundred</span> = 100 </code></pre></div>
    </div>
    <div>
      <div><pre><code><span class="keyword">var</span> <span class="variable-name">hundred</span> = 100;</code></pre></div>
    </div>
    <div>
      <div><pre><code>console.log <span class="string">&quot;Hello World&quot;</span>  </code></pre></div>
    </div>
    <div>
      <div><pre><code>console.log(<span class="string">&quot;Hello World&quot;</span>);</code></pre></div>
    </div>
    <div>
      <div><h2>static typing</h2></div>
    </div>
    <div>
      <div><pre><code><span class="comment">// Won't compile
// console.log ("40" + 2)</span></code></pre></div>
    </div>
    <div>
      <div><pre><code><span class="keyword">let</span> <span class="variable-name">f</span> <span class="variable-name">x</span> : Number = x


console.log (f 100)
<span class="comment">// Won't compile:
// console.log (f "100")</span></code></pre></div>
    </div>
    <div>
      <div><pre><code><span class="keyword">var</span> <span class="variable-name">f</span> = <span class="keyword">function</span>(x) {
    <span class="keyword">return</span> x;
};
console.log(f(100));
<span class="comment">// Won't compile:
// console.log (f "100")</span></code></pre></div>
    </div>
    <div>
      <div><h2>extensible records</h2></div>
    </div>
    <div class="wide">
      <div><pre><code><span class="keyword">let</span> <span class="variable-name">show</span> <span class="variable-name">a</span> = a.name ++ <span class="string">': '</span> ++ a.sound
show {
  name: <span class="string">'Hand'</span>
  sound: <span class="string">'clap'</span>
}
show {
  name: <span class="string">'Duck'</span>
  sound: <span class="string">'quack'</span>
  age: 2
}
<span class="comment">// Won't compile
// show {
//   name: 'Tree'
// }</span></code></pre></div>
    </div>
    <div class="wide">
      <div><pre><code><span class="keyword">var</span> <span class="variable-name">show</span> = <span class="keyword">function</span>(a) {
    <span class="keyword">return</span> a.name + <span class="string">': '</span> + a.sound;
};
show({
    <span class="string">&quot;name&quot;</span>: <span class="string">'Hand'</span>,
    <span class="string">&quot;sound&quot;</span>: <span class="string">'clap'</span>
});
show({
    <span class="string">&quot;name&quot;</span>: <span class="string">'Duck'</span>,
    <span class="string">&quot;sound&quot;</span>: <span class="string">'quack'</span>,
    <span class="string">&quot;age&quot;</span>: 2
});</code></pre></div>
    </div>
    <div>
      <div><h2>sum types</h2></div>
    </div>
    <div>
      <div><pre><code><span class="keyword">data</span> <span class="type">Option</span> <span class="variable-name">a</span> =
  Some <span class="variable-name">a</span> | None</code></pre></div>
    </div>
    <div>
      <div><pre><code><span class="keyword">var</span> <span class="variable-name">Some</span> = <span class="keyword">function</span>(<span class="variable-name">a_0</span>) {
    <span class="keyword">if</span>(!(<span class="constant">this</span> <span class="keyword">instanceof</span> <span class="type">Some</span>)) {
        <span class="keyword">return new</span> <span class="type">Some</span>(a_0);
    }
    <span class="constant">this</span>._0 = a_0;
};
<span class="keyword">var</span> <span class="variable-name">None</span> = <span class="keyword">function</span>() {
    <span class="keyword">if</span>(!(<span class="constant">this</span> <span class="keyword">instanceof</span> <span class="type">None</span>)) {
        <span class="keyword">return new</span> <span class="type">None</span>();
    }
};</code></pre></div>
    </div>
    <div>
      <div><h2>pattern matching</h2></div>
    </div>
    <div>
      <div><pre><code><span class="keyword">let</span> noneZero <span class="variable-name">o</span> = <span class="keyword">match</span> o     &nbsp;
  <span class="keyword">case</span> (Some <span class="variable-name">s</span>) = s
  <span class="keyword">case</span> (None ()) = 0</code></pre></div>
    </div>
    <div>
      <div><pre><code><span class="keyword">var</span> <span class="variable-name">noneZero</span> = <span class="keyword">function</span>(<span class="variable-name">o</span>) {
    <span class="keyword">return</span> (<span class="keyword">function</span>() {
        <span class="keyword">if</span>(o <span class="keyword">instanceof</span> <span class="type">Some</span>) {
            <span class="keyword">var</span> <span class="variable-name">s</span> = o._0;
            <span class="keyword">return</span> s;
        } <span class="keyword">else if</span>(o <span class="keyword">instanceof</span> <span class="type">None</span>) {   &nbsp;
            <span class="keyword">return</span> 0;
        }
    })();
}</code></pre></div>
    </div>
    <div>
      <div><pre><code>noneZero (None ())
<span class="comment">// 0</span>
noneZero (Some 1)
<span class="comment">// 1</span></code></pre></div>
    </div>
    <div>
      <div><pre><code>noneZero(None());
<span class="comment">// 0</span>
noneZero(Some(1));
<span class="comment">// 1</span></code></pre></div>
    </div>
    <div>
      <div><h2>type classes</h2></div>
    </div>
    <div class="wide">
      <div><pre><code><span class="keyword">typeclass</span> <span class="type">Monoid</span> <span class="variable-name">#a</span> {
  append: Function(#a, #a, #a)
  empty: #a
}

<span class="keyword">instance</span> <span class="variable-name">stringMonoid</span> = <span class="type">Monoid</span> <span class="variable-name">String</span> {
  append: \x y -> x ++ y
  empty: <span class="string">&quot;&quot;</span>
}

console.log (append <span class="string">&quot;Hello!&quot;</span> empty)</code></pre></div>
    </div>
    <div class="wide">
      <div><pre><code><span class="keyword">var</span> <span class="variable-name">stringMonoid</span> = {
    <span class="string">&quot;append&quot;</span>: <span class="keyword">function</span>(x, y) {
        <span class="keyword">return</span> x + y;
    },
    <span class="string">&quot;empty&quot;</span>: <span class="string">&quot;&quot;</span>
};
console.log(stringMonoid.append(<span class="string">&quot;Hello!&quot;</span>, stringMonoid.empty));</code></pre></div>
    </div>
    <div>
      <div><h2>jQuery.Deferred monad</h2></div>
    </div>
    <div class="wide">
      <div><pre><code><span class="keyword">let</span> <span class="variable-name">deferred</span> = {
  return: \x ->
    <span class="keyword">let</span> <span class="variable-name">d</span> = $.Deferred ()
    d.resolve x
    d.promise ()
  bind: \x f -> x.pipe f
}</code></pre></div>
    </div>
    <div class="wide">
      <div><pre><code><span class="keyword">var</span> <span class="variable-name">deferred</span> = {
    <span class="string">&quot;return&quot;</span>: <span class="keyword">function</span>(x) {
        <span class="keyword">var</span> <span class="variable-name">d</span> = $.Deferred();
        d.resolve(x);
        <span class="keyword">return</span> d.promise();
    },
    <span class="string">&quot;bind&quot;</span>: <span class="keyword">function</span>(x, f) {
        <span class="keyword">return</span> x.pipe(f);
    }
};</code></pre></div>
    </div>
    <div class="wide">
      <div><pre><code><span class="keyword">let</span> <span class="variable-name">v</span> = <span class="keyword">do</span> deferred
  val &lt;- $.ajax <span class="string">'examples/helloworld.roy'</span>
  val2 &lt;- $.ajax <span class="string">'examples/alias.roy'</span>
  <span class="keyword">return</span> (val ++ val2)</code></pre></div>
    </div>
    <div class="wide">
      <div><pre><code><span class="keyword">var</span> v = (<span class="keyword">function</span>(){
    <span class="keyword">return</span> deferred.bind($.ajax(<span class="string">'examples/helloworld.roy'</span>), <span class="keyword">function</span>(val) {
        <span class="keyword">return</span> deferred.bind($.ajax(<span class="string">'examples/alias.roy'</span>), <span class="keyword">function</span>(val2) {
            <span class="keyword">return</span> deferred.return(val + val2);
        });
    });
})();</code></pre></div>
    </div>
    <div>
      <div><h2>modules</h2></div>
    </div>
    <div>
      <div><h2>Roy write-once module</h2></div>
      <div><pre><code><span class="keyword">import</span> <span class="string">&quot;./settings&quot;</span>

<span class="keyword">let</span> <span class="variable-name">appName</span> = <span class="string">&quot;App &quot;</span> ++ settings.name
<span class="keyword">export</span> <span class="variable-name">appName</span></code></pre></div>
    </div>
    <div>
      <div><h2>Browser global object</h2></div>
      <div><pre><code>(<span class="keyword">function</span>() {
<span class="comment">// Using browser module: &quot;settings&quot;</span>
<span class="keyword">var</span> <span class="variable-name">appName</span> = <span class="string">&quot;App &quot;</span> + settings.name;
<span class="constant">this</span>[<span class="string">&quot;appName&quot;</span>] = appName;
})();</code></pre></div>
    </div>
    <div>
      <div><h2>CommonJS 1.0 (node.js)</h2></div>
      <div><pre><code><span class="keyword">var</span> <span class="variable-name">settings</span> = require(<span class="string">&quot;./settings&quot;</span>);
<span class="keyword">var</span> <span class="variable-name">appName</span> = <span class="string">&quot;App &quot;</span> + settings.name;
exports[<span class="string">&quot;appName&quot;</span>] = appName;</code></pre></div>
    </div>
    <div>
      <div><h2>Async module defs</h2></div>
      <div><pre><code>define(<span class="string">'mymodule'</span>, [<span class="string">'settings'</span>],
  <span class="keyword">function</span>(<span class="variable-name">require</span>, <span class="variable-name">exports</span>, <span class="variable-name">settings</span>) {
    <span class="keyword">var</span> <span class="variable-name">appName</span> = <span class="string">&quot;App &quot;</span> + settings.name;
    exports[<span class="string">&quot;appName&quot;</span>] = appName;    
  }
);</code></pre></div>
    </div>
    <div class="dark title">
      <div>future</div>
    </div>
    <div>
      <div><h2>Functional lenses</h2></div>
      <div>make immutability easier than Haskell</div>
    </div>
    <div class="wide">
      <div><pre><code><span class="keyword">let</span> <span class="variable-name">me</span> =
  {name: <span class="string">&quot;Brian&quot;</span>, address: {no: 1007, street: <span class="string">&quot;Pearl St&quot;</span>}}

<span class="keyword">let</span> <span class="variable-name">personStreet</span> =
  compose .street .address

<span class="keyword">get</span> personStreet <span class="variable-name">me</span> <span class="comment">// gives back &quot;Pearl St&quot;</span>
<span class="keyword">set</span> personStreet <span class="string">&quot;Walnut St&quot;</span> <span class="variable-name">me</span> <span class="comment">// copy, updated street</span></code></pre></div>
    </div>
    <div>
      <div><h2>Deferred type errors</h2></div>
      <div>blatantly copying Haskell's new feature</div>
    </div>
    <div>
      <div>./roy <strong>--defer-type-errors</strong> my-program.roy</div>
    </div>
    <div>
      <div><pre><code><span class="keyword">if</span> <span class="constant">true</span> <span class="keyword">then</span>
  console.log (1 + 1)
<span class="keyword">else</span>
  console.log (<span class="string">&quot;TODO&quot;</span> + 1)</code></pre></div>
    </div>
    <div>
      <div><pre><code><span class="keyword">if</span>(<span class="constant">true</span>) {
  <span class="keyword">return</span> console.log(1 + 1);
} <span class="keyword">else</span> {
  <span class="keyword">return</span> console.log((<span class="keyword">function</span>() {
    <span class="keyword">throw new</span> <span class="constant">Error</span>(<span class="string">&quot;String is not Number&quot;</span>);
  })());
}</code></pre></div>
    </div>
    <div class="dark wide">
      <div><a href="http://roy.brianmckenna.org/">roy.brianmckenna.org</a></div>
    </div>
    <div class="try-roy wide image">
    </div>
    <div class="dark end title">
      <div>Thanks!</div>
      <div><a href="http://twitter.com/puffnfresh">@puffnfresh</a></div>
    </div>
  </body>
</html>