Sibi
March 01, 2014
130

Just another abstraction

March 01, 2014

## Transcript

1. ### Introduction Monad Sheep Cloning Experiment Conclusion Monad March 1, 2014

Sibi Just Another Abstraction

Programmer Internet Handle: psibi (github, Twitter) Mail: sibi@psibi.in Sibi Just Another Abstraction
3. ### Introduction Monad Sheep Cloning Experiment Conclusion Outline 1 Introduction 2

Monad 3 Sheep Cloning Experiment 4 Conclusion Sibi Just Another Abstraction
4. ### Introduction Monad Sheep Cloning Experiment Conclusion Some basics Types TypeClasses

Functions Sibi Just Another Abstraction
5. ### Introduction Monad Sheep Cloning Experiment Conclusion Maybe Type For values

which may or may not have a value. data Maybe a = Just a | Nothing Examples: Just "hi" Just 3 Nothing Sibi Just Another Abstraction
6. ### Introduction Monad Sheep Cloning Experiment Conclusion Deﬁnition Category theory deﬁnition

is scary! But you don’t need to know that. :-) Best learnt with time and observing patterns. Sibi Just Another Abstraction

m where (>>=) : : m a −> ( a −> m b ) −> m b return : : a −> m a Sibi Just Another Abstraction

Maybe where return x = Just x Nothing >>= f = Nothing Just x >>= f = f x Sibi Just Another Abstraction
9. ### Introduction Monad Sheep Cloning Experiment Conclusion Types and Functions type

Sheep = . . . father : : Sheep −> Maybe Sheep father = . . . mother : : Sheep −> Maybe Sheep mother = . . . Sibi Just Another Abstraction
10. ### Introduction Monad Sheep Cloning Experiment Conclusion Other Functions maternalGrandfather :

: Sheep −> Maybe Sheep maternalGrandfather s = case ( mother s ) of Nothing −> Nothing Just m −> father m mpg : : Sheep −> Maybe Sheep mpg s = case ( mother s ) of Nothing −> Nothing Just m −> case ( father m) of Nothing −> Nothing Just gf −> father gf Sibi Just Another Abstraction
11. ### Introduction Monad Sheep Cloning Experiment Conclusion Monads into action! mpg

: : Sheep −> Maybe Sheep mpg s = ( Just s ) >>= mother >>= father >>= father Sibi Just Another Abstraction
12. ### Introduction Monad Sheep Cloning Experiment Conclusion Conclusion Monads are easy!

Monads are fun! It’s just another abstraction. There are lot of other abstractions. :-) Sibi Just Another Abstraction