SlideShare a Scribd company logo
1 of 31
Paradigm Blend
Knowledge Gap for Devs
Those interested in Monads have no good
starting places
Category Theory
Functional abstractions are
patterns
Origin in math
What’s a Monad?
A Monad is just a Monoid in the category
of endofunctors
Monads are not
metaphors
Functors
From the ground up
Functors are containers
Type Constructors - F[A]
Functors need to have a Map function
                        map
You did take PLP with Wallingford,
right?
def map[A,B](cont: List[A], f: A => B)
Apply the function f to each element
Higher Order Functions
Higher Order Functions
Functors need a map method
Functors are containers
Lift arity-1 function to a function
that works on computational
context
Applicative Functors
Applicative Functors
currying functions is fun
Lifts an n-arity function to work on
computational context through
currying.
Currying?


x => (y => x + y)
Applicative is just a more generalized Functor
Applicative Style

pure(+) <*> pure(3) <*> pure(4)
Recap:
 Functors lift 1-arity
 Applic lift n-arity
Monoid
a distant cousin
Type-class which have values that can
be combined
Binary operation must be associative
object StringMonoid {
   def mAppend(x: String, y: String): String = x + y
   def mEmpty: String = ""
 }
Monad
The Main Attraction
Structure computations
Compose functions of different types that can
be logically combined
Monads in a purely functional language
(Haskell)
Monads in Scala
case class Identity[A](value: A) {
  def map[B](f: A => B) = Identity(f(value))
  def flatMap[B](f: A => Identity[B]) (value)
  def unit(a: A) = Identity(a)
}
object Monoid {
   def append(a1: List[A], a2: List[A]) = a1 ::: a2
   def empty = Nil
 }
case class Writer[Log, A](log: Log, value: A) {
 def map[B](f: A => B) = Writer(log, f(value))

    def flatMap[B](f: A => Writer[Log, B])(m: Monoid[Log]) = {
      val x: Writer[Log,B] = f(value)
      Writer(m.append(log, x.log), x.value)
    }
    def unit[Log, A](value: A)(m: Monoid[Log]) =
      Writer(m.empty, value)
}
def main(args: Array[String]) {
   val start = 3
   val finalWriter =
    for(a <- addOne(start);
       b <- intString(a);
       c <- lengthGreaterThan5(b);
       d <- noLog(oneOrZero(c));
       e <- squareOf(d)
      ) yield e
 }

“Adding one to 3.
Changing 4 to a String.
Checking if length is greater than 5.
Squaring 1.”
FIN?
Monads and Scala
For - Comprehensions
Scala has Monads everywhere!
Scala recognizes monadic code.
val first = List(1)
val second = List(4)
val third = List(8)

for {                  first flatMap {
  x <- first             x => second flatMap {
  y <- second              y=> third map {
  z <- third                 z => x + y + z
}                          )
yield ( x + y + z)       )
                       )
case class Transaction(memberInfo: Option[MemberInfo], id: String)
case class MemberInfo(privateInfo: Option[PrivateMember], birthdate:
String)
case class PrivateInfo(socialSecurityNumber: String)

val ssNumber = “389-39-2983”
val priv = PrivateInfo(ssNumber)
val member = MemberInfo(priv, “10-20-87”)
val optionalTransaction = Transaction(member, “28948”)

for {
  transaction <- optionalTransaction
  memberInfo <- transaction.memberInfo
  privInformation <- memberInfo.privateInfo
}
yield privInformation.socialSecurityNumber

More Related Content

What's hot

Modular Module Systems
Modular Module SystemsModular Module Systems
Modular Module Systems
league
 

What's hot (18)

Functional Programming in Swift
Functional Programming in SwiftFunctional Programming in Swift
Functional Programming in Swift
 
Templates
TemplatesTemplates
Templates
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Modular Module Systems
Modular Module SystemsModular Module Systems
Modular Module Systems
 
Bcsl 033 data and file structures lab s4-2
Bcsl 033 data and file structures lab s4-2Bcsl 033 data and file structures lab s4-2
Bcsl 033 data and file structures lab s4-2
 
Type-level programming
Type-level programmingType-level programming
Type-level programming
 
Traversals for all ocasions
Traversals for all ocasionsTraversals for all ocasions
Traversals for all ocasions
 
Tools for research plotting
Tools for research plottingTools for research plotting
Tools for research plotting
 
An introduction to matlab
An introduction to matlabAn introduction to matlab
An introduction to matlab
 
Map, Reduce and Filter in Swift
Map, Reduce and Filter in SwiftMap, Reduce and Filter in Swift
Map, Reduce and Filter in Swift
 
Linked list searching deleting inserting
Linked list searching deleting insertingLinked list searching deleting inserting
Linked list searching deleting inserting
 
week-21x
week-21xweek-21x
week-21x
 
Lecture 21.07.2014
Lecture 21.07.2014Lecture 21.07.2014
Lecture 21.07.2014
 
Testing in the World of Functional Programming
Testing in the World of Functional ProgrammingTesting in the World of Functional Programming
Testing in the World of Functional Programming
 
Essence of the iterator pattern
Essence of the iterator patternEssence of the iterator pattern
Essence of the iterator pattern
 
Principled Error Handling with FP
Principled Error Handling with FPPrincipled Error Handling with FP
Principled Error Handling with FP
 
SATySFiのこれからの課題たち
SATySFiのこれからの課題たちSATySFiのこれからの課題たち
SATySFiのこれからの課題たち
 
Legacy lambda code
Legacy lambda codeLegacy lambda code
Legacy lambda code
 

Similar to Thesis PPT

Types by Adform Research
Types by Adform ResearchTypes by Adform Research
Types by Adform Research
Vasil Remeniuk
 
Algebraic Data Types and Origami Patterns
Algebraic Data Types and Origami PatternsAlgebraic Data Types and Origami Patterns
Algebraic Data Types and Origami Patterns
Vasil Remeniuk
 
High Wizardry in the Land of Scala
High Wizardry in the Land of ScalaHigh Wizardry in the Land of Scala
High Wizardry in the Land of Scala
djspiewak
 

Similar to Thesis PPT (20)

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)
 
Oh, All the things you'll traverse
Oh, All the things you'll traverseOh, All the things you'll traverse
Oh, All the things you'll traverse
 
Monads and friends demystified
Monads and friends demystifiedMonads and friends demystified
Monads and friends demystified
 
Types by Adform Research
Types by Adform ResearchTypes by Adform Research
Types by Adform Research
 
Functional programming in scala
Functional programming in scalaFunctional programming in scala
Functional programming in scala
 
Fp in scala with adts
Fp in scala with adtsFp in scala with adts
Fp in scala with adts
 
(2015 06-16) Three Approaches to Monads
(2015 06-16) Three Approaches to Monads(2015 06-16) Three Approaches to Monads
(2015 06-16) Three Approaches to Monads
 
Scala Functional Patterns
Scala Functional PatternsScala Functional Patterns
Scala Functional Patterns
 
Why Haskell Matters
Why Haskell MattersWhy Haskell Matters
Why Haskell Matters
 
Algebraic Data Types and Origami Patterns
Algebraic Data Types and Origami PatternsAlgebraic Data Types and Origami Patterns
Algebraic Data Types and Origami Patterns
 
Scala. Introduction to FP. Monads
Scala. Introduction to FP. MonadsScala. Introduction to FP. Monads
Scala. Introduction to FP. Monads
 
Fp in scala with adts part 2
Fp in scala with adts part 2Fp in scala with adts part 2
Fp in scala with adts part 2
 
Frp2016 3
Frp2016 3Frp2016 3
Frp2016 3
 
High Wizardry in the Land of Scala
High Wizardry in the Land of ScalaHigh Wizardry in the Land of Scala
High Wizardry in the Land of Scala
 
An Introduction to Functional Programming using Haskell
An Introduction to Functional Programming using HaskellAn Introduction to Functional Programming using Haskell
An Introduction to Functional Programming using Haskell
 
Power of functions in a typed world
Power of functions in a typed worldPower of functions in a typed world
Power of functions in a typed world
 
Introduction to haskell
Introduction to haskellIntroduction to haskell
Introduction to haskell
 
Practical cats
Practical catsPractical cats
Practical cats
 
Fp in scala part 2
Fp in scala part 2Fp in scala part 2
Fp in scala part 2
 

Recently uploaded

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Recently uploaded (20)

Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 

Thesis PPT