forked from rescript-lang/rescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbb-reveal-example-presentation.html
566 lines (359 loc) · 13.6 KB
/
bb-reveal-example-presentation.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title> Example Presentation Showing bb-reveal </title>
<!-- link to main stylesheet -->
<link rel="stylesheet" href="./reveal-js/bb-reveal/bb-reveal.css">
<link rel="stylesheet" href="./reveal-js/bb-reveal/light-slides.css">
<!-- Code syntax highlighting -->
<link rel="stylesheet" href="./reveal-js/bb-reveal/bb-reveal-syntax-light.css">
<!-- Printing and PDF exports -->
<script>
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match( /print-pdf/gi )
? './reveal-js/css/print/pdf.css'
: './reveal-js/css/print/paper.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>
</head>
<body>
<div class="reveal">
<div class="footer">
<!-- Taking this out for now - it is not redering well with the current .css
<div class="footertitle">Example Presentation Showing bb-reveal </div>
-->
<div class="footerlogo">
<img src="./reveal-js/bb-reveal/BBLogoFooter.png" width=100%>
</div>
<div class="copyright">
© 2016 Bloomberg L.P. All rights reserved.
</div>
</div>
<div class="slides">
<section
data-markdown
data-separator="
===
"
data-separator-vertical ="
---
"
>
<script type="text/template">
# BuckleScript
Bringing OCaml to Javascript developers
Hongbo Zhang, Bloomberg
OCaml Meetup in Paris
December 6, 2016
===
## Why BuckleScript?
### Why OCaml
- Save this slide for OCaml audience ^_^
---
### Why JS
- Arguably the most used programming language
- Everywhere and cross platform (Browser: the only language; Desktop
App: Electron; Server: NodeJS, huge potential on [IoT](https://blogs.windows.com/buildingapps/2015/05/12/bringing-node-js-to-windows-10-iot-core/))
- NPM: largest package manager since 2014
- WebAssembly will make JS platform more attractive, for the first
time cross platform FFI
- Bloomberg is a big industry user of Javascript
===
## Current status
- BuckleScript is still a young project (started late 2015)
- It covers the whole language, except libraries relying on c stubs
- It grows fast (the most starred open source project by Bloomberg),
already used by external users in production (Collaborations with
Facebook Reason team)
<blockquote style= 'background: #f9f9f9; ';>
I'm on the Facebook Reason team, and we're using BuckleScript to compile OCaml into the best compiler output I've ever seen. People didn't recognize that my React components were generated, not hand-written.
</blockquote>
===
## Design goals (differences from Js_of_ocaml)
Highlights of BuckleScript:
- Easy FFI (OCaml -> JS, JS -> OCaml), incremental migration from JS
to OCaml (One OCaml module <-> One JS module)
- Human debuggable output (not relying on source-map)
- Fast build (Save -> Compile -> Run: 100ms)
- Native Windows support (same build experience)
Advantages of Js_of_ocaml:
- No changes to your existing OCaml build system
- Less maintenance effort
===
## A brief overview of compiler pipeline
[Compiler pipelines](http://bucklescript.github.io/bucklescript/Manual.html#_high_level_compiler_workflow)
===
## What does it look like?
[Example: balanced tree](http://bucklescript.github.io/bucklescript-playground/#Balanced_tree)
---
## Balanced tree with 2 million keys insertion and deletion
Execution Time (node v7.2.0, BuckleScript + Google Closure, jsoo minify):
- OCAMLOPT (-g): 0.837s
- BuckleScript: 2.219s
- JSOO: 3.035s
- OCAMLC (-g): 6.545s
- Using Facebook ImmutableJS lib: 13.520s
JS output size:
- BuckleScript: 542 bytes
- JSOO: 3836 bytes
===
## A brief look at FFI (Call OCaml from JS)
- `.mli` is respected
- Basic data types are closely matched (Array -> Array, Tuple -> Array, etc)
- BuckleScript can also emit `.d.ts` files for TypeScript compiler (*experimental*)
- [Publish and consume npm packages out of box](https://www.npmjs.com/package/bs-platform)
- [Call OCaml library from JS side](http://bucklescript.github.io/bucklescript-playground/#Use_OCaml_Standard_Library)
===
## FFI: (Calling Javascript from OCaml)
Users must write *type declarations* for existing
JavaScript libraries
- Introducing built-in extension points and attributes
- Structural typing (model JavaScript Objects)
- Polymorphic variants (model Event handler)
- Label and optional arguments (model JSON configuration)
```ocaml
external exp : float -> float = "Math.exp" [@@bs.val]
let v = exp 3.
```
```js
var v = Math.exp(3.)
```
---
## FFI examples
Typescript binding:
```ocaml
type readline
type line_callback = string -> unit [@bs]
(* [bs] annotation to mark it as uncurried callback *)
type close_callback = unit -> unit [@bs]
external on : readline ->
([ `line of line_callback
| `close of close_callback]
[@bs.string]) -> unit = "" [@@bs.send]
let register readline =
on readline (`line begin fun s -> prerr_endline s end);
on readline (`close begin fun () -> prerr_endline "finished" end);
print_endline "done"
```
---
## FFI examples
- In BuckleScript, `##` is used as method dispatch
```ocaml
let f obj = obj##height + obj##width
val f : [%obj: < height : int ; width : int ; .. > ] -> int
let a = f [%obj { height = 3; width = 32}] (* compiles *)
let b = f [%obj {height = 3 ; width = 32; unused = 3 }] (* compiles *)
```
---
## FFI examples (http server using Node.js)
- `Test_http_server`
```ocaml
let port = 3000
let hostname = "127.0.0.1"
let create_server http =
let server = http##createServer begin fun [@bs] req resp ->
resp##statusCode #= 200;
resp##setHeader "Content-Type" "text/plain";
resp##end_ "Hello world\n"
end
in
server##listen port hostname begin fun [@bs] () ->
Js.log ("Server running at http://"^ hostname ^ ":" ^ Pervasives.string_of_int port ^ "/")
end
let () =
create_server Http_types.http
```
---
## FFI examples (FFI bindings to NODEJS http module)
- `http_types`
```ocaml
type req
class type _resp = object
method statusCode : int [@@bs.set]
method setHeader : string -> string -> unit
method end_ : string -> unit
end [@bs]
class type _server = object
method listen : int -> string -> (unit -> unit [@bs]) -> unit
end [@bs]
type server = _server Js.t
class type _http = object
method createServer : (req -> resp -> unit [@bs] ) -> server
end [@bs]
type http = _http Js.t
external http : http = "" [@@bs.module]
```
---
### FFI (HTTP server)
- Output for `http.ml` is empty (pure type declarations)
- `Test_http_server`
```js
var Pervasives = require("bs-platform/lib/js/pervasives");
var Http = require("http");
var hostname = "127.0.0.1";
function create_server(http) {
var server = http.createServer(function (_, resp) {
resp.statusCode = 200;
resp.setHeader("Content-Type", "text/plain");
return resp.end("Hello world\n");
});
return server.listen(3000, hostname, function () {
console.log("Server running at http://" + (hostname + (":" + (Pervasives.string_of_int(3000) + "/"))));
return /* () */0;
});
}
create_server(Http);
```
===
## Easy to set up
Installation
```
npm install bs-platform
```
Create a JSON file to describe the build spec:
```js
{
"name": "test",
"sources": [
{
"dir": "src"
}
]
}
```
Build and run
```
bsb -w
```
===
## Different Semantics from other back-ends
[Semantics diverge](http://bucklescript.github.io/bucklescript/Manual.html#_semantics_difference_from_other_backends)
===
## Data representation
[OCaml data representation in JS](http://bucklescript.github.io/bucklescript/Manual.html#_runtime_representation)
===
## Wishes from OCaml compiler upstream
- Tell the difference between block and array in lambda layer
- OCaml Array has to be JS array for better FFI
- More efficient data layout, useful for jsoo too
---
## Wishes from OCaml compiler upstream
- Native uncurried calling convention support
- Essential for FFI in callbacks
- BuckleScript attributes is leaky in error message, can not be Polymorpphic
- Useful for jsoo too and external C bindings
- Helps improve perf of native backend partial application
- Built-in uncurying support can be smarter than ppx
`'a -> int` === `'a -> int [@bs]`
---
## Wishes from OCaml compiler upstream
- More flexible lexical convention for method name, structual typing
is useful but limited by syntax, name mangling is not cool
```js
{ "open" : true }
{ "Content-Type" : "text"}
```
---
## Wishes from OCaml compiler upstream
- Polymorpphic variants as string (with immutable string optimization
coming)
- Useful in webprogramming, but generated unreadable code
- Lift the char range limitation
===
## Questions
@bobzhang1988
</script>
</section>
</div>
</div>
<script src="reveal-js/lib/js/head.min.js"></script>
<script src="reveal-js/js/reveal.js"></script>
<script>
Reveal.initialize({
width: 1280,
height: 720,
// Display controls in the bottom right corner
controls: true ,
// Display a presentation progress bar
progress: true,
// Display the page number of the current slide
slideNumber: true,
// Push each slide change to the browser history
history: true,
// Enable keyboard shortcuts for navigation
keyboard: true,
// Enable the slide overview mode
overview: true,
// Vertical centering of slides
center: false,
// Enables touch navigation on devices with touch input
touch: true,
// Loop the presentation
loop: false,
// Change the presentation direction to be RTL
rtl: false,
// Randomizes the order of slides each time the presentation loads
shuffle: false,
// Turns fragments on and off globally
fragments: true,
// Flags if the presentation is running in an embedded mode,
// i.e. contained within a limited portion of the screen
embedded: false,
// Flags if we should show a help overlay when the questionmark
// key is pressed
help: true,
// Flags if speaker notes should be visible to all viewers
showNotes: false,
// Number of milliseconds between automatically proceeding to the
// next slide, disabled when set to 0, this value can be overwritten
// by using a data-autoslide attribute on your slides
autoSlide: 0,
// Stop auto-sliding after user input
autoSlideStoppable: true,
// Use this method for navigation when auto-sliding
autoSlideMethod: Reveal.navigateNext,
// Enable slide navigation via mouse wheel
mouseWheel: false,
// Hides the address bar on mobile devices
hideAddressBar: true,
// Opens links in an iframe preview overlay
previewLinks: false,
// Transition style
transition: 'slide', // none/fade/slide/convex/concave/zoom
// Transition speed
transitionSpeed: 'fast', // default/fast/slow
// Transition style for full page slide backgrounds
backgroundTransition: 'default', // none/fade/slide/convex/concave/zoom
// Number of slides away from the current that are visible
viewDistance: 3,
// Parallax background image
parallaxBackgroundImage: '',
// e.g. "'https://s3.amazonaws.com/hakim-static/reveal-js/reveal-parallax-1.jpg'"
// Parallax background size
parallaxBackgroundSize: '', // CSS syntax, e.g. "2100px 900px"
// Number of pixels to move the parallax background per slide
// - Calculated automatically unless specified
// - Set to 0 to disable movement along an axis
parallaxBackgroundHorizontal: null,
parallaxBackgroundVertical: null,
//------------------------------------------------------------
// Optional reveal.js plugins
dependencies: [
{ src: 'reveal-js/lib/js/classList.js',
condition: function() { return !document.body.classList; } },
{ src: 'reveal-js/plugin/markdown/marked.js',
condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'reveal-js/plugin/markdown/markdown.js',
condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'reveal-js/plugin/highlight/highlight.js',
async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: 'reveal-js/plugin/zoom-js/zoom.js', async: true },
{ src: 'reveal-js/plugin/notes/notes.js', async: true }
]
});
</script>
</body>
</html>