SlideShare uma empresa Scribd logo
1 de 63
Baixar para ler offline
ReasonML
Strict, powerful, and forgiving
Me
After a few
months...
Okay, this is like
real work now...
After a few
months...
After a few
months...
After a few
months...
This looks
interesting.
Looks familiar
enough...
Oooh. Smart
people language.
Buckle… script.
Oh, I get it...
It’s so weird.
And fascinating!
Go!
That’s it?
npm install -g bs-platform
npm install -g reason-cli@latest-macos
(or linux)
All right then.
Let’s code.
Static types? Check!
Type inference? Check!
let car = "Blue Maruti 800";
'use strict';
var car = "Blue Maruti 800";
exports.car = car;
let car = "Blue Maruti 800";
/* This is fine. */
Js.log(car ++ " is sold out");
var car = "Blue Maruti 800";
console.log(
"Blue Maruti 800 is sold out"
);
let car = "Blue Maruti 800";
/* This is not OK. */
Js.log(car + 1);
We've found a bug for you!
This has type:
string
But somewhere wanted:
int
let myFirstCar = {
colour: "Blue",
make: "Maruti",
model: "800"
};
We've found a bug for you!
The record field colour can't
be found.
type car = {
colour: string,
make: string,
model: string
};
let myFirstCar = {
colour: "Blue",
make: "Maruti",
model: "800"
};
var myFirstCar = /* record */[
/* colour */"Blue",
/* make */"Maruti",
/* model */"800"
];
type colour = Red | Blue | White | Pink;
type colour = Red | Blue | White | Pink;
That’s a Variant.
type colour = Red | Blue | White | Pink;
These are the variant’s constructors.
type make = Maruti | HindustanMotors;
type model = EightHundred | Zen | Ambassador;
type colour = Red | Blue | White | Pink;
type car = {
make: make,
model: model,
colour: colour
};
let myFirstCar = {
var myFirstCar =
/* colour : Blu
/* make : Marut
/* model : Eigh
];
make: make,
model: model,
colour: colour
};
let myFirstCar = {
make: Maruti,
model: EightHundred,
colour: Blue
};
var myFirstCar =
/* colour : Blu
/* make : Marut
/* model : Eigh
];
ar = {
i,
tHundred,
e
var myFirstCar = /* record */[
/* colour : Blue */1,
/* make : Maruti */0,
/* model : EightHundred */0
];
model: EightHundred,
colour: Blue
};
let productionRun = car => {
switch (car.model) {
| EightHundred => "1983 to 2013"
}
};
var Caml_builtin_exception
require("./stdlib/caml_bui
function productionRun(car
var match = car[/* model
if (match !== 0) {
throw [
Caml_builtin_exc
/* tuple */[
".",
19,
2
]
];
} else {
return "1983 to 2013";
}
}
d
Run = car => {
odel) {
d => "1983 to 2013"
var Caml_builtin_exceptions =
require("./stdlib/caml_builtin_exceptions.js");
function productionRun(car) {
var match = car[/* model */2];
if (match !== 0) {
throw [
Caml_builtin_exceptions.match_failure,
/* tuple */[
".",
19,
2
]
];
} else {
return "1983 to 2013";
}
}
make: Maruti,
model: EightHundred,
colour: Blue
};
let productionRun = car => {
switch (car.model) {
| EightHundred => "1983 to 2013"
}
};
Warning number 8
You forgot to handle a possible
value here, for example:
(Zen|Ambassador)
model: EightHundred,
colour: Blue
};
let productionRun = car => {
switch (car.model) {
| EightHundred => "1983 to 2013"
| Ambassador => "1958 to 2014"
| Zen => "1993 to present"
}
};
function productionRun(car) {
var match = car[/* model */2];
switch (match) {
case 0 :
return "1983 to 2013";
case 1 :
return "1993 to present";
case 2 :
return "1958 to 2014";
}
}
Warning number 8
You forgot to handle a possible
value here, for example:
(Zen|Ambassador)
Use variants to
describe possibilities.
Got it.
type make = Maruti | HindustanMotors;
type model = EightHundred | Zen | Ambassador;
type colour = Red | Blue | White | Pink;
type car = {
make: make,
model: model,
colour: colour,
};
let abomination = {
make: HindustanMotors,
model: Ambassador,
colour: Pink
};
var abomination = /* record */[
/* colour : Pink */3,
/* make : HindustanMotors */1,
/* model : Ambassador */2
];
/* Nope, not available. */
let pink800 = {
make: Maruti,
model: EightHundred,
colour: Pink
};
/* You can buy one of these. */
let pinkZen = {
make: Maruti,
model: Zen,
colour: Pink
};
var pink800 = /* record */[
/* colour : Pink */3,
/* make : Maruti */0,
/* model : EightHundred */0
];
var pinkZen = /* record */[
/* colour : Pink */3,
/* make : Maruti */0,
/* model : Zen */1
];
/* Wut?! */
let marutiAmbassador = {
make: Maruti,
model: Ambassador,
colour: Pink
};
var marutiAmbassador = /* record
*/[
/* colour : Pink */3,
/* make : Maruti */0,
/* model : Ambassador */2
];
type car = {
make: make,
model: model,
colour: colour
};
/* Wut?! */
let marutiAmbassador = {
make: Maruti,
var marutiAmbassador = /* record
*/[
/* colour : Pink */3,
/* make : Maruti */0,
/* model : Ambassador */2
];
type ambiColour = JetBlack | OysterBlue | FireBrickRed | EcruBeige; /* and more */
type zenColour = BeamBlue | PearlSilver | BrightRed | FusionPink; /* and more */
type ehColour = BlueBlaze | SilkySilver | BrickRed | SuperiorWhite; /* and more */
type marutiModel = EightHundred(ehColour) | Zen(zenColour);
type hmModel = Ambassador(ambiColour);
type make = Maruti(marutiModel) | HindustanMotors(hmModel);
type car = { make: make };
type ambiColour = JetBlack | OysterBlue | FireBrickRed | EcruBeige; /* and more */
type zenColour = BeamBlue | PearlSilver | BrightRed | FusionPink; /* and more */
type ehColour = BlueBlaze | SilkySilver | BrickRed | SuperiorWhite; /* and more */
type marutiModel = EightHundred(ehColour) | Zen(zenColour);
type hmModel = Ambassador(ambiColour);
type car = Maruti(marutiModel) | HindustanMotors(hmModel);
let blueMaruti =
Maruti(EightHundred(BlueBlaze));
var Block = require("./stdlib/block.js");
var blueMaruti = /* Maruti */Block.__(0, [
/* EightHundred */Block.__(0, [
/* BlueBlaze */0
])
]);
let pinkAmbassador =
HindustanMotors(Ambassador(FusionPink));
We've found a bug for you!
This variant expression
is expected to have type
ambiColour
The constructor
FusionPink does not
belong to type ambiColour
let marutiAmbassador =
Maruti(Ambassador(BlueBlaze));
We've found a bug for you!
This variant expression
is expected to have type
marutiModel
The constructor
Ambassador does not
belong to type
marutiModel
Make illegal states unrepresentable.
So, that takes
care of data on
the inside.
But what about
stuff from the
outside?
let make = "Maruti";
let model = "Ambassador";
let colour = "FusionPink";
let productionRun = car => {
/* Production run as a string. */
};
let inStock = car => {
/**
* Boolean indicating whether
* car model is in stock.
*/
}
type ambiColour = JetBlack | OysterBlue | FireBrickRed | EcruBeige; /* and more */
type zenColour = BeamBlue | PearlSilver | BrightRed | FusionPink; /* and more */
type ehColour = BlueBlaze | SilkySilver | BrickRed | SuperiorWhite; /* and more */
type marutiModel = EightHundred(ehColour) | Zen(zenColour);
type hmModel = Ambassador(ambiColour);
type car = Maruti(marutiModel) | HindustanMotors(hmModel);
Maruti
Maruti
Hindustan
Motors
800
Zen
Ambassador
Jet
Black
Fusion
Pink
Blaze
Blue
Maruti
Ambassador
Fusion
Pink
let make = "Maruti";
let model = "Ambassador";
let colour = "FusionPink";
Where are you
going with this?
Where are you
going with this?
Make illegal states unrepresentable.
Variants
Compiler
Make illegal states unrepresentable.
Variants
Compiler
Pattern-matching
Functions
Make illegal states unrepresentable.
Parse all external data & enforce
boundaries.
Make illegal states unrepresentable.
Parse all external data & enforce
boundaries.
Mint a module for every type.
Enforce invariants using the module
interface.
Perform compiler-assisted
refactoring.
Use equational reasoning.
Variants
Compiler
Pattern-matching
Functions
Modules
Abstract types
Referential transparency
Variants
Compiler
Pattern-matching
Functions
Modules
Abstract types
Referential transparency
Make illegal states unrepresentable.
Parse all external data & enforce
boundaries.
Mint a module for every type.
Enforce invariants using the module
interface.
Perform compiler-assisted
refactoring.
Use equational reasoning.
Patterns!
Features!
let f = (~x, ~y=0) => Js.log2(x, y);
Warning number 16
This optional parameter in final
position will, in practice, not be
optional.
Reorder the parameters so that at least
one non-optional one is in final
position or, if all parameters are
optional, insert a final ().
Explanation: If the final parameter is
optional, it'd be unclear whether a
function application that omits it
should be considered fully applied, or
partially applied. Imagine writing `let
title = display("hello!")`, only to
realize `title` isn't your desired
result, but a curried call that takes a
final optional argument, e.g.
`~showDate`.
Formal rule: an optional argument is
considered intentionally omitted when
the 1st positional (i.e. neither
labeled nor optional) argument defined
after it is passed in.
let x = 1;
let y = 2.4;
Js.log(x + y);
We've found a bug for you!
This has type:
float
But somewhere wanted:
int
You can convert a float to a int
with int_of_float.If this is a
literal, you want a number
without a trailing dot (e.g.
20).
let make = _children => {
...component,
initialState: () => { x: "Hello" },
render: self => {
{ self.state.x |> ReasonReact.string; }
}
};
We've found a bug for you!
Is this a ReasonReact
reducerComponent or component
with retained props?
If so, is the type for state,
retained props or action
declared _after_
the component declaration?
Moving these types above the
component declaration should
resolve this!
Bye!
@harigopal
mail@harigopal.in
turaku.com
discord.gg/reasonml
reasonml.chat

Mais conteúdo relacionado

Semelhante a ReasonML - Strict, powerful, and forgiving functional programming language

ONLY EDIT CapacityOptimizer.java, Simulator.java, and TriangularD.pdf
ONLY EDIT  CapacityOptimizer.java, Simulator.java, and TriangularD.pdfONLY EDIT  CapacityOptimizer.java, Simulator.java, and TriangularD.pdf
ONLY EDIT CapacityOptimizer.java, Simulator.java, and TriangularD.pdfvinodagrawal6699
 
R, Scikit-Learn and Apache Spark ML - What difference does it make?
R, Scikit-Learn and Apache Spark ML - What difference does it make?R, Scikit-Learn and Apache Spark ML - What difference does it make?
R, Scikit-Learn and Apache Spark ML - What difference does it make?Villu Ruusmann
 
Automobile.javapublic class Automobile {    Declaring instan.pdf
Automobile.javapublic class Automobile {    Declaring instan.pdfAutomobile.javapublic class Automobile {    Declaring instan.pdf
Automobile.javapublic class Automobile {    Declaring instan.pdfanitasahani11
 
C#i need help creating the instance of stream reader to read from .pdf
C#i need help creating the instance of stream reader to read from .pdfC#i need help creating the instance of stream reader to read from .pdf
C#i need help creating the instance of stream reader to read from .pdfajantha11
 
The Ring programming language version 1.10 book - Part 97 of 212
The Ring programming language version 1.10 book - Part 97 of 212The Ring programming language version 1.10 book - Part 97 of 212
The Ring programming language version 1.10 book - Part 97 of 212Mahmoud Samir Fayed
 
#include iostream#include string#include iomanip#inclu.docx
#include iostream#include string#include iomanip#inclu.docx#include iostream#include string#include iomanip#inclu.docx
#include iostream#include string#include iomanip#inclu.docxmayank272369
 
(9) cpp abstractions separated_compilation_and_binding_part_ii
(9) cpp abstractions separated_compilation_and_binding_part_ii(9) cpp abstractions separated_compilation_and_binding_part_ii
(9) cpp abstractions separated_compilation_and_binding_part_iiNico Ludwig
 
Assignment DIn Problem D1 we will use a file to contain the dat.pdf
Assignment DIn Problem D1 we will use a file to contain the dat.pdfAssignment DIn Problem D1 we will use a file to contain the dat.pdf
Assignment DIn Problem D1 we will use a file to contain the dat.pdffasttrackscardecors
 
Compiler Design and Construction COSC 5353Project Instructions -
Compiler Design and Construction COSC 5353Project Instructions -Compiler Design and Construction COSC 5353Project Instructions -
Compiler Design and Construction COSC 5353Project Instructions -LynellBull52
 
C++ Program Auto workshop service system
C++ Program Auto workshop service systemC++ Program Auto workshop service system
C++ Program Auto workshop service systemShahzaib Farooq
 
Effecient javascript
Effecient javascriptEffecient javascript
Effecient javascriptmpnkhan
 
Gift-VT Tools Development Overview
Gift-VT Tools Development OverviewGift-VT Tools Development Overview
Gift-VT Tools Development Overviewstn_tkiller
 
#OOP_D_ITS - 5th - C++ Oop Operator Overloading
#OOP_D_ITS - 5th - C++ Oop Operator Overloading#OOP_D_ITS - 5th - C++ Oop Operator Overloading
#OOP_D_ITS - 5th - C++ Oop Operator OverloadingHadziq Fabroyir
 
Treatment, Architecture and Threads
Treatment, Architecture and ThreadsTreatment, Architecture and Threads
Treatment, Architecture and ThreadsMathias Seguy
 
Loops in C# for loops while and do while loop.
Loops in C# for loops while and do while loop.Loops in C# for loops while and do while loop.
Loops in C# for loops while and do while loop.Abid Kohistani
 
C++ Advanced
C++ AdvancedC++ Advanced
C++ AdvancedVivek Das
 

Semelhante a ReasonML - Strict, powerful, and forgiving functional programming language (20)

ONLY EDIT CapacityOptimizer.java, Simulator.java, and TriangularD.pdf
ONLY EDIT  CapacityOptimizer.java, Simulator.java, and TriangularD.pdfONLY EDIT  CapacityOptimizer.java, Simulator.java, and TriangularD.pdf
ONLY EDIT CapacityOptimizer.java, Simulator.java, and TriangularD.pdf
 
R, Scikit-Learn and Apache Spark ML - What difference does it make?
R, Scikit-Learn and Apache Spark ML - What difference does it make?R, Scikit-Learn and Apache Spark ML - What difference does it make?
R, Scikit-Learn and Apache Spark ML - What difference does it make?
 
Automobile.javapublic class Automobile {    Declaring instan.pdf
Automobile.javapublic class Automobile {    Declaring instan.pdfAutomobile.javapublic class Automobile {    Declaring instan.pdf
Automobile.javapublic class Automobile {    Declaring instan.pdf
 
C#i need help creating the instance of stream reader to read from .pdf
C#i need help creating the instance of stream reader to read from .pdfC#i need help creating the instance of stream reader to read from .pdf
C#i need help creating the instance of stream reader to read from .pdf
 
The Ring programming language version 1.10 book - Part 97 of 212
The Ring programming language version 1.10 book - Part 97 of 212The Ring programming language version 1.10 book - Part 97 of 212
The Ring programming language version 1.10 book - Part 97 of 212
 
#include iostream#include string#include iomanip#inclu.docx
#include iostream#include string#include iomanip#inclu.docx#include iostream#include string#include iomanip#inclu.docx
#include iostream#include string#include iomanip#inclu.docx
 
(9) cpp abstractions separated_compilation_and_binding_part_ii
(9) cpp abstractions separated_compilation_and_binding_part_ii(9) cpp abstractions separated_compilation_and_binding_part_ii
(9) cpp abstractions separated_compilation_and_binding_part_ii
 
Assignment DIn Problem D1 we will use a file to contain the dat.pdf
Assignment DIn Problem D1 we will use a file to contain the dat.pdfAssignment DIn Problem D1 we will use a file to contain the dat.pdf
Assignment DIn Problem D1 we will use a file to contain the dat.pdf
 
Compiler Design and Construction COSC 5353Project Instructions -
Compiler Design and Construction COSC 5353Project Instructions -Compiler Design and Construction COSC 5353Project Instructions -
Compiler Design and Construction COSC 5353Project Instructions -
 
C# Programming Help
C# Programming HelpC# Programming Help
C# Programming Help
 
C++ Program Auto workshop service system
C++ Program Auto workshop service systemC++ Program Auto workshop service system
C++ Program Auto workshop service system
 
Kotlin
KotlinKotlin
Kotlin
 
Itsjustangular
ItsjustangularItsjustangular
Itsjustangular
 
Effecient javascript
Effecient javascriptEffecient javascript
Effecient javascript
 
Gift-VT Tools Development Overview
Gift-VT Tools Development OverviewGift-VT Tools Development Overview
Gift-VT Tools Development Overview
 
#OOP_D_ITS - 5th - C++ Oop Operator Overloading
#OOP_D_ITS - 5th - C++ Oop Operator Overloading#OOP_D_ITS - 5th - C++ Oop Operator Overloading
#OOP_D_ITS - 5th - C++ Oop Operator Overloading
 
Introduction to Swift
Introduction to SwiftIntroduction to Swift
Introduction to Swift
 
Treatment, Architecture and Threads
Treatment, Architecture and ThreadsTreatment, Architecture and Threads
Treatment, Architecture and Threads
 
Loops in C# for loops while and do while loop.
Loops in C# for loops while and do while loop.Loops in C# for loops while and do while loop.
Loops in C# for loops while and do while loop.
 
C++ Advanced
C++ AdvancedC++ Advanced
C++ Advanced
 

Último

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 

Último (20)

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 

ReasonML - Strict, powerful, and forgiving functional programming language

  • 2. Me
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 9. Okay, this is like real work now... After a few months...
  • 12.
  • 17. It’s so weird. And fascinating!
  • 18. Go!
  • 19. That’s it? npm install -g bs-platform npm install -g reason-cli@latest-macos (or linux)
  • 21. Static types? Check! Type inference? Check!
  • 22. let car = "Blue Maruti 800"; 'use strict'; var car = "Blue Maruti 800"; exports.car = car;
  • 23. let car = "Blue Maruti 800"; /* This is fine. */ Js.log(car ++ " is sold out"); var car = "Blue Maruti 800"; console.log( "Blue Maruti 800 is sold out" );
  • 24. let car = "Blue Maruti 800"; /* This is not OK. */ Js.log(car + 1); We've found a bug for you! This has type: string But somewhere wanted: int
  • 25. let myFirstCar = { colour: "Blue", make: "Maruti", model: "800" }; We've found a bug for you! The record field colour can't be found.
  • 26. type car = { colour: string, make: string, model: string }; let myFirstCar = { colour: "Blue", make: "Maruti", model: "800" }; var myFirstCar = /* record */[ /* colour */"Blue", /* make */"Maruti", /* model */"800" ];
  • 27. type colour = Red | Blue | White | Pink;
  • 28. type colour = Red | Blue | White | Pink; That’s a Variant.
  • 29. type colour = Red | Blue | White | Pink; These are the variant’s constructors.
  • 30. type make = Maruti | HindustanMotors; type model = EightHundred | Zen | Ambassador; type colour = Red | Blue | White | Pink; type car = { make: make, model: model, colour: colour }; let myFirstCar = { var myFirstCar = /* colour : Blu /* make : Marut /* model : Eigh ];
  • 31. make: make, model: model, colour: colour }; let myFirstCar = { make: Maruti, model: EightHundred, colour: Blue }; var myFirstCar = /* colour : Blu /* make : Marut /* model : Eigh ];
  • 32. ar = { i, tHundred, e var myFirstCar = /* record */[ /* colour : Blue */1, /* make : Maruti */0, /* model : EightHundred */0 ];
  • 33. model: EightHundred, colour: Blue }; let productionRun = car => { switch (car.model) { | EightHundred => "1983 to 2013" } }; var Caml_builtin_exception require("./stdlib/caml_bui function productionRun(car var match = car[/* model if (match !== 0) { throw [ Caml_builtin_exc /* tuple */[ ".", 19, 2 ] ]; } else { return "1983 to 2013"; } }
  • 34. d Run = car => { odel) { d => "1983 to 2013" var Caml_builtin_exceptions = require("./stdlib/caml_builtin_exceptions.js"); function productionRun(car) { var match = car[/* model */2]; if (match !== 0) { throw [ Caml_builtin_exceptions.match_failure, /* tuple */[ ".", 19, 2 ] ]; } else { return "1983 to 2013"; } }
  • 35. make: Maruti, model: EightHundred, colour: Blue }; let productionRun = car => { switch (car.model) { | EightHundred => "1983 to 2013" } }; Warning number 8 You forgot to handle a possible value here, for example: (Zen|Ambassador)
  • 36. model: EightHundred, colour: Blue }; let productionRun = car => { switch (car.model) { | EightHundred => "1983 to 2013" | Ambassador => "1958 to 2014" | Zen => "1993 to present" } }; function productionRun(car) { var match = car[/* model */2]; switch (match) { case 0 : return "1983 to 2013"; case 1 : return "1993 to present"; case 2 : return "1958 to 2014"; } }
  • 37. Warning number 8 You forgot to handle a possible value here, for example: (Zen|Ambassador) Use variants to describe possibilities. Got it.
  • 38. type make = Maruti | HindustanMotors; type model = EightHundred | Zen | Ambassador; type colour = Red | Blue | White | Pink; type car = { make: make, model: model, colour: colour, };
  • 39. let abomination = { make: HindustanMotors, model: Ambassador, colour: Pink }; var abomination = /* record */[ /* colour : Pink */3, /* make : HindustanMotors */1, /* model : Ambassador */2 ];
  • 40. /* Nope, not available. */ let pink800 = { make: Maruti, model: EightHundred, colour: Pink }; /* You can buy one of these. */ let pinkZen = { make: Maruti, model: Zen, colour: Pink }; var pink800 = /* record */[ /* colour : Pink */3, /* make : Maruti */0, /* model : EightHundred */0 ]; var pinkZen = /* record */[ /* colour : Pink */3, /* make : Maruti */0, /* model : Zen */1 ];
  • 41. /* Wut?! */ let marutiAmbassador = { make: Maruti, model: Ambassador, colour: Pink }; var marutiAmbassador = /* record */[ /* colour : Pink */3, /* make : Maruti */0, /* model : Ambassador */2 ];
  • 42. type car = { make: make, model: model, colour: colour }; /* Wut?! */ let marutiAmbassador = { make: Maruti, var marutiAmbassador = /* record */[ /* colour : Pink */3, /* make : Maruti */0, /* model : Ambassador */2 ];
  • 43. type ambiColour = JetBlack | OysterBlue | FireBrickRed | EcruBeige; /* and more */ type zenColour = BeamBlue | PearlSilver | BrightRed | FusionPink; /* and more */ type ehColour = BlueBlaze | SilkySilver | BrickRed | SuperiorWhite; /* and more */ type marutiModel = EightHundred(ehColour) | Zen(zenColour); type hmModel = Ambassador(ambiColour); type make = Maruti(marutiModel) | HindustanMotors(hmModel); type car = { make: make };
  • 44. type ambiColour = JetBlack | OysterBlue | FireBrickRed | EcruBeige; /* and more */ type zenColour = BeamBlue | PearlSilver | BrightRed | FusionPink; /* and more */ type ehColour = BlueBlaze | SilkySilver | BrickRed | SuperiorWhite; /* and more */ type marutiModel = EightHundred(ehColour) | Zen(zenColour); type hmModel = Ambassador(ambiColour); type car = Maruti(marutiModel) | HindustanMotors(hmModel);
  • 45. let blueMaruti = Maruti(EightHundred(BlueBlaze)); var Block = require("./stdlib/block.js"); var blueMaruti = /* Maruti */Block.__(0, [ /* EightHundred */Block.__(0, [ /* BlueBlaze */0 ]) ]);
  • 46. let pinkAmbassador = HindustanMotors(Ambassador(FusionPink)); We've found a bug for you! This variant expression is expected to have type ambiColour The constructor FusionPink does not belong to type ambiColour
  • 47. let marutiAmbassador = Maruti(Ambassador(BlueBlaze)); We've found a bug for you! This variant expression is expected to have type marutiModel The constructor Ambassador does not belong to type marutiModel
  • 48. Make illegal states unrepresentable.
  • 49. So, that takes care of data on the inside.
  • 50. But what about stuff from the outside?
  • 51. let make = "Maruti"; let model = "Ambassador"; let colour = "FusionPink";
  • 52. let productionRun = car => { /* Production run as a string. */ }; let inStock = car => { /** * Boolean indicating whether * car model is in stock. */ }
  • 53. type ambiColour = JetBlack | OysterBlue | FireBrickRed | EcruBeige; /* and more */ type zenColour = BeamBlue | PearlSilver | BrightRed | FusionPink; /* and more */ type ehColour = BlueBlaze | SilkySilver | BrickRed | SuperiorWhite; /* and more */ type marutiModel = EightHundred(ehColour) | Zen(zenColour); type hmModel = Ambassador(ambiColour); type car = Maruti(marutiModel) | HindustanMotors(hmModel);
  • 55. Maruti Ambassador Fusion Pink let make = "Maruti"; let model = "Ambassador"; let colour = "FusionPink";
  • 56. Where are you going with this?
  • 57. Where are you going with this? Make illegal states unrepresentable.
  • 59. Variants Compiler Pattern-matching Functions Make illegal states unrepresentable. Parse all external data & enforce boundaries.
  • 60. Make illegal states unrepresentable. Parse all external data & enforce boundaries. Mint a module for every type. Enforce invariants using the module interface. Perform compiler-assisted refactoring. Use equational reasoning. Variants Compiler Pattern-matching Functions Modules Abstract types Referential transparency
  • 61. Variants Compiler Pattern-matching Functions Modules Abstract types Referential transparency Make illegal states unrepresentable. Parse all external data & enforce boundaries. Mint a module for every type. Enforce invariants using the module interface. Perform compiler-assisted refactoring. Use equational reasoning. Patterns! Features!
  • 62. let f = (~x, ~y=0) => Js.log2(x, y); Warning number 16 This optional parameter in final position will, in practice, not be optional. Reorder the parameters so that at least one non-optional one is in final position or, if all parameters are optional, insert a final (). Explanation: If the final parameter is optional, it'd be unclear whether a function application that omits it should be considered fully applied, or partially applied. Imagine writing `let title = display("hello!")`, only to realize `title` isn't your desired result, but a curried call that takes a final optional argument, e.g. `~showDate`. Formal rule: an optional argument is considered intentionally omitted when the 1st positional (i.e. neither labeled nor optional) argument defined after it is passed in. let x = 1; let y = 2.4; Js.log(x + y); We've found a bug for you! This has type: float But somewhere wanted: int You can convert a float to a int with int_of_float.If this is a literal, you want a number without a trailing dot (e.g. 20). let make = _children => { ...component, initialState: () => { x: "Hello" }, render: self => { { self.state.x |> ReasonReact.string; } } }; We've found a bug for you! Is this a ReasonReact reducerComponent or component with retained props? If so, is the type for state, retained props or action declared _after_ the component declaration? Moving these types above the component declaration should resolve this!