Write bind
using fmap
and join
link:ch18_18.2_1.hs[role=include]
-
interesting
link:ch18_18.7_1.hs[role=include]
-
I took the
Either
example and just search/replace,a
andb
flipped, thereforeLeft
andRight
flipped too. Had to hideLeft
andRight
not to collide with those fromPrelude
.link:ch18_18.7_2.hs[role=include]
-
this went ok
link:ch18_18.7_3.hs[role=include]
-
pretty cool, I had to fix the
Arbitrary
instance forList
. I had it broken before.link:ch18_18.7_4.hs[role=include]
-
let j :: Monad m ⇒ m (m a) → m a; j = join
-
let l1 :: Monad m ⇒ (a → b) → m a → m b; l1 = liftM
-
let l2 :: Monad m ⇒ (a → b → c) → m a → m b → m c; l2 = liftM2
-
let a :: Monad m ⇒ m a → m (a → b) → m b; a = flip ap
-
Kinda clunky and there is already
forM
that does that. Anyway, I cracked it. Good feeling.link:ch18_18.7_5.hs[role=include]
-
Still not totally clear about
join
, need to play with it more. And againsequence
does just the same.link:ch18_18.7_6.hs[role=include]