loading
open in
main.hs
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
addOne :: (Monad m, Num a) => a -> m a
addOne a = return (a + 1)

main = do
  print $ [ ]    >>= addOne
  print $ [1]    >>= addOne
  print $ [1, 2] >>= addOne

  print $ [ ]    >>= addOne >>= addOne
  print $ [1]    >>= addOne >>= addOne
  print $ [1, 2] >>= addOne >>= addOne

  -- Maybe
  print $ Nothing >>= addOne
  print $ Just 1  >>= addOne

  print $ Nothing >>= addOne >>= addOne
  print $ Just 1  >>= addOne >>= addOne

  -- Either
  print $ (Left  1 >>= addOne :: Either Int Int)
  print $ (Right 1 >>= addOne :: Either Int Int)

  print $ (Right 1 >>= addOne >>= addOne :: Either Int Int)
  print $ (Left  1 >>= addOne >>= addOne :: Either Int Int)
GHCi, version 8.6.3