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.
First off, prove it's a Pacman-complete language.
Anyone know Witness?
Anyone like the Re-prefix?
Then you'll love…
Reason is a language that wants to help you, not block you.
The Goldilocks of languages
"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"
"Like, it's-so-fast-you-can't-blink fast"
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…
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!
BuckleScript: A JavaScript backend for OCaml focused on smooth integration and clean generated code.
"focused on … clean generated code."
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);
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;
"(Compiler) Finishes before others warm up"
(So fast, you don't have time to say fast)
Native iOS/Android anyone?
Native Rasperry pi!
DEMO!
Great semantics, even better reach
Imagine Flow and Babelscript integrated into a sound language with a great build tool, deep editor integration, and fantastic reach. That's Reason(ml).
Reason is a systematic approach to solving the challenges faced by OCaml.
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!
There's just too much stuff
Distributed friendly hacking event! - @sgrove, @reasoncup, http://reasoncup.com/
Ben & Avery! Author of Rewitness, helped a ton with env setup, code structure, hand-holding, general emotional support, etc.
&