loading

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.4399198241904927","path":"main.hs","file":{"path":"main.hs","content":{"asEncoding":{"base64":"aW1wb3J0IENvbnRyb2wuQXBwbGljYXRpdmUgKGxpZnRBMikKCmFkZCA6OiBOdW0gYSA9PiBhIC0+IGEgLT4gYQphZGQgYSBiID0gYSArIGIKCm1haW4gPSBkbwogIHByaW50ICQgbGlmdEEyIGFkZCBbIF0gICBbIF0KICBwcmludCAkIGxpZnRBMiBhZGQgWzFdICAgWyBdCiAgcHJpbnQgJCBsaWZ0QTIgYWRkIFsxXSAgIFsyXQogIHByaW50ICQgbGlmdEEyIGFkZCBbMSwyXSBbMl0KICBwcmludCAkIGxpZnRBMiBhZGQgWzEsMl0gWzIsM10KCiAgcHJpbnQgJCBsaWZ0QTIgYWRkIChOb3RoaW5nKSAoTm90aGluZykKICBwcmludCAkIGxpZnRBMiBhZGQgKE5vdGhpbmcpIChKdXN0IDIpCiAgcHJpbnQgJCBsaWZ0QTIgYWRkIChKdXN0IDEpICAoTm90aGluZykKICBwcmludCAkIGxpZnRBMiBhZGQgKEp1c3QgMSkgIChKdXN0IDIpCgogIHByaW50ICQgKGxpZnRBMiBhZGQgKExlZnQgIDEpIChMZWZ0ICAyKSA6OiBFaXRoZXIgSW50IEludCkKICBwcmludCAkIChsaWZ0QTIgYWRkIChMZWZ0ICAxKSAoUmlnaHQgMikgOjogRWl0aGVyIEludCBJbnQpCiAgcHJpbnQgJCAobGlmdEEyIGFkZCAoUmlnaHQgMSkgKExlZnQgIDIpIDo6IEVpdGhlciBJbnQgSW50KQogIHByaW50ICQgKGxpZnRBMiBhZGQgKFJpZ2h0IDEpIChSaWdodCAyKSA6OiBFaXRoZXIgSW50IEludCk="},"asBuffer":null},"loaded":true}}
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