Slide 1

Slide 1 text

Introduction Monad Sheep Cloning Experiment Conclusion Monad March 1, 2014 Sibi Just Another Abstraction

Slide 2

Slide 2 text

Introduction Monad Sheep Cloning Experiment Conclusion About Me Sibi Haskell Programmer Internet Handle: psibi (github, Twitter) Mail: [email protected] Sibi Just Another Abstraction

Slide 3

Slide 3 text

Introduction Monad Sheep Cloning Experiment Conclusion Outline 1 Introduction 2 Monad 3 Sheep Cloning Experiment 4 Conclusion Sibi Just Another Abstraction

Slide 4

Slide 4 text

Introduction Monad Sheep Cloning Experiment Conclusion Some basics Types TypeClasses Functions Sibi Just Another Abstraction

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

Introduction Monad Sheep Cloning Experiment Conclusion Definition Category theory definition is scary! But you don’t need to know that. :-) Best learnt with time and observing patterns. Sibi Just Another Abstraction

Slide 7

Slide 7 text

Introduction Monad Sheep Cloning Experiment Conclusion Monad TypeClass class Monad m where (>>=) : : m a −> ( a −> m b ) −> m b return : : a −> m a Sibi Just Another Abstraction

Slide 8

Slide 8 text

Introduction Monad Sheep Cloning Experiment Conclusion Maybe Monad instance Monad Maybe where return x = Just x Nothing >>= f = Nothing Just x >>= f = f x Sibi Just Another Abstraction

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

Introduction Monad Sheep Cloning Experiment Conclusion Monads into action! mpg : : Sheep −> Maybe Sheep mpg s = ( Just s ) >>= mother >>= father >>= father Sibi Just Another Abstraction

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

Introduction Monad Sheep Cloning Experiment Conclusion Courtesy All about Monads by Jeff Newbern Real World Haskell Sibi Just Another Abstraction

Slide 14

Slide 14 text

Introduction Monad Sheep Cloning Experiment Conclusion Questions? ??? Sibi Just Another Abstraction