Thesis
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

PDF
Gopher conbr golang e data science - oficial
PDF
1D Array
PDF
Bcsl 033 data and file structures lab s3-3
PPT
Data Structure and Algorithms Stacks
PPT
Data Structure and Algorithms Queues
PPTX
Template C++ OOP
PDF
15 - Scala. Dependent function type (Π-type)
PDF
XKE Typeclass
Gopher conbr golang e data science - oficial
1D Array
Bcsl 033 data and file structures lab s3-3
Data Structure and Algorithms Stacks
Data Structure and Algorithms Queues
Template C++ OOP
15 - Scala. Dependent function type (Π-type)
XKE Typeclass

What's hot (18)

PPTX
Functional Programming in Swift
PPT
Templates
PDF
Modular Module Systems
PDF
Bcsl 033 data and file structures lab s4-2
PDF
Type-level programming
PDF
Traversals for all ocasions
PPT
Tools for research plotting
PPTX
An introduction to matlab
PDF
Map, Reduce and Filter in Swift
PDF
Linked list searching deleting inserting
DOCX
Lecture 21.07.2014
PDF
Testing in the World of Functional Programming
PDF
Essence of the iterator pattern
PDF
SATySFiのこれからの課題たち
PDF
Principled Error Handling with FP
PPTX
Legacy lambda code
Functional Programming in Swift
Templates
Modular Module Systems
Bcsl 033 data and file structures lab s4-2
Type-level programming
Traversals for all ocasions
Tools for research plotting
An introduction to matlab
Map, Reduce and Filter in Swift
Linked list searching deleting inserting
Lecture 21.07.2014
Testing in the World of Functional Programming
Essence of the iterator pattern
SATySFiのこれからの課題たち
Principled Error Handling with FP
Legacy lambda code
Ad

Similar to Thesis (20)

PPTX
The Essence of the Iterator Pattern
PDF
The Essence of the Iterator Pattern (pdf)
PDF
Oh, All the things you'll traverse
PPTX
Monads and friends demystified
PPTX
Types by Adform Research
PPT
Functional programming in scala
PDF
Fp in scala with adts
PPTX
(2015 06-16) Three Approaches to Monads
PDF
Scala Functional Patterns
PDF
Why Haskell Matters
PDF
Algebraic Data Types and Origami Patterns
PDF
Scala. Introduction to FP. Monads
PDF
Fp in scala with adts part 2
PDF
Frp2016 3
PDF
High Wizardry in the Land of Scala
KEY
An Introduction to Functional Programming using Haskell
PDF
Power of functions in a typed world
PDF
Introduction to haskell
PDF
Practical cats
PDF
Fp in scala part 2
The Essence of the Iterator Pattern
The Essence of the Iterator Pattern (pdf)
Oh, All the things you'll traverse
Monads and friends demystified
Types by Adform Research
Functional programming in scala
Fp in scala with adts
(2015 06-16) Three Approaches to Monads
Scala Functional Patterns
Why Haskell Matters
Algebraic Data Types and Origami Patterns
Scala. Introduction to FP. Monads
Fp in scala with adts part 2
Frp2016 3
High Wizardry in the Land of Scala
An Introduction to Functional Programming using Haskell
Power of functions in a typed world
Introduction to haskell
Practical cats
Fp in scala part 2
Ad

Thesis