0
Upcoming SlideShare
×

# 3 FP Concepts: Recursion, List Comprehensions and Monads

4,021

Published on

3 FP Concepts: Recursion, List Comprehensions and Monads

Published in: Technology
1 Like
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

Views
Total Views
4,021
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
25
0
Likes
1
Embeds 0
No embeds

No notes for slide

### Transcript of "3 FP Concepts: Recursion, List Comprehensions and Monads"

1. 1. 3 FP Concepts Recursion, List comprehensions and Monads@diego_pacheco  about.me/diegopacheco
2. 2. 3 FP Concepts Recursion List Comprehensions Monads
3. 3. Recursion
4. 4. Recursion Function defined inside a function Function calling it-self Defining an infinite set of objects by a finitestatement (Recursion Power by Wikipedia) Same behavior as loop, for, while, etc…
5. 5. Recursion
6. 6. List Comprehensions
7. 7. List Comprehensions Syntactic construct based on lists Inspired by math: set comprehensions Expressions on lists, powerful stuff!
8. 8. List Comprehensions
10. 10. Monads => NO State on a world FULL ofState, Looks nonsense!? WTF?
11. 11. FP/Haskell are against state? Hell No!It’s all about discipline state…
12. 12. How to Deal with state without globalshared state variables ?
13. 13. Workaround => Truck Food as Monad !!! (Abstraction)
14. 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 exactlythe 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. 15. Monads as types/class (>>=), OOP!?
16. 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