loading
main.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import Control.Applicative (liftA2)

add :: Num a => a -> a -> a
add a b = a + b

main = do
  print $ liftA2 add [ ]   [ ]
  print $ liftA2 add [1]   [ ]
  print $ liftA2 add [1]   [2]
  print $ liftA2 add [1,2] [2]
  print $ liftA2 add [1,2] [2,3]

  print $ liftA2 add (Nothing) (Nothing)
  print $ liftA2 add (Nothing) (Just 2)
  print $ liftA2 add (Just 1)  (Nothing)
  print $ liftA2 add (Just 1)  (Just 2)

  print $ (liftA2 add (Left  1) (Left  2) :: Either Int Int)
  print $ (liftA2 add (Left  1) (Right 2) :: Either Int Int)
  print $ (liftA2 add (Right 1) (Left  2) :: Either Int Int)
  print $ (liftA2 add (Right 1) (Right 2) :: Either Int Int)
GHCi, version 8.6.5