Reason

A new developer experience based on OCaml, built by the same people behind React, with friendly syntax, deep editor integration, and carefully thought out build tooling.

Demo

First off, prove it's a Pacman-complete language.

Anyone know Witness?

Anyone like the Re-prefix?

Then you'll love…

Rewitness

Fun!

Reason is a language that wants to help you, not block you.

The Goldilocks of languages

  • Type system tries really not to block or burden you
  • But still, it's very effective at blocking simple bugs
  • Encourages a free fun ctional style, but allows for imperative code when necessary

Robotic pair buddy

"Whoops, we missed a spot!"

1: let is_odd number =>
2:   switch number {
3:   | 0 => false
4:   | 1 => true
5:   | 2 => false
6:   };
Warning 8: this pattern-matching is not exhaustive.
Here is an example of a value that is not matched:
3

"Whoops, we missed a spot!"

 1: type animal =
 2:   | Cat
 3:   | Dog
 4:   | Bird;
 5: 
 6: let petAnimal animal =>
 7:   switch animal {
 8:   | Cat => {}
 9:   | Dog => {}
10:   };
Warning 8: this pattern-matching is not exhaustive.
Here is an example of a value that is not matched:
Bird

"One of these is not like the other…"

 1: type animal =
 2:   | Cat
 3:   | Dog
 4:   | Bird;
 5: 
 6: type sound =
 7:   | Purr
 8:   | Pant
 9:   | Chirp;
10: 
11: let petAnimal animal =>
12:   switch animal {
13:   | Cat => Purr
14:   | Dog => Pant
15:   | Bird => "Singsong"
16:   };
Error: This expression has type string but an expression was expected of
       type sound

"Don't worry: I checked, you don't need that."

1: let peek cat =>
2:   switch (Random.bool ()) {
3:   | true => {lives: cat.lives - 1}
4:   | false => cat
5:   | _ => failwith "I'm really nervous to remove this catch-all"
6:   };
Warning 11: this match case is unused.
1: let peek cat =>
2:   switch (Random.bool ()) {
3:   | true => {lives: cat.lives - 1}
4:   | false => cat
5:   };

"Actually, we usually write it this way"

1: let peek cat => Random.bool () ? {lives: cat.lives - 1} : cat;

"In fact, let me do it for you"

BetterErrors

4baf80c2-d1d6-11e5-8f88-1d7b8065567c.png

4bc78262-d1d6-11e5-9dcc-2f9046dc1950.png

a47377f4-d1d6-11e5-9c12-c0b5285dba47.png

a4895d30-d1d6-11e5-996a-b7e0e2ba63bf.png

Reach!

Unikernels - MirageOS

  • New way of building and deploying applications
  • Operating system as a library
  • Pure OCaml-implementation of low-level libraries
    • TCP/IP
    • TLS
  • Data storage
  • Compiled ahead of time
  • Only pay for what you use
  • No app on top of a run time on top of an operating system on top of a hypervisor
  • Your app is the VM

Fantastically small numbers

  • Tens-of-thousands of lines of memory (and type!)-safe code vs millions of unsafe code
  • Security implications!
  • Compiled VMs weighing in at 100KB-10MB
  • So small, every artifact deployed can be checked into a git repository - total audit!
  • Repro cases now significantly different
  • VM + App bootup time of 50ms (might hit 20ms!)
  • New ways of deploying/booting applications (Jitsu)

"Like, it's-so-fast-you-can't-blink fast" jitsu.jpg

  • Time to cold-boot a AWS Lambda function: 40ms
  • Time to cold-boot an entire Mirage server: 20-50ms⁂

    ⁂ Could be closer to 5-10ms with the right ukvm setup

But don't stop there, because…

Unix/Windows

Works too, and it works fast. What more is there to say? Develop and run traditional server or client apps in OCaml. We got you covered.

And that's not all!

Javascript

BuckleScript: A JavaScript backend for OCaml focused on smooth integration and clean generated code.

"focused on … clean generated code."

  • No joke -

Computer or human (1/2)?

 1: "use strict";
 2: var Int_map=require("./int_map.js");
 3: function test() {
 4:   var m = /* Empty */0;
 5:   for(var i = 0; i <= 1000000; ++i){
 6:     m = add(i, i, m);
 7:   }
 8:   for(var j = 0; j <= 1000000; ++j){
 9:     find(j, m);
10:   }
11:   return /* () */0;
12: }
13: test(/* () */0);

Computer or human (2/2)?

 1: 'use strict';
 2: var Pervasives = require("bs-platform/lib/js/pervasives");
 3: var Http       = require("http");
 4: 
 5: var hostname = "127.0.0.1";
 6: 
 7: function create_server(http) {
 8:   var server = http.createServer(function (_, resp) {
 9:     resp.statusCode = 200;
10:     resp.setHeader("Content-Type", "text/plain");
11:     return resp.end("Hello world\n");
12:   });
13:   return server.listen(3000, hostname, function () {
14:     console.log("Server running at http://" +
15:     (hostname + (":" + (Pervasives.string_of_int(3000) + "/"))));
16:     return /* () */0;
17:   });
18: }
19: 
20: create_server(Http);

Trick question: Both compiled output!

 1: let module IntMap = Map.Make {
 2:   type t = int;
 3:   let compare (x: int) y => compare x y;
 4: };
 5: 
 6: let test () => {
 7:   let m = ref IntMap.empty;
 8:   let count = 1000000;
 9:   for i in 0 to count {
10:     m := IntMap.add i i !m
11:   };
12:   for i in 0 to count {
13:     ignore (IntMap.find i !m)
14:   }
15: };
 1: let port = 3000;
 2: 
 3: let hostname = "127.0.0.1";
 4: 
 5: let create_server http => {
 6:   let server = http##createServer (
 7:     (fun req resp => {
 8:         resp##statusCode#=200;
 9:         resp##setHeader "Content-Type" "text/plain";
10:         resp##_end "Hello world\n"
11:       }
12:     [@bs]
13:   );
14:   server##listen
15:     port
16:     hostname
17:     (
18:       (fun () => Js.log (
19:           "Server running at http://" ^ hostname ^ ":" ^
20:           Pervasives.string_of_int port ^ "/")
21:       )
22:       [@bs]
23:     )
24: };
25: 
26: let () = create_server Http_types.http;

Fst

"(Compiler) Finishes before others warm up"

compile-time.PNG

(So fast, you don't have time to say fast)

ARM64

Native iOS/Android anyone? relayout.png

Native Rasperry pi! CsmbHUUUIAAX6Ug.jpg

DEMO!

Reach?

Great semantics, even better reach

Power!

  • Well-suited for systems programming and for app dev
  • An obsession with performance that borders on the worrisome at times
  • Statically compiled with predictable characteristics

Conclusion

  • Sound semantics
  • Unprecedented reach
  • Absurd developer experience (and only going to get better)

Imagine Flow and Babelscript integrated into a sound language with a great build tool, deep editor integration, and fantastic reach. That's Reason(ml).

So where's OCaml been?

Chasm.png

OCaml Challenges

  • Ecosystem
  • Mindset/culture (traditionally not for web apps)
  • Market selection: If it’s so old and hasn’t won, it must not be good, right?
  • Documentation
  • Polish
  • Tools, tools, tools

OCaml Challenges continued…

  • Tooling, namespacing, etc. are nightmares
  • Learning resources can be outdated
  • Syntax can be off-putting
  • Community is significantly smaller than many others
  • Errors can be inscrutable
  • Single-core

Reason is a systematic approach to solving the challenges faced by OCaml.

Re-Projects

  • rejs: Parse js, output Reason, jumpstart conversions
  • Rebel: Reason build system with careful incremental compilation
  • ReLayout: Flexbox implementation in pure Reason
  • ExampleProject: Easy-to-get-started example project
  • Rewitness: Demo OpenGL/WebGL Reason game
  • Rereact: Reactjs bindings in Bucklescript

Tradeoffs

  • JS?
  • ClojureScript?
  • Elm?

Flow

Flow.js:

 1: /* @flow */
 2: type schrodingersCat = {
 3:  lives: number
 4: };
 5: let peek = (cat:schrodingersCat) => {
 6:  if (Math.random() > 0.5) {
 7:  return {...cat, lives: cat.lives - 1};
 8:  }
 9:  return cat;
10: };

Reasonml:

1: type schrodingersCat = {lives: int};
2: 
3: let peek cat =>
4:   if (Random.bool ()) {
5:     {lives: cat.lives - 1}
6:   } else {
7:     cat
8:   };

Very similar!

  • Flow: Great approach, making huge strides. Sadly working uphill, e.g. No exhaustive pattern matching

Misc

There's just too much stuff

  • Syntax - This'll blow your mind. JSX, GraphQL, CLOJURE!
    • Let 1000 syntaxes bloom-phase
  • Algebraic Effect Handlers (see Eff presentation, though greatly improved since)
  • Spacetime - Insane allocation tracker/profiler
  • Multicore
  • Super-aggressive dead-code elimination

unikernel.png

ReasonCup

Distributed friendly hacking event! - @sgrove, @reasoncup, http://reasoncup.com/ ReasonCup2016.png

Thanks

Ben & Avery! Author of Rewitness, helped a ton with env setup, code structure, hand-holding, general emotional support, etc.

bensan.jpeg & schmavery.jpeg

Sanders and Daniel | JSX & Talk review sanderspies.jpeg & dwwoelfel.png