SlideShare a Scribd company logo
3 FP Concepts




                Recursion, List comprehensions and Monads



@diego_pacheco  about.me/diegopacheco
3 FP Concepts
  Recursion

  List Comprehensions

  Monads
Recursion
Recursion

 Function defined inside a function
 Function calling it-self
 Defining an infinite set of objects by a finite
statement (Recursion Power by Wikipedia)
 Same behavior as loop, for, while, etc…
Recursion
List Comprehensions
List Comprehensions

 Syntactic construct based on lists
 Inspired by math: set comprehensions
 Expressions on lists, powerful stuff!
List Comprehensions
Monads
Monads => NO State on a world FULL of
State, Looks nonsense!? WTF?
FP/Haskell are against state? Hell No!
It’s all about discipline state…
How to Deal with state without global
shared state variables ?
Workaround => Truck Food as Monad !!!
  (Abstraction)
Monads

 Deal with side-effects in a functional way
 Mathematical construct
 Without monads PURE FP would be nuts
 Functional able todo IO
 Good to Control tracking of things
 Similar to AOP Interceptors
 Function Composition: LINQ, Unix Pipes
 You can build environments that support exactly
the features that you want (Scala Option[A])
 Encapsulating two things:
   control flow (Maybe, Error, List, Continuation, parser monads)
   state propagation (State, Reader, Writer, IO)
Monads as types/class (>>=), OOP!?
Monads have laws…
                        its not just type/classes
                        Make possible assumptions about the
                        type/class and his behavior.


1. Left Identity (apply function to value)
     return x >>= f (the same as) f x
     sample: return 3 >>= (x -> Just (x+100000))
2. Right Identity (value to feed return)
     m >>= return (the same as) m
     sample: [1,2,3,4] >>= (x -> return x)
3. Associativity (no matter how nested chain)
     (m >>= f) >>= g (the same as) m >>= (x -> f x >>= g)
     sample: return (0,0) >>= landRight 2 >>= landLeft 2 >>= landRight 2
Monads

         >>= (bind)
Monads
https://github.com/diegopacheco/functional-society
3 FP Concepts

                   Thank You!
                    Obrigado!
                Higher Order Functions, Lambda and Currying



@diego_pacheco  about.me/diegopacheco

More Related Content

DOCX
Stacks in data structure
PDF
1. python
PDF
Doubly Link List
PPTX
Groovy
PPTX
16 containers
DOCX
Collections framework
PDF
Map reduce & HDFS with Hadoop
PDF
Clojure functions v
Stacks in data structure
1. python
Doubly Link List
Groovy
16 containers
Collections framework
Map reduce & HDFS with Hadoop
Clojure functions v

Viewers also liked (17)

PDF
Tech Evaluation
PDF
3 little clojure functions 4
PPT
Spring Capitulo 02
PDF
PDF
Vacations @ 2012 -1
PDF
PDF
Terraform
PDF
Delivering happiness
PDF
Snowplow Analitics
PDF
Scala FS 2012
PDF
Apache Storm
PDF
Throughtput dos Coachs
PDF
PDF
is TDD Dead? System Nature is the anwser!
PPT
Soa Governance Made Easy
PDF
Irrational cognitive biases
PDF
Lean Architecture
Tech Evaluation
3 little clojure functions 4
Spring Capitulo 02
Vacations @ 2012 -1
Terraform
Delivering happiness
Snowplow Analitics
Scala FS 2012
Apache Storm
Throughtput dos Coachs
is TDD Dead? System Nature is the anwser!
Soa Governance Made Easy
Irrational cognitive biases
Lean Architecture
Ad

Similar to 3 FP Concepts: Recursion, List Comprehensions and Monads (20)

PDF
A taste of Functional Programming
PPTX
Intro to Functional Programming
PDF
Demystifying functional programming with Scala
PPTX
Advanced Functional Programming in Scala
PPTX
Functional programming for the Advanced Beginner
PDF
Functional Scala
PPTX
Functional programming
PDF
Practical cats
PDF
pure-functional-programming.pdf
PPTX
The joy of functional programming
PDF
Rainer Grimm, “Functional Programming in C++11”
PDF
Functional programming is the most extreme programming
PPTX
Monadic Computations in C++14
PDF
The Fuss about || Haskell | Scala | F# ||
PPT
Thesis PPT
PPT
Thesis
PDF
Functional programming with haskell
PDF
Introduction à Scala - Michel Schinz - January 2010
PDF
Arriving at monads by going from pure-function composition to effectful-funct...
PDF
Making the most of lambdas
A taste of Functional Programming
Intro to Functional Programming
Demystifying functional programming with Scala
Advanced Functional Programming in Scala
Functional programming for the Advanced Beginner
Functional Scala
Functional programming
Practical cats
pure-functional-programming.pdf
The joy of functional programming
Rainer Grimm, “Functional Programming in C++11”
Functional programming is the most extreme programming
Monadic Computations in C++14
The Fuss about || Haskell | Scala | F# ||
Thesis PPT
Thesis
Functional programming with haskell
Introduction à Scala - Michel Schinz - January 2010
Arriving at monads by going from pure-function composition to effectful-funct...
Making the most of lambdas
Ad

More from Diego Pacheco (20)

PDF
Naming Things Book : Simple Book Review!
PDF
Continuous Discovery Habits Book Review.pdf
PDF
Thoughts about Shape Up
PDF
Holacracy
PDF
AWS IAM
PDF
PDF
Encryption Deep Dive
PDF
Sec 101
PDF
Reflections on SCM
PDF
Management: Doing the non-obvious! III
PDF
Design is not Subjective
PDF
Architecture & Engineering : Doing the non-obvious!
PDF
Management doing the non-obvious II
PDF
Testing in production
PDF
Nine lies about work
PDF
Management: doing the nonobvious!
PDF
AI and the Future
PDF
Dealing with dependencies
PDF
Dealing with dependencies in tests
PDF
Kanban 2020
Naming Things Book : Simple Book Review!
Continuous Discovery Habits Book Review.pdf
Thoughts about Shape Up
Holacracy
AWS IAM
Encryption Deep Dive
Sec 101
Reflections on SCM
Management: Doing the non-obvious! III
Design is not Subjective
Architecture & Engineering : Doing the non-obvious!
Management doing the non-obvious II
Testing in production
Nine lies about work
Management: doing the nonobvious!
AI and the Future
Dealing with dependencies
Dealing with dependencies in tests
Kanban 2020

Recently uploaded (20)

PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Encapsulation theory and applications.pdf
PDF
August Patch Tuesday
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Machine learning based COVID-19 study performance prediction
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
TLE Review Electricity (Electricity).pptx
PPTX
Spectroscopy.pptx food analysis technology
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
OMC Textile Division Presentation 2021.pptx
PPTX
Machine Learning_overview_presentation.pptx
PPTX
1. Introduction to Computer Programming.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
Per capita expenditure prediction using model stacking based on satellite ima...
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Encapsulation theory and applications.pdf
August Patch Tuesday
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Accuracy of neural networks in brain wave diagnosis of schizophrenia
Assigned Numbers - 2025 - Bluetooth® Document
NewMind AI Weekly Chronicles - August'25-Week II
Mobile App Security Testing_ A Comprehensive Guide.pdf
Machine learning based COVID-19 study performance prediction
Encapsulation_ Review paper, used for researhc scholars
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Advanced methodologies resolving dimensionality complications for autism neur...
TLE Review Electricity (Electricity).pptx
Spectroscopy.pptx food analysis technology
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
OMC Textile Division Presentation 2021.pptx
Machine Learning_overview_presentation.pptx
1. Introduction to Computer Programming.pptx
MIND Revenue Release Quarter 2 2025 Press Release

3 FP Concepts: Recursion, List Comprehensions and Monads

  • 1. 3 FP Concepts Recursion, List comprehensions and Monads @diego_pacheco  about.me/diegopacheco
  • 2. 3 FP Concepts Recursion List Comprehensions Monads
  • 4. Recursion  Function defined inside a function  Function calling it-self  Defining an infinite set of objects by a finite statement (Recursion Power by Wikipedia)  Same behavior as loop, for, while, etc…
  • 7. List Comprehensions  Syntactic construct based on lists  Inspired by math: set comprehensions  Expressions on lists, powerful stuff!
  • 10. Monads => NO State on a world FULL of State, Looks nonsense!? WTF?
  • 11. FP/Haskell are against state? Hell No! It’s all about discipline state…
  • 12. How to Deal with state without global shared state variables ?
  • 13. Workaround => Truck Food as Monad !!! (Abstraction)
  • 14. Monads  Deal with side-effects in a functional way  Mathematical construct  Without monads PURE FP would be nuts  Functional able todo IO  Good to Control tracking of things  Similar to AOP Interceptors  Function Composition: LINQ, Unix Pipes  You can build environments that support exactly the features that you want (Scala Option[A])  Encapsulating two things:  control flow (Maybe, Error, List, Continuation, parser monads)  state propagation (State, Reader, Writer, IO)
  • 15. Monads as types/class (>>=), OOP!?
  • 16. Monads have laws… its not just type/classes Make possible assumptions about the type/class and his behavior. 1. Left Identity (apply function to value) return x >>= f (the same as) f x sample: return 3 >>= (x -> Just (x+100000)) 2. Right Identity (value to feed return) m >>= return (the same as) m sample: [1,2,3,4] >>= (x -> return x) 3. Associativity (no matter how nested chain) (m >>= f) >>= g (the same as) m >>= (x -> f x >>= g) sample: return (0,0) >>= landRight 2 >>= landLeft 2 >>= landRight 2
  • 17. Monads >>= (bind)
  • 20. 3 FP Concepts Thank You! Obrigado! Higher Order Functions, Lambda and Currying @diego_pacheco  about.me/diegopacheco