SlideShare ist ein Scribd-Unternehmen logo
1 von 38
Downloaden Sie, um offline zu lesen
Functional Programming

beyond map/filter/reduce
JFokus 2018
Prof. Dierk König
canoo
mittie
Monads

are just

monoids in the category
of endofunctors.
Explanation Path
Monoid it's simple
Functor you already know it
Endo- cool idea
Monoid of endofunctors = monad
Integers (+)
2 + 3 == 5 

2 + 0 == 2 

0 + 3 == 3 

( 1+2 )+3 == 1+( 2+3 )
Integers (*)
2 * 3 == 6 

2 * 1 == 2 

1 * 3 == 3 

( 2*3 )*4 == 2*( 3*4 )
Boolean (&&)
a && b == c 

a && true == a 

true && b == b 

( a && b ) && c == a &&( b && c )
Lists, Arrays (+)
[1] + [2] == [1, 2]

[1] + [ ] == [1]

[ ] + [2] == [2]

([1]+[2])+[3] == [1]+([2]+[3])
Strings (+)
"1" + "2" == "12"

"1" + "" == "1"

"" + "2" == "2"

( "Hi"+"," )+"JFokus" == 

"Hi"+( ","+"JFokus" )
Extract
type <> type => type
neutral element
left & right identity
associative
Abstract
We call this concept "Monoid"

short for "that thing, you know, that you can combine
with another thing of the same type to produce a new
thing of the type of the other two as long as there is a
value of that type that when combined left or right does
not change the value you combined that special value
with and any such combination must yield the same
result no matter which two you combine first."
LEGO Monoid
LEGO Monoid
LEGO Monoid
LEGO Neutral Brick
LEGO Left & Right Identity
Generic Fold Right
Generic Fold Right
Generic Fold Right
Generic Fold Right
Generic Optimized Fold
Generic Optimized Fold
Generic Optimized Fold
Crazy Monoids
(a -> b) <> (b -> c) == (a -> c)
Can a function type (a->b) be a monoid?
What is the operation?
What is the neutral element?
Is it associative?
Function Composition
co(f,g) = x => f(g(x));
id(x) = x;
co(id,g) == x => id(g(x)) // definition co

== x => g(x) // apply id

== g // qed
Functors map
[1, 2, 3].map( x=> x+2 ) == [3, 4, 5]
(Just 1).map( x=> x+2 ) == Just 3
Nothing.map( whatever ) == Nothing
List, Tree, Stream, Optional, Pipeline, Error,
Validation, Observable, Future, Promise,..
Functors compose
[1, 2, 3].map( x => x + 2 )

.map( x => 3 * x ) 

==

[1, 2, 3].map( x => 3 * (x+2) )
co( functor.map(f), functor.map(g) ) 

== functor.map( co(f, g) )
functor.map(id) == id // only for completeness
Functors are not Monoids
[1, 2, 3] .map( x => x.toString() ) == ["1","2","3"]
[Int] .map( Int -> String ) -> [String]
functor a .map( a -> b) -> functor b
Clever Idea:
instead of (a->b)

provide a special mapping with (a -> functor b),

which is essentially a constructor for functors.


functor a <> functor b => functor b

functor a .endo(a->functor b) => functor b
Clever Idea in Action
[1, 2, 3].endo( x => replicate(x, x.toString()) ) ==

[ ["1"], ["2","2"], ["3","3","3"] ]
then flatten => ["1", "2", "2", "3", "3", "3"] //aka "join"
funcA.flatMap(f) = funcB.flatten(funcA.endo(f))
// aka "bind" or ">>="
Finalising the Monoid
functor a .flatMap(a->functor b) => functor b



(a->functor a) <> (a->functor b) => (a->functor b)
We need an (a-> functor a) ctor and flatMap (we
already have map, so we only need flatten). If the
functor is monoidal with flatMap as <> and ctor as
neutal element, then we call it a Monad.
Wrapping up
Let (m a) be a given monad over type a.

(m a) has a ctor (a -> m a). // aka "return" or "pure"

(m a) is a functor over a. 

(m (m a)) can be flattened to (m a).

(a-> m a).flatMap( a -> m b) is a monoidal operation.
Alternative way of writing in pure FP style

(>>=) :: Monad m => m a -> (a -> m b) -> m b
Takeaways
Associativity (monoid) requires pure functions.
Monoids can fold but they cannot escape.
Monads are the most versatile functors (map, filter,
expand, reduce) that composes and folds without
escaping.
Use Cases
Purely functional state threads

List comprehensions, Streams (possibly reactive)

CompletableFuture, Promises, Continuations

LINQ-style database access

Either, Validation, Exception handling

Optionality, Indeterminism, Parsers, Search trees

Sequencing IO actions, isolating UI actions

STM transactions, …
No IO in Transactions!
Type inference FTW
Less	tricky

errors
There is a world…
… where logical reasoning rules and structure
arises from consistency and a rich set of relations.
Exploring this world is like programming without
implementation.
Purely functional programming opens the door.

Consider Haskell, Frege, Purescript, Idris.
mittie
Please give feedback!
Prof. Dierk König
canoo

Weitere ähnliche Inhalte

Was ist angesagt?

Composite functions
Composite functionsComposite functions
Composite functionsShaun Wilson
 
2.4 operations on functions
2.4 operations on functions2.4 operations on functions
2.4 operations on functionshisema01
 
Operations With Functions May 25 2009
Operations With Functions May 25 2009Operations With Functions May 25 2009
Operations With Functions May 25 2009ingroy
 
Gentle Introduction to Functional Programming
Gentle Introduction to Functional ProgrammingGentle Introduction to Functional Programming
Gentle Introduction to Functional ProgrammingSaurabh Singh
 
Day 4b iteration and functions for-loops.pptx
Day 4b   iteration and functions  for-loops.pptxDay 4b   iteration and functions  for-loops.pptx
Day 4b iteration and functions for-loops.pptxAdrien Melquiond
 
Day 5 examples u6w14
Day 5 examples u6w14Day 5 examples u6w14
Day 5 examples u6w14jchartiersjsd
 
2.1 the basic language of functions t
2.1 the basic language of functions  t2.1 the basic language of functions  t
2.1 the basic language of functions tmath260
 
Day 4a iteration and functions.pptx
Day 4a   iteration and functions.pptxDay 4a   iteration and functions.pptx
Day 4a iteration and functions.pptxAdrien Melquiond
 
Exercise 2
Exercise 2Exercise 2
Exercise 2math126
 
Translating Linear Functions "I AM" Answer Key!
Translating Linear Functions "I AM" Answer Key!Translating Linear Functions "I AM" Answer Key!
Translating Linear Functions "I AM" Answer Key!Deborah_Johnson
 
4 2 operations on functions
4 2 operations on functions4 2 operations on functions
4 2 operations on functionshisema01
 
119 Powerpoint 2.6
119 Powerpoint 2.6119 Powerpoint 2.6
119 Powerpoint 2.6Jeneva Clark
 
Admission for b.tech
Admission for b.techAdmission for b.tech
Admission for b.techEdhole.com
 
Math - Operations on Functions, Kinds of Functions
Math - Operations on Functions, Kinds of FunctionsMath - Operations on Functions, Kinds of Functions
Math - Operations on Functions, Kinds of FunctionsChuckie Balbuena
 
Quadratic functions
Quadratic functionsQuadratic functions
Quadratic functionsIvy Estrella
 

Was ist angesagt? (20)

Composite functions
Composite functionsComposite functions
Composite functions
 
2.4 operations on functions
2.4 operations on functions2.4 operations on functions
2.4 operations on functions
 
Operations With Functions May 25 2009
Operations With Functions May 25 2009Operations With Functions May 25 2009
Operations With Functions May 25 2009
 
Gentle Introduction to Functional Programming
Gentle Introduction to Functional ProgrammingGentle Introduction to Functional Programming
Gentle Introduction to Functional Programming
 
Day 4b iteration and functions for-loops.pptx
Day 4b   iteration and functions  for-loops.pptxDay 4b   iteration and functions  for-loops.pptx
Day 4b iteration and functions for-loops.pptx
 
Day 5 examples u6w14
Day 5 examples u6w14Day 5 examples u6w14
Day 5 examples u6w14
 
2.1 the basic language of functions t
2.1 the basic language of functions  t2.1 the basic language of functions  t
2.1 the basic language of functions t
 
Day 4a iteration and functions.pptx
Day 4a   iteration and functions.pptxDay 4a   iteration and functions.pptx
Day 4a iteration and functions.pptx
 
Exercise 2
Exercise 2Exercise 2
Exercise 2
 
Day 5 u8f13
Day 5 u8f13Day 5 u8f13
Day 5 u8f13
 
Translating Linear Functions "I AM" Answer Key!
Translating Linear Functions "I AM" Answer Key!Translating Linear Functions "I AM" Answer Key!
Translating Linear Functions "I AM" Answer Key!
 
4 2 operations on functions
4 2 operations on functions4 2 operations on functions
4 2 operations on functions
 
Array and pointer
Array and pointerArray and pointer
Array and pointer
 
119 Powerpoint 2.6
119 Powerpoint 2.6119 Powerpoint 2.6
119 Powerpoint 2.6
 
Admission for b.tech
Admission for b.techAdmission for b.tech
Admission for b.tech
 
Math - Operations on Functions, Kinds of Functions
Math - Operations on Functions, Kinds of FunctionsMath - Operations on Functions, Kinds of Functions
Math - Operations on Functions, Kinds of Functions
 
Lesson 3 Operation on Functions
Lesson 3 Operation on FunctionsLesson 3 Operation on Functions
Lesson 3 Operation on Functions
 
Function : Introduction
Function : IntroductionFunction : Introduction
Function : Introduction
 
Quadratic functions
Quadratic functionsQuadratic functions
Quadratic functions
 
Ch18 18
Ch18 18Ch18 18
Ch18 18
 

Ähnlich wie Monads from Definition

하스켈 프로그래밍 입문 4
하스켈 프로그래밍 입문 4하스켈 프로그래밍 입문 4
하스켈 프로그래밍 입문 4Kwang Yul Seo
 
Grokking Monads in Scala
Grokking Monads in ScalaGrokking Monads in Scala
Grokking Monads in ScalaTim Dalton
 
Functors, applicatives, monads
Functors, applicatives, monadsFunctors, applicatives, monads
Functors, applicatives, monadsrkaippully
 
Fp in scala with adts
Fp in scala with adtsFp in scala with adts
Fp in scala with adtsHang Zhao
 
Introduction to Monads in Scala (2)
Introduction to Monads in Scala (2)Introduction to Monads in Scala (2)
Introduction to Monads in Scala (2)stasimus
 
Monoids, monoids, monoids
Monoids, monoids, monoidsMonoids, monoids, monoids
Monoids, monoids, monoidsLuka Jacobowitz
 
Functional programming from its fundamentals
Functional programming from its fundamentalsFunctional programming from its fundamentals
Functional programming from its fundamentalsMauro Palsgraaf
 
The Essence of the Iterator Pattern
The Essence of the Iterator PatternThe Essence of the Iterator Pattern
The Essence of the Iterator PatternEric Torreborre
 
The Essence of the Iterator Pattern (pdf)
The Essence of the Iterator Pattern (pdf)The Essence of the Iterator Pattern (pdf)
The Essence of the Iterator Pattern (pdf)Eric Torreborre
 
Christian Gill ''Functional programming for the people''
Christian Gill ''Functional programming for the people''Christian Gill ''Functional programming for the people''
Christian Gill ''Functional programming for the people''OdessaJS Conf
 
Monad Transformers In The Wild
Monad Transformers In The WildMonad Transformers In The Wild
Monad Transformers In The WildStackMob Inc
 
JSDC 2014 - functional java script, why or why not
JSDC 2014 - functional java script, why or why notJSDC 2014 - functional java script, why or why not
JSDC 2014 - functional java script, why or why notChengHui Weng
 
Use Applicative where applicable!
Use Applicative where applicable!Use Applicative where applicable!
Use Applicative where applicable!Hermann Hueck
 
Unit 8(rational expressions) week 22 - simplifying rational expressions
Unit 8(rational expressions)   week 22 - simplifying rational expressionsUnit 8(rational expressions)   week 22 - simplifying rational expressions
Unit 8(rational expressions) week 22 - simplifying rational expressionsJason Morgan
 
Fp in scala part 2
Fp in scala part 2Fp in scala part 2
Fp in scala part 2Hang Zhao
 

Ähnlich wie Monads from Definition (20)

하스켈 프로그래밍 입문 4
하스켈 프로그래밍 입문 4하스켈 프로그래밍 입문 4
하스켈 프로그래밍 입문 4
 
Grokking Monads in Scala
Grokking Monads in ScalaGrokking Monads in Scala
Grokking Monads in Scala
 
Functors, applicatives, monads
Functors, applicatives, monadsFunctors, applicatives, monads
Functors, applicatives, monads
 
Fp in scala with adts
Fp in scala with adtsFp in scala with adts
Fp in scala with adts
 
Introduction to Monads in Scala (2)
Introduction to Monads in Scala (2)Introduction to Monads in Scala (2)
Introduction to Monads in Scala (2)
 
MP in Clojure
MP in ClojureMP in Clojure
MP in Clojure
 
Monoids, monoids, monoids
Monoids, monoids, monoidsMonoids, monoids, monoids
Monoids, monoids, monoids
 
Functional programming from its fundamentals
Functional programming from its fundamentalsFunctional programming from its fundamentals
Functional programming from its fundamentals
 
The Essence of the Iterator Pattern
The Essence of the Iterator PatternThe Essence of the Iterator Pattern
The Essence of the Iterator Pattern
 
The Essence of the Iterator Pattern (pdf)
The Essence of the Iterator Pattern (pdf)The Essence of the Iterator Pattern (pdf)
The Essence of the Iterator Pattern (pdf)
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
 
Class XII CBSE Mathematics Sample question paper with solution
Class XII CBSE Mathematics Sample question paper with solutionClass XII CBSE Mathematics Sample question paper with solution
Class XII CBSE Mathematics Sample question paper with solution
 
Christian Gill ''Functional programming for the people''
Christian Gill ''Functional programming for the people''Christian Gill ''Functional programming for the people''
Christian Gill ''Functional programming for the people''
 
Monad Transformers In The Wild
Monad Transformers In The WildMonad Transformers In The Wild
Monad Transformers In The Wild
 
JSDC 2014 - functional java script, why or why not
JSDC 2014 - functional java script, why or why notJSDC 2014 - functional java script, why or why not
JSDC 2014 - functional java script, why or why not
 
Use Applicative where applicable!
Use Applicative where applicable!Use Applicative where applicable!
Use Applicative where applicable!
 
Efoom 2020
Efoom 2020Efoom 2020
Efoom 2020
 
Unit 8(rational expressions) week 22 - simplifying rational expressions
Unit 8(rational expressions)   week 22 - simplifying rational expressionsUnit 8(rational expressions)   week 22 - simplifying rational expressions
Unit 8(rational expressions) week 22 - simplifying rational expressions
 
Fp in scala part 2
Fp in scala part 2Fp in scala part 2
Fp in scala part 2
 
Monad Fact #4
Monad Fact #4Monad Fact #4
Monad Fact #4
 

Mehr von Dierk König

OpenDolphin with GroovyFX Workshop at GreachConf, Madrid
OpenDolphin with GroovyFX Workshop at GreachConf, MadridOpenDolphin with GroovyFX Workshop at GreachConf, Madrid
OpenDolphin with GroovyFX Workshop at GreachConf, MadridDierk König
 
Greach, GroovyFx Workshop
Greach, GroovyFx WorkshopGreach, GroovyFx Workshop
Greach, GroovyFx WorkshopDierk König
 
FregeFX - JavaFX with Frege, a Haskell for the JVM
FregeFX - JavaFX with Frege, a Haskell for the JVMFregeFX - JavaFX with Frege, a Haskell for the JVM
FregeFX - JavaFX with Frege, a Haskell for the JVMDierk König
 
Software Transactional Memory (STM) in Frege
Software Transactional Memory (STM) in Frege Software Transactional Memory (STM) in Frege
Software Transactional Memory (STM) in Frege Dierk König
 
Quick into to Software Transactional Memory in Frege
Quick into to Software Transactional Memory in FregeQuick into to Software Transactional Memory in Frege
Quick into to Software Transactional Memory in FregeDierk König
 
Frege Tutorial at JavaOne 2015
Frege Tutorial at JavaOne 2015Frege Tutorial at JavaOne 2015
Frege Tutorial at JavaOne 2015Dierk König
 
Frege - consequently functional programming for the JVM
Frege - consequently functional programming for the JVMFrege - consequently functional programming for the JVM
Frege - consequently functional programming for the JVMDierk König
 
FregeDay: Parallelism in Frege compared to GHC Haskell (Volker Steiss)
FregeDay: Parallelism in Frege compared to GHC Haskell (Volker Steiss) FregeDay: Parallelism in Frege compared to GHC Haskell (Volker Steiss)
FregeDay: Parallelism in Frege compared to GHC Haskell (Volker Steiss) Dierk König
 
FregeDay: Design and Implementation of the language (Ingo Wechsung)
FregeDay: Design and Implementation of the language (Ingo Wechsung)FregeDay: Design and Implementation of the language (Ingo Wechsung)
FregeDay: Design and Implementation of the language (Ingo Wechsung)Dierk König
 
FregeDay: Roadmap for resolving differences between Haskell and Frege (Ingo W...
FregeDay: Roadmap for resolving differences between Haskell and Frege (Ingo W...FregeDay: Roadmap for resolving differences between Haskell and Frege (Ingo W...
FregeDay: Roadmap for resolving differences between Haskell and Frege (Ingo W...Dierk König
 
UI Engineer - the missing profession, devoxx 2013
UI Engineer - the missing profession, devoxx 2013UI Engineer - the missing profession, devoxx 2013
UI Engineer - the missing profession, devoxx 2013Dierk König
 
OpenDolphin: Enterprise Apps for collaboration on Desktop, Web, and Mobile
OpenDolphin: Enterprise Apps for collaboration on Desktop, Web, and MobileOpenDolphin: Enterprise Apps for collaboration on Desktop, Web, and Mobile
OpenDolphin: Enterprise Apps for collaboration on Desktop, Web, and MobileDierk König
 

Mehr von Dierk König (12)

OpenDolphin with GroovyFX Workshop at GreachConf, Madrid
OpenDolphin with GroovyFX Workshop at GreachConf, MadridOpenDolphin with GroovyFX Workshop at GreachConf, Madrid
OpenDolphin with GroovyFX Workshop at GreachConf, Madrid
 
Greach, GroovyFx Workshop
Greach, GroovyFx WorkshopGreach, GroovyFx Workshop
Greach, GroovyFx Workshop
 
FregeFX - JavaFX with Frege, a Haskell for the JVM
FregeFX - JavaFX with Frege, a Haskell for the JVMFregeFX - JavaFX with Frege, a Haskell for the JVM
FregeFX - JavaFX with Frege, a Haskell for the JVM
 
Software Transactional Memory (STM) in Frege
Software Transactional Memory (STM) in Frege Software Transactional Memory (STM) in Frege
Software Transactional Memory (STM) in Frege
 
Quick into to Software Transactional Memory in Frege
Quick into to Software Transactional Memory in FregeQuick into to Software Transactional Memory in Frege
Quick into to Software Transactional Memory in Frege
 
Frege Tutorial at JavaOne 2015
Frege Tutorial at JavaOne 2015Frege Tutorial at JavaOne 2015
Frege Tutorial at JavaOne 2015
 
Frege - consequently functional programming for the JVM
Frege - consequently functional programming for the JVMFrege - consequently functional programming for the JVM
Frege - consequently functional programming for the JVM
 
FregeDay: Parallelism in Frege compared to GHC Haskell (Volker Steiss)
FregeDay: Parallelism in Frege compared to GHC Haskell (Volker Steiss) FregeDay: Parallelism in Frege compared to GHC Haskell (Volker Steiss)
FregeDay: Parallelism in Frege compared to GHC Haskell (Volker Steiss)
 
FregeDay: Design and Implementation of the language (Ingo Wechsung)
FregeDay: Design and Implementation of the language (Ingo Wechsung)FregeDay: Design and Implementation of the language (Ingo Wechsung)
FregeDay: Design and Implementation of the language (Ingo Wechsung)
 
FregeDay: Roadmap for resolving differences between Haskell and Frege (Ingo W...
FregeDay: Roadmap for resolving differences between Haskell and Frege (Ingo W...FregeDay: Roadmap for resolving differences between Haskell and Frege (Ingo W...
FregeDay: Roadmap for resolving differences between Haskell and Frege (Ingo W...
 
UI Engineer - the missing profession, devoxx 2013
UI Engineer - the missing profession, devoxx 2013UI Engineer - the missing profession, devoxx 2013
UI Engineer - the missing profession, devoxx 2013
 
OpenDolphin: Enterprise Apps for collaboration on Desktop, Web, and Mobile
OpenDolphin: Enterprise Apps for collaboration on Desktop, Web, and MobileOpenDolphin: Enterprise Apps for collaboration on Desktop, Web, and Mobile
OpenDolphin: Enterprise Apps for collaboration on Desktop, Web, and Mobile
 

Kürzlich hochgeladen

(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 

Kürzlich hochgeladen (20)

(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 

Monads from Definition

  • 3. Monads
 are just
 monoids in the category of endofunctors.
  • 4. Explanation Path Monoid it's simple Functor you already know it Endo- cool idea Monoid of endofunctors = monad
  • 5. Integers (+) 2 + 3 == 5 
 2 + 0 == 2 
 0 + 3 == 3 
 ( 1+2 )+3 == 1+( 2+3 )
  • 6. Integers (*) 2 * 3 == 6 
 2 * 1 == 2 
 1 * 3 == 3 
 ( 2*3 )*4 == 2*( 3*4 )
  • 7. Boolean (&&) a && b == c 
 a && true == a 
 true && b == b 
 ( a && b ) && c == a &&( b && c )
  • 8. Lists, Arrays (+) [1] + [2] == [1, 2]
 [1] + [ ] == [1]
 [ ] + [2] == [2]
 ([1]+[2])+[3] == [1]+([2]+[3])
  • 9. Strings (+) "1" + "2" == "12"
 "1" + "" == "1"
 "" + "2" == "2"
 ( "Hi"+"," )+"JFokus" == 
 "Hi"+( ","+"JFokus" )
  • 10. Extract type <> type => type neutral element left & right identity associative
  • 11. Abstract We call this concept "Monoid"
 short for "that thing, you know, that you can combine with another thing of the same type to produce a new thing of the type of the other two as long as there is a value of that type that when combined left or right does not change the value you combined that special value with and any such combination must yield the same result no matter which two you combine first."
  • 16. LEGO Left & Right Identity
  • 24. Crazy Monoids (a -> b) <> (b -> c) == (a -> c) Can a function type (a->b) be a monoid? What is the operation? What is the neutral element? Is it associative?
  • 25. Function Composition co(f,g) = x => f(g(x)); id(x) = x; co(id,g) == x => id(g(x)) // definition co
 == x => g(x) // apply id
 == g // qed
  • 26. Functors map [1, 2, 3].map( x=> x+2 ) == [3, 4, 5] (Just 1).map( x=> x+2 ) == Just 3 Nothing.map( whatever ) == Nothing List, Tree, Stream, Optional, Pipeline, Error, Validation, Observable, Future, Promise,..
  • 27. Functors compose [1, 2, 3].map( x => x + 2 )
 .map( x => 3 * x ) 
 ==
 [1, 2, 3].map( x => 3 * (x+2) ) co( functor.map(f), functor.map(g) ) 
 == functor.map( co(f, g) ) functor.map(id) == id // only for completeness
  • 28. Functors are not Monoids [1, 2, 3] .map( x => x.toString() ) == ["1","2","3"] [Int] .map( Int -> String ) -> [String] functor a .map( a -> b) -> functor b
  • 29. Clever Idea: instead of (a->b)
 provide a special mapping with (a -> functor b),
 which is essentially a constructor for functors. 
 functor a <> functor b => functor b
 functor a .endo(a->functor b) => functor b
  • 30. Clever Idea in Action [1, 2, 3].endo( x => replicate(x, x.toString()) ) ==
 [ ["1"], ["2","2"], ["3","3","3"] ] then flatten => ["1", "2", "2", "3", "3", "3"] //aka "join" funcA.flatMap(f) = funcB.flatten(funcA.endo(f)) // aka "bind" or ">>="
  • 31. Finalising the Monoid functor a .flatMap(a->functor b) => functor b
 
 (a->functor a) <> (a->functor b) => (a->functor b) We need an (a-> functor a) ctor and flatMap (we already have map, so we only need flatten). If the functor is monoidal with flatMap as <> and ctor as neutal element, then we call it a Monad.
  • 32. Wrapping up Let (m a) be a given monad over type a.
 (m a) has a ctor (a -> m a). // aka "return" or "pure"
 (m a) is a functor over a. 
 (m (m a)) can be flattened to (m a).
 (a-> m a).flatMap( a -> m b) is a monoidal operation. Alternative way of writing in pure FP style
 (>>=) :: Monad m => m a -> (a -> m b) -> m b
  • 33. Takeaways Associativity (monoid) requires pure functions. Monoids can fold but they cannot escape. Monads are the most versatile functors (map, filter, expand, reduce) that composes and folds without escaping.
  • 34. Use Cases Purely functional state threads
 List comprehensions, Streams (possibly reactive)
 CompletableFuture, Promises, Continuations
 LINQ-style database access
 Either, Validation, Exception handling
 Optionality, Indeterminism, Parsers, Search trees
 Sequencing IO actions, isolating UI actions
 STM transactions, …
  • 35. No IO in Transactions!
  • 37. There is a world… … where logical reasoning rules and structure arises from consistency and a rich set of relations. Exploring this world is like programming without implementation. Purely functional programming opens the door.
 Consider Haskell, Frege, Purescript, Idris.