Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
ReasonML @ OCaml Users in Paris
Search
Matthias Le Brun
September 26, 2017
Programming
0
620
ReasonML @ OCaml Users in Paris
Matthias Le Brun
September 26, 2017
Tweet
Share
More Decks by Matthias Le Brun
See All by Matthias Le Brun
GraphQL, Pothos & SQLite: a perfect match
bloodyowl
0
75
(why the hell did I) build a GraphQL client for the browser
bloodyowl
0
130
Boxed: bringing algebraic types to TypeScript
bloodyowl
0
150
leveraging (algebraic data) types to make your UI rock @ jsheroes
bloodyowl
0
310
Leveraging (algebraic data) types to make your UI rock solid
bloodyowl
0
460
La drôle d'histoire de JavaScript
bloodyowl
0
380
Healthy Code Collaboration
bloodyowl
0
340
Simplify your UI management with (algebraic data) types
bloodyowl
0
830
Simplify your UI management with (algebraic data) types
bloodyowl
1
550
Other Decks in Programming
See All in Programming
Python’s True Superpower
hynek
0
200
15年目のiOSアプリを1から作り直す技術
teakun
1
600
どんと来い、データベース信頼性エンジニアリング / Introduction to DBRE
nnaka2992
1
140
クライアントワークでSREをするということ。あるいは事業会社におけるSREと同じこと・違うこと
nnaka2992
1
310
PostgreSQL を使った快適な go test 環境を求めて
otakakot
0
410
AI駆動開発の本音 〜Claude Code並列開発で見えたエンジニアの新しい役割〜
hisuzuya
4
480
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
230
nuget-server - あなたが必要だったNuGetサーバー
kekyo
PRO
0
170
日本だけで解禁されているアプリ起動の方法
ryunakayama
0
370
Ruby x Terminal
a_matsuda
7
580
守る「だけ」の優しいEMを抜けて、 事業とチームを両方見る視点を身につけた話
maroon8021
3
280
AIとペアプロして処理時間を97%削減した話 #pyconshizu
kashewnuts
1
200
Featured
See All Featured
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.6k
The Limits of Empathy - UXLibs8
cassininazir
1
240
jQuery: Nuts, Bolts and Bling
dougneiner
65
8.4k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
150
What's in a price? How to price your products and services
michaelherold
247
13k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
1.8k
Become a Pro
speakerdeck
PRO
31
5.8k
30 Presentation Tips
portentint
PRO
1
250
Speed Design
sergeychernyshev
33
1.6k
Building Flexible Design Systems
yeseniaperezcruz
330
40k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
460
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
68
Transcript
REASON
Matthias Le Brun twitter.com/bloodyowl github.com/bloodyowl Putain de code !
OCaml
let rec qsort = function | [] !-> [] |
pivot #:: rest !-> let is_less x = x < pivot in let left, right = List.partition is_less rest in qsort left @ [pivot] @ qsort right
Syntax isn't really friendly to newcomers
FP communities aren’t really welcoming to newcomers
None
Here comes Reason
Storytime •Initially, React was written in SML by Jordan Walke
•The idea for Reason actually predates React •Front-end community wasn’t ready yet
1. Syntax 2. Tooling 3. Ecosystem 4. Community
1. Syntax 2. Tooling 3. Ecosystem 4. Community
Functions let x a b = e let x =
fun a b !-> e OCaml Reason let x a b %=> e; let x = fun a b %=> e;
Equality a = b b '== c a #<> b
a *!= b OCaml Reason a '== b b ##=== c a *!= b a --!== b
Expressions let c = let a = "a" in let
b = "b" in a ^ b OCaml Reason let c = { let a = "a"; let b = "b"; a ^ b };
Tuples type tup = int * int let tuple =
a, b OCaml Reason type tup = (int, int) let tuple = (a, b)
Record types type rec = { foo: string; bar: string
}; OCaml Reason type rec = { foo: string, bar: string };
Records { foo = "bar"; bar = "baz" } OCaml
Reason { foo: "bar", bar: "baz", }
Lists [1; 2; 3] OCaml Reason [1, 2, 3]
Type params string option list OCaml Reason list (option string)
Variants type foo = | A of string | B
of string OCaml Reason type foo = | A string | B string
Pattern matching match a with | A x %=> "A"
^ x | B x %=> "B" ^ x OCaml Reason switch a { | A x %=> "A" ^ x | B x %=> "B" ^ x }
Equality (* comment *) OCaml Reason //* comment -*/
Refmt: one language, one formatting
ReasonFatigue prevented ☕
Syntax simpler to JS folks
1. Syntax 2. Tooling 3. Ecosystem 4. Community
BuckleScript
BuckleScript •Like js_of_ocaml but takes on after an earlier step
of compilation •Makes some optimisations considering the JS target •Great interoperability
Produces code that’s faster than vanilla™
Smaller footprint var user = //* record -*/[ //* username
-*/"Bob", //* id : Some -*/["abc"], //* age -*/32 ];
[ "Bob", ["abc"], 32 ]; Smaller footprint
Don’t want to rewrite your project from scratch?
external myExistingModule : string = [@@bs.module "-../myExistingModule"]; Use JS
type user = { name: string, age: int }; let
fromJs jsObject %=> { name: jsObject###name, age: jsObject###age }; Convert from JS
let toJs object %=> { "name": object.name, "age": object.age };
Convert to JS
{ "message_type": "image" | "string", "value": string } Complex conversions
type message = | Image string | String string; let
fromJs js %=> { switch js###message_type { | "image" %=> Image js###value | "string" | _ %=> String js###value } } Complex conversions
Lots of bindings existing/on the way
let getPageKeywords () %=> switch ( DomRe.Document.querySelector "meta[name=\"keywords\"]" DomRe.document )
{ | Some meta %=> switch (DomRe.Element.getAttribute "content" meta) { | Some content %=> Js.String.split "," content *|> Array.to_list *|> List.map String.trim | None %=> [] } | None %=> [] };
None
BetterErrors
Simpler workflow •Effort is for now a lot on the
JS back-end •Coming for native compilation
1. Syntax 2. Tooling 3. Ecosystem 4. Community
ReasonReact
ReactJS import React from "react"; import { string } from
"prop-types"; const App = props %=> ( <div> {props.message} !</div> ) App.propTypes = { message: string.isRequired };
ReasonReact let component = ReasonReact.statelessComponent "App"; let make #::message _children
%=> { …component, render: fun _ %=> <div> (ReasonReact.stringToElement message) !</div> };
ReasonReact type state = int; type actions = | Increment
| Decrement;
ReasonReact let component = ReasonReact .reducerComponent "App"; let make _
%=> { …component, reducer: fun action state %=> switch action { | Increment %=> ReasonReact.Update (state + 1) | Decrement %=> ReasonReact.Update (state - 1) }, //* … -*/ }
ReasonReact render: fun {state, reduce} %=> <div> (ReasonReact.stringToElement (string_of_int state))
<Button title="-" onClick=(reduce (fun _ %=> Increment)) 6/> !</div>
<div> (switch resource { | Loading %=> <ActivityIndicator 6/> |
Idle value %=> <Component value 6/> | Error %=> ErrorMessage.serverError }) !</div> ReasonReact
module MyType = { let name = "Type"; type t
= string; }; module MyTypeCollectionView = Primitives.FixedCollectionView.Make MyType; <MyTypeCollectionView items 6/> ReasonReact
let jsComponent = ReasonReact.wrapReasonForJs #::component (fun jsProps %=> make message#::jsProps###message
[#||] ); ReasonReact
let make #::message children %=> ReasonReact.wrapJsForReason #::reactClass props#::{"message": message} children;
ReasonReact
ReasonReact: good entry point for the front-end community
1. Syntax 2. Tooling 3. Ecosystem 4. Community
Community
Lots of meetups popping up
1. Syntax 2. Tooling 3. Ecosystem 4. Community Sum up
• A new, simpler syntax for OCaml • Lots of
efforts in improving tooling (BetterErrors, BuckleScript is a friend project) • New features like JSX • A new community (super active at the moment) • A great core team who knows what to prioritise first to make it good for everyone
Thank you! Questions?