Exercise 3.2

You Could Have Invented Monads! (And Maybe You Already Have.)

Show that lift f * lift g = lift (f.g)

——————————

The meaning of f' * g' should be (bind f') . (bind g') instead.

f' * g' = (bind f') . (bind g')
lift f = unit . f
f' = lift f

(lift f * lift g) (x, xs)
= (bind (lift f)) . (bind (lift g)) (x, xs)
= bind (lift f) (bind (lift g) (x, xs))
= bind (lift f) (gx, xs++gs)
  where
    (gx, gs) = (lift g) x

= bind (lift f) (gx, xs++gs)
  where
    (gx, gs) = (g x, "")

= bind (lift f) (g x, xs)

= (fx, xs++fs)
  where
    (fx, fs) = (lift f) gx
 
= (fx, xs++fs)
  where
    (fx, fs) = (f gx, "")

= (fx, xs)
  where
    (fx, fs) = (f (g x), "")

= (f (g x), xs)

bind f' (gx,gs) = (fx, gs++fs)
                  where
                    (fx,fs) = f' gx

bind (lift (f.g)) (x, xs)
= (hx, xs++hs)
  where
    (hx, hs) = (lift (f.g)) x

= (hx, xs++hs)
  where
    (hx, hs) = ((f.g) x, "")

= ((f (g x)), xs)

— Me@2015.07.19 11:04 PM

2015.10.02 Friday (c) All rights reserved by ACHK