SlideShare une entreprise Scribd logo
1  sur  54
MONADS
Explained for OOP Developers
by Mikhail Shilkov
ROME - APRIL 13/14 2018
MONAD
MONOID
CATEGORY
ENDOFUNCTORS
“
“
Douglas Crockford,
who found Good Parts
in Javascript
Monads are cursed - once
you understand monads for
yourself you lose the ability
to explain them to others
“
“
TomasPetricek,
TheAlanTuringInstitute
http://tomasp.net/acade
mic/papers/monads/mon
ads-programming.pdf
Learning monads and writing a
monad tutorial or writing a talk
on monads has also become an
important milestone in learning
about theory of functional
programming.
// Type annotation
func: TypeA -> TypeB
// Static methods
static class Mapper {
static ClassB func(ClassA a) { ... }
}
// Instance methods
class ClassA {
ClassB func() { ... }
}
class Speaker {
Talk nextTalk() { ... }
}
class Talk {
Conference getConference() { ... }
}
class Conference {
City getCity() { ... }
}
class City { ... }
static City nextTalkCity(Speaker speaker)
{
Talk talk = speaker.nextTalk();
Conference conf = talk.getConference();
City city = conf.getCity();
return city;
}
City nextTalkCity Speaker
nextTalk
getConference
getCity
NULL
Speaker
Nullable<Talk> nextTalk
Talk
Nullable<Conference> getConference
Conference
Nullable<City> getCity
Nullable<City> nextTalkCity Speaker
Talk? nextTalk
Conference? getConference
City? getCity
Nullable<City> nextTalkCity Speaker
Talk? nextTalk
Conference? getConference
City? getCity
Nullable<City> nextTalkCity Speaker
nextTalk
getConference
getCity
Speaker
Optional<Talk> nextTalk
Talk
Optional<Conference> getConference
Conference
Optional<City> getCity
Optional<City> nextTalkCity
Speaker
nextTalk
getConference
getCity
Optional<City> nextTalkCity
Speaker
nextTalk
getConference
getCity
Speaker
List<Talk> getTalks
Talk
List<Conference> getConferences
Conference
List<City> getCities
List<City> allCitiesToVisit Speaker
List<City>
Talk getTalks
Conference getConferences
City getCities
List<City> allCitiesToVisit Speaker
getTalks
getConferences
getCities
List<City> allCitiesToVisit Speaker
getTalks
getConferences
getCities
List<City> allCitiesToVisit Speaker
getTalks
getConferences
getCities
List<City> allCitiesToVisit Speaker
getTalks
getConferences
getCities
Speaker
Task<Talk> nextTalk
Talk
Task<Conference> getConference
Conference
Task<City> getCity
Task<City> nextTalkCity Speaker
nextTalk
getConference
getCity
Task<City> nextTalkCity Speaker
nextTalk
getConference
getCity
CompletableFuture<City> nextTalkCity
Speaker
nextTalk
getConference
getCity
CompletableFuture<City> nextTalkCity
Speaker
nextTalk
getConference
getCity
PATTERN
nextTalk
getConference
getCity // Optional<T>
getTalks
getConferences
getCities // List<T>
nextTalk
getConference
getCity // CompletableFuture<T>
WorkflowThatReturns<T>
WorkflowThatReturns<U> addStep
Function T WorkflowThatReturns<U>
WorkflowThatReturns<Phone> workflow Speaker
nextTalk
getConference
getCity
Monad<T>
Monad<U> bind T Monad<U>
// or alternatively
Monad<T>
Monad<U> map T U
Monad<U> flatten Monad<Monad<U>>
Optional<T>
// ... constructors go here
Optional<U> flatMap T Optional<U> func
func
Optional
Enumerable
IEnumerable<U> SelectMany
IEnumerable<T>
T IEnumerable<U> func
func
CompletableFuture
CompletableFuture<U> thenCompose
T CompletableFuture<U>> func
// Some black magic happens here,
// but it works!!!
WORKFLOW
Talk talk
talk
talk
talk
async
talk await
await talk
await talk
MONADS
nextTalkCity async
let! nextTalk
let! getConference
let! getCity
nextTalkCity option
let! nextTalk
let! getConference
let! getCity
actor
let!
return!
MONAD
• To apply same approach to new
problems
• To talk to other developers
• It’s already in your language
• It’s getting used more
• Pattern
• Generic Container
• Workflow Builder
“
“
John De Goes,
who knows what
Monads are
Monads are virtual machines
for expressing sequential,
dependent computation,
where the instruction set of a
VM is given by the structure of
the monad's constructors
Monads Explained for OOP Developers
Monads Explained for OOP Developers

Contenu connexe

Similaire à Monads Explained for OOP Developers

MS Day EPITA 2010: Visual Studio 2010 et Framework .NET 4.0
MS Day EPITA 2010: Visual Studio 2010 et Framework .NET 4.0MS Day EPITA 2010: Visual Studio 2010 et Framework .NET 4.0
MS Day EPITA 2010: Visual Studio 2010 et Framework .NET 4.0Thomas Conté
 
Protocol-Oriented Programming in Swift
Protocol-Oriented Programming in SwiftProtocol-Oriented Programming in Swift
Protocol-Oriented Programming in SwiftOleksandr Stepanov
 
Refactoring for Software Architecture Smells - International Workshop on Refa...
Refactoring for Software Architecture Smells - International Workshop on Refa...Refactoring for Software Architecture Smells - International Workshop on Refa...
Refactoring for Software Architecture Smells - International Workshop on Refa...Ganesh Samarthyam
 
Visual Studio .NET2010
Visual Studio .NET2010Visual Studio .NET2010
Visual Studio .NET2010Satish Verma
 
Engineering Efficiency in LINE
Engineering Efficiency in LINEEngineering Efficiency in LINE
Engineering Efficiency in LINEHuy Do
 
Ruby on Rails vs ASP.NET MVC
Ruby on Rails vs ASP.NET MVCRuby on Rails vs ASP.NET MVC
Ruby on Rails vs ASP.NET MVCSimone Chiaretta
 
TypeScript Vs. KotlinJS
TypeScript Vs. KotlinJSTypeScript Vs. KotlinJS
TypeScript Vs. KotlinJSGarth Gilmour
 
Digibury: Edd Barrett - A Case Study in Cross-Language Tracing
Digibury: Edd Barrett - A Case Study in Cross-Language TracingDigibury: Edd Barrett - A Case Study in Cross-Language Tracing
Digibury: Edd Barrett - A Case Study in Cross-Language TracingLizzie Hodgson
 
Modern Release Engineering in a Nutshell - Why Researchers should Care!
Modern Release Engineering in a Nutshell - Why Researchers should Care!Modern Release Engineering in a Nutshell - Why Researchers should Care!
Modern Release Engineering in a Nutshell - Why Researchers should Care!Bram Adams
 
Building a Reactive RESTful API with Akka Http & Slick
Building a Reactive RESTful API with Akka Http & SlickBuilding a Reactive RESTful API with Akka Http & Slick
Building a Reactive RESTful API with Akka Http & SlickZalando Technology
 
Willow, the interaction tour by Maxi Tabacman
Willow, the interaction tour by Maxi TabacmanWillow, the interaction tour by Maxi Tabacman
Willow, the interaction tour by Maxi TabacmanFAST
 
[4DEV] Bartosz Sokół - Functional developer in object oriented world - how F#...
[4DEV] Bartosz Sokół - Functional developer in object oriented world - how F#...[4DEV] Bartosz Sokół - Functional developer in object oriented world - how F#...
[4DEV] Bartosz Sokół - Functional developer in object oriented world - how F#...PROIDEA
 
Rethink your architecture - Marten Deinum
Rethink your architecture - Marten DeinumRethink your architecture - Marten Deinum
Rethink your architecture - Marten DeinumNLJUG
 
LarKC Tutorial at ISWC 2009 - Urban Computing
LarKC Tutorial at ISWC 2009 - Urban ComputingLarKC Tutorial at ISWC 2009 - Urban Computing
LarKC Tutorial at ISWC 2009 - Urban ComputingLarKC
 
Transforming Forbes into a Technology Powerhouse with MongoDB
Transforming Forbes into a Technology Powerhouse with MongoDBTransforming Forbes into a Technology Powerhouse with MongoDB
Transforming Forbes into a Technology Powerhouse with MongoDBMongoDB
 
WebCamp: Developer Day: DDD in PHP on example of Symfony - Олег Зинченко
WebCamp: Developer Day: DDD in PHP on example of Symfony - Олег ЗинченкоWebCamp: Developer Day: DDD in PHP on example of Symfony - Олег Зинченко
WebCamp: Developer Day: DDD in PHP on example of Symfony - Олег ЗинченкоGeeksLab Odessa
 
Architectural Patterns in Building Modular Domain Models
Architectural Patterns in Building Modular Domain ModelsArchitectural Patterns in Building Modular Domain Models
Architectural Patterns in Building Modular Domain ModelsDebasish Ghosh
 

Similaire à Monads Explained for OOP Developers (20)

MS Day EPITA 2010: Visual Studio 2010 et Framework .NET 4.0
MS Day EPITA 2010: Visual Studio 2010 et Framework .NET 4.0MS Day EPITA 2010: Visual Studio 2010 et Framework .NET 4.0
MS Day EPITA 2010: Visual Studio 2010 et Framework .NET 4.0
 
Protocol-Oriented Programming in Swift
Protocol-Oriented Programming in SwiftProtocol-Oriented Programming in Swift
Protocol-Oriented Programming in Swift
 
Refactoring for Software Architecture Smells - International Workshop on Refa...
Refactoring for Software Architecture Smells - International Workshop on Refa...Refactoring for Software Architecture Smells - International Workshop on Refa...
Refactoring for Software Architecture Smells - International Workshop on Refa...
 
Visual Studio .NET2010
Visual Studio .NET2010Visual Studio .NET2010
Visual Studio .NET2010
 
Engineering Efficiency in LINE
Engineering Efficiency in LINEEngineering Efficiency in LINE
Engineering Efficiency in LINE
 
Ruby on Rails vs ASP.NET MVC
Ruby on Rails vs ASP.NET MVCRuby on Rails vs ASP.NET MVC
Ruby on Rails vs ASP.NET MVC
 
MLflow with R
MLflow with RMLflow with R
MLflow with R
 
TypeScript Vs. KotlinJS
TypeScript Vs. KotlinJSTypeScript Vs. KotlinJS
TypeScript Vs. KotlinJS
 
ONE_DSL4negotiations
ONE_DSL4negotiationsONE_DSL4negotiations
ONE_DSL4negotiations
 
Digibury: Edd Barrett - A Case Study in Cross-Language Tracing
Digibury: Edd Barrett - A Case Study in Cross-Language TracingDigibury: Edd Barrett - A Case Study in Cross-Language Tracing
Digibury: Edd Barrett - A Case Study in Cross-Language Tracing
 
Modern Release Engineering in a Nutshell - Why Researchers should Care!
Modern Release Engineering in a Nutshell - Why Researchers should Care!Modern Release Engineering in a Nutshell - Why Researchers should Care!
Modern Release Engineering in a Nutshell - Why Researchers should Care!
 
Building a Reactive RESTful API with Akka Http & Slick
Building a Reactive RESTful API with Akka Http & SlickBuilding a Reactive RESTful API with Akka Http & Slick
Building a Reactive RESTful API with Akka Http & Slick
 
Willow, the interaction tour by Maxi Tabacman
Willow, the interaction tour by Maxi TabacmanWillow, the interaction tour by Maxi Tabacman
Willow, the interaction tour by Maxi Tabacman
 
[4DEV] Bartosz Sokół - Functional developer in object oriented world - how F#...
[4DEV] Bartosz Sokół - Functional developer in object oriented world - how F#...[4DEV] Bartosz Sokół - Functional developer in object oriented world - how F#...
[4DEV] Bartosz Sokół - Functional developer in object oriented world - how F#...
 
Rethink your architecture - Marten Deinum
Rethink your architecture - Marten DeinumRethink your architecture - Marten Deinum
Rethink your architecture - Marten Deinum
 
LarKC Tutorial at ISWC 2009 - Urban Computing
LarKC Tutorial at ISWC 2009 - Urban ComputingLarKC Tutorial at ISWC 2009 - Urban Computing
LarKC Tutorial at ISWC 2009 - Urban Computing
 
Transforming Forbes into a Technology Powerhouse with MongoDB
Transforming Forbes into a Technology Powerhouse with MongoDBTransforming Forbes into a Technology Powerhouse with MongoDB
Transforming Forbes into a Technology Powerhouse with MongoDB
 
WebCamp: Developer Day: DDD in PHP on example of Symfony - Олег Зинченко
WebCamp: Developer Day: DDD in PHP on example of Symfony - Олег ЗинченкоWebCamp: Developer Day: DDD in PHP on example of Symfony - Олег Зинченко
WebCamp: Developer Day: DDD in PHP on example of Symfony - Олег Зинченко
 
Architectural Patterns in Building Modular Domain Models
Architectural Patterns in Building Modular Domain ModelsArchitectural Patterns in Building Modular Domain Models
Architectural Patterns in Building Modular Domain Models
 
Legacy is Good
Legacy is GoodLegacy is Good
Legacy is Good
 

Plus de ☁️ Mikhail Shilkov

Plus de ☁️ Mikhail Shilkov (8)

Performance Tales of Serverless - CloudNative London 2018
Performance Tales of Serverless - CloudNative London 2018Performance Tales of Serverless - CloudNative London 2018
Performance Tales of Serverless - CloudNative London 2018
 
Performance Tales of Serverless
Performance Tales of ServerlessPerformance Tales of Serverless
Performance Tales of Serverless
 
Azure F#unctions
Azure F#unctionsAzure F#unctions
Azure F#unctions
 
Azure F#unctions
Azure F#unctionsAzure F#unctions
Azure F#unctions
 
Event Driven Applications in F#
Event Driven Applications in F#Event Driven Applications in F#
Event Driven Applications in F#
 
Why Learn F# and Functional Programming
Why Learn F# and Functional ProgrammingWhy Learn F# and Functional Programming
Why Learn F# and Functional Programming
 
The taste of F#
The taste of F#The taste of F#
The taste of F#
 
Introduction of Functional Programming
Introduction of Functional ProgrammingIntroduction of Functional Programming
Introduction of Functional Programming
 

Dernier

Dreaming Marissa Sánchez Music Video Treatment
Dreaming Marissa Sánchez Music Video TreatmentDreaming Marissa Sánchez Music Video Treatment
Dreaming Marissa Sánchez Music Video Treatmentnswingard
 
SOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdf
SOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdfSOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdf
SOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdfMahamudul Hasan
 
My Presentation "In Your Hands" by Halle Bailey
My Presentation "In Your Hands" by Halle BaileyMy Presentation "In Your Hands" by Halle Bailey
My Presentation "In Your Hands" by Halle Baileyhlharris
 
lONG QUESTION ANSWER PAKISTAN STUDIES10.
lONG QUESTION ANSWER PAKISTAN STUDIES10.lONG QUESTION ANSWER PAKISTAN STUDIES10.
lONG QUESTION ANSWER PAKISTAN STUDIES10.lodhisaajjda
 
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...amilabibi1
 
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...David Celestin
 
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdfAWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdfSkillCertProExams
 
Dreaming Music Video Treatment _ Project & Portfolio III
Dreaming Music Video Treatment _ Project & Portfolio IIIDreaming Music Video Treatment _ Project & Portfolio III
Dreaming Music Video Treatment _ Project & Portfolio IIINhPhngng3
 
Report Writing Webinar Training
Report Writing Webinar TrainingReport Writing Webinar Training
Report Writing Webinar TrainingKylaCullinane
 
The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdf
The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdfThe workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdf
The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdfSenaatti-kiinteistöt
 
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptxChiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptxraffaeleoman
 
Digital collaboration with Microsoft 365 as extension of Drupal
Digital collaboration with Microsoft 365 as extension of DrupalDigital collaboration with Microsoft 365 as extension of Drupal
Digital collaboration with Microsoft 365 as extension of DrupalFabian de Rijk
 
If this Giant Must Walk: A Manifesto for a New Nigeria
If this Giant Must Walk: A Manifesto for a New NigeriaIf this Giant Must Walk: A Manifesto for a New Nigeria
If this Giant Must Walk: A Manifesto for a New NigeriaKayode Fayemi
 
Uncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac FolorunsoUncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac FolorunsoKayode Fayemi
 

Dernier (15)

Dreaming Marissa Sánchez Music Video Treatment
Dreaming Marissa Sánchez Music Video TreatmentDreaming Marissa Sánchez Music Video Treatment
Dreaming Marissa Sánchez Music Video Treatment
 
SOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdf
SOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdfSOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdf
SOLID WASTE MANAGEMENT SYSTEM OF FENI PAURASHAVA, BANGLADESH.pdf
 
My Presentation "In Your Hands" by Halle Bailey
My Presentation "In Your Hands" by Halle BaileyMy Presentation "In Your Hands" by Halle Bailey
My Presentation "In Your Hands" by Halle Bailey
 
lONG QUESTION ANSWER PAKISTAN STUDIES10.
lONG QUESTION ANSWER PAKISTAN STUDIES10.lONG QUESTION ANSWER PAKISTAN STUDIES10.
lONG QUESTION ANSWER PAKISTAN STUDIES10.
 
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
 
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
Proofreading- Basics to Artificial Intelligence Integration - Presentation:Sl...
 
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdfAWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
 
Dreaming Music Video Treatment _ Project & Portfolio III
Dreaming Music Video Treatment _ Project & Portfolio IIIDreaming Music Video Treatment _ Project & Portfolio III
Dreaming Music Video Treatment _ Project & Portfolio III
 
Report Writing Webinar Training
Report Writing Webinar TrainingReport Writing Webinar Training
Report Writing Webinar Training
 
The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdf
The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdfThe workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdf
The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdf
 
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptxChiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
 
Digital collaboration with Microsoft 365 as extension of Drupal
Digital collaboration with Microsoft 365 as extension of DrupalDigital collaboration with Microsoft 365 as extension of Drupal
Digital collaboration with Microsoft 365 as extension of Drupal
 
ICT role in 21st century education and it's challenges.pdf
ICT role in 21st century education and it's challenges.pdfICT role in 21st century education and it's challenges.pdf
ICT role in 21st century education and it's challenges.pdf
 
If this Giant Must Walk: A Manifesto for a New Nigeria
If this Giant Must Walk: A Manifesto for a New NigeriaIf this Giant Must Walk: A Manifesto for a New Nigeria
If this Giant Must Walk: A Manifesto for a New Nigeria
 
Uncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac FolorunsoUncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac Folorunso
 

Monads Explained for OOP Developers