4. (* ocaml *)
let x y = y + 2
type 'a mytype
type listOfString = string list
let run () =
let nothing = None in
let something = Some 10 in
Js.log3 "a" 2 something;
let count = match nothing with
| None !=> "10"
| Some _ !=> "20"
in
if x 2 = 4 then
Js.log "Good"
else
Js.log "panic!"
.
!/* old reason !*/
let x y !=> y + 2;
type mytype 'a;
type listOfString = list string;
let run () !=> {
let nothing = None;
let something = Some 10;
Js.log3 "a" 2 something;
let count = switch nothing {
| None !=> "10"
| Some _ !=> "20"
};
if (x 2 !== 4) {
Js.log "Good"
} else {
Js.log "panic!"
}
};
!/* new reason !*/
let x(y) !=> y + 2;
type mytype('a);
type listOfString = list(string);
let run () !=> {
let nothing = None();
let something = Some(10);
Js.log3("a", 2, something);
let count = switch nothing {
| None !=> "10"
| Some _ !=> "20"
};
if (x(2) !== 4) {
Js.log("Good");
} else {
Js.log("panic!");
}
};
7. FULL REBUILD IS 2S, INCREMENTAL BUILD IS <100MS ON AVERAGE.
USED TO RECEIVE BUGS REPORTS ON A DAILY BASIS; THERE HAVE BEEN A
TOTAL OF 10 BUGS DURING THE WHOLE YEAR!
REFACTORING SPEED WENT FROM DAYS TO DOZENS OF MINUTES.
Messenger.com
44. MODERN SYNTAX AND TOOLCHAIN FOR OCAML
STATIC TYPE AND TYPE INFERENCE
CAN TARGET AND INTEROP WITH JS
COMPILE TO NATIVE AND BYTECODE
FAST, READABLE OUTPUT, READABLE ERROR MESSAGE
54. Variants 101
type species =
| Saiyan
| Namekian
| Human
| Majin
| Other;
type characters = {
age: int,
name: string,
species,
};
let bejita = {age: 42, name: "Vegeta", species: Saiyan};
55. Pattern Matching 101
let reply =
switch (message) {
| "Reason's pretty cool" => "Yep"
| "good night" => "See ya!"
| “hello" | “hi" | “heya" | "hey" => "hello to you too!"
| _ => "Nice to meet you!"
};
56. Pattern Matching and Variant
let hear =
switch (bejita.species) {
| Saiyan => "This is too easy for me!!"
| Namekian => “…”
| Other => “Let’s try one more time"
};
57. Binding and Interop
[%bs.raw {|
console.log("here is some js for you!")
|}];
Js.log("this is reason");
let x = [%bs.raw {| 'here is a string from javascript' |}];
Js.log(x ++ " back in reason land");
[@bs.val] external pi: float = "Math.PI";
let volume_cylinder = (diameter, height) => pi *. diameter *. height;
76. “At the language level, it has features that we’v previously had to
Bolt on top of the JavaScript such as alloca+on-less named
arguments, prop types and more. In short, it is the best way to
take React to the next level — unlocking far beGer user
experience and fast-loading applica+ons.”
Jordan Walke
Creator React and Reason
77. JavaScript and HTML — I can build things!
React — I can reuse my things!
ReasonReact — I can reuse my React things more safely!
All FuncGonal Programming