Conference apps
‣ Schedule, personal schedule, map, events, announcements
‣ Facebook F8
‣ Google I/O
‣ Apple WWDC
‣ Web Summit
‣ Build-in chat for attendees
Slide 4
Slide 4 text
Let's build one for Ruby × Elixir Conf!
Slide 5
Slide 5 text
What to use?
‣ App: ReasonML
‣ Backend: Elixir
‣ API: GraphQL
...why so many new things?
Slide 6
Slide 6 text
A helpful programming language can
teach you how to write robust
programes
Slide 7
Slide 7 text
Some of them restricts you with
human defined rules
̿纷ୗ݈翥捌犋螂ԧ牧অ簡̀
Slide 8
Slide 8 text
Others teaches you some CS ways to
think: data structures, theory of
computation, type theory, formal
methods
̿߶牧ܻ㬵౯䛑扗蝡䰬ᘍ㺔氂牏蝡愊మဩ磪綠笙牧憽݈蝱ྍԧ̀
Slide 9
Slide 9 text
Elixir
Functional, Concurrent, Fault-tolerance, Extendable via
macros, Based on Erlang
Slide 10
Slide 10 text
Functional
“I don’t want to hide data. I want to transform it.”
(Quoted from “Programming Elixir” by Dave Thomas)
Slide 11
Slide 11 text
Concurrent
“Most programmers treat threads and processes as a
necessary evil; Elixir developers feel they are an important
simplification.”
(Quoted from “Programming Elixir” by Dave Thomas)
ReasonML
Write type safe, functional, fast code with the help form
OCaml. Compiles to JavaScript.
Slide 18
Slide 18 text
ReasonML
‣ Reason (syntax): JavaScript-developer-friendly
syntax of OCaml
‣ BuckleScript: OCaml to JavaScript compiler
Slide 19
Slide 19 text
Benefits form OCaml
‣ Battle-tested language created in 1996
‣ Functional and immutable by default
‣ Solid type system: structural, inferred and sound
‣ Flow is written in OCaml!
‣ Ecosystem & tooling
‣ ocaml-language-server
Slide 20
Slide 20 text
Why ReasonML
‣ Type safety
‣ Fast compile time
‣ Generates fast code
‣ The language of React
‣ When Reason's creator created React, the prototype was
written in Standard ML1
‣ ReasonReact: All your ReactJS knowledge, codified
‣ Fun
1 OCaml is also a member of the ML programming language family.
Slide 21
Slide 21 text
Pattern Matching
Slide 22
Slide 22 text
Pattern Matching - Switch
Slide 23
Slide 23 text
Pattern Matching - Switch in function
‣ ଉ憎አဩ
Slide 24
Slide 24 text
Pattern Matching - Function
‣ 䌘㻌㮆 argument ፗ矑狶 pattern matching 犖ݢ犥አ fun ጱ䌃ဩ
Slide 25
Slide 25 text
Varient Type
‣ ݢ犥ቘ薹౮胼癲独ጱ enum
‣ አ type 㬵狶 pattern matching
‣ 犖胼አ㬵玟獤㻌֖2
e.g.: Pt(2.)牏Px(12.)
2 Mars Climate Orbiter, costed hundreds of millions of US
dollars, crashed because of a pound-force-seconds and
newton-seconds type mismatch in 1999.
Slide 26
Slide 26 text
"Option" for nullable
‣ 疰ฎ Haskell 愊ጱ Maybe a = Just a | Nothing
Slide 27
Slide 27 text
Type System
‣ Prevent mistakes such as typo, null, wrong argument...
‣ Prevent unexpected behavior changes when adding new features
‣ Document!
Slide 28
Slide 28 text
Type system: Structural v.s. Nominal
(* These functions takes a list of and returns a . *)
let first: 'a list -> 'a = fun (item::_) -> item
let second: 'a list -> 'a = fun (_::item::_) -> item
(*
* The type of function that takes a list of string and returns a string.
* Note that this type signature is different from the two functions above.
*)
type listOfStringSelector = string list -> string
(* A function that applies a listOfStringSelector to a list of string. *)
let selectListOfStringBy: listOfStringSelector -> string list -> string =
fun f -> fun l -> f l
Slide 29
Slide 29 text
Type system: Structural v.s. Nominal
let second: 'a list -> 'a = fun (_::item::_) -> item
type listOfStringSelector = string list -> string
let selectListOfStringBy: listOfStringSelector -> string list -> string =
fun f -> fun l -> f l
(*
* The structure of
* "function that takes a list of and returns a "
* is comaticatible with
* "function that takes a list of string and returns a string ",
* so the code compiles!
*)
let b = ["a"; "b"; "c"; "d"]
|> selectListOfStringBy second
Slide 30
Slide 30 text
Type system: Inferred
We can remove all the type annotations. OCaml will infer them
correctly.
(*
* OCaml will know that the type of these functions are "'a list -> 'a",
* as the argument is patteren-matched as a list and will return an
* item from the list.
*)
let first = fun (item::_) -> item
let second = fun (_::item::_) -> item
Slide 31
Slide 31 text
More about ReasonML
‣ 2ality Ӥጱ "What is ReasonML?" 羬ڜ
‣ Reason
‣ ReasonReact
‣ BuckleScript
Slide 32
Slide 32 text
GraphQL
Data query language
Slide 33
Slide 33 text
GraphQL
‣ Graph data query language
‣ Schema first development
‣ Easily parallels frontend & backend develop
‣ Easier communication for developers
‣ No need of extra document