Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Monad

A513bc1fa519d2fcf5e4e0d9b5500101?s=47 Sibi
March 01, 2014

 Monad

Just another abstraction

A513bc1fa519d2fcf5e4e0d9b5500101?s=128

Sibi

March 01, 2014
Tweet

Transcript

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

    Sibi Just Another Abstraction
  2. Introduction Monad Sheep Cloning Experiment Conclusion About Me Sibi Haskell

    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 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
  7. 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
  8. 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
  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
  13. Introduction Monad Sheep Cloning Experiment Conclusion Courtesy All about Monads

    by Jeff Newbern Real World Haskell Sibi Just Another Abstraction
  14. Introduction Monad Sheep Cloning Experiment Conclusion Questions? ??? Sibi Just

    Another Abstraction