Skip to content

Latest commit

 

History

History
69 lines (64 loc) · 1.38 KB

ch18.adoc

File metadata and controls

69 lines (64 loc) · 1.38 KB

18 Monad

18.2 Sorry — Monad is not a burrito

Write bind using fmap and join

link:ch18_18.2_1.hs[role=include]

18.4 Examples of Monad use

List

link:ch18_18.4_1.hs[role=include]

Either

link:ch18_18.4_2.hs[role=include]

18.5 Monad laws

link:ch18_18.5_1.hs[role=include]

18.7 Chapter Exercises

  1. interesting

    link:ch18_18.7_1.hs[role=include]
  2. I took the Either example and just search/replace, a and b flipped, therefore Left and Right flipped too. Had to hide Left and Right not to collide with those from Prelude.

    link:ch18_18.7_2.hs[role=include]
  3. this went ok

    link:ch18_18.7_3.hs[role=include]
  4. pretty cool, I had to fix the Arbitrary instance for List. I had it broken before.

    link:ch18_18.7_4.hs[role=include]
  5. let j :: Monad m ⇒ m (m a) → m a; j = join

  6. let l1 :: Monad m ⇒ (a → b) → m a → m b; l1 = liftM

  7. let l2 :: Monad m ⇒ (a → b → c) → m a → m b → m c; l2 = liftM2

  8. let a :: Monad m ⇒ m a → m (a → b) → m b; a = flip ap

  9. Kinda clunky and there is already forM that does that. Anyway, I cracked it. Good feeling.

    link:ch18_18.7_5.hs[role=include]
  10. Still not totally clear about join, need to play with it more. And again sequence does just the same.

    link:ch18_18.7_6.hs[role=include]