1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
x :: Int
f :: Int -> Maybe Int
g :: Int -> Maybe Int

-- Task: evaluate g (f x) and abstract out Maybe.

case (f x) of
  Nothing -> Nothing
  Just y -> case (g y) of
              Nothing -> Nothing
              Just z -> z

-- equiv to

f x >>= \y ->
g y >>= \z ->
return z

-- equiv to

do y <- f x
   z <- g y
   return z

-- equiv to

y x >>= g