summaryrefslogtreecommitdiff
path: root/examples/passing/Operators.purs
blob: a222fe1fc602faff773656c290eb64bb885553f9 (plain)
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
module Main where

  import Control.Monad.Eff
  import Debug.Trace

  (?!) :: forall a. a -> a -> a
  (?!) x _ = x

  bar :: String -> String -> String
  bar = \s1 s2 -> s1 ++ s2

  test1 :: forall n. (Num n) => n -> n -> (n -> n -> n) -> n
  test1 x y z = x * y + z x y

  test2 = (\x -> x.foo false) { foo : \_ -> 1 }

  test3 = (\x y -> x)(1 + 2 * (1 + 2)) (true && (false || false))

  k = \x -> \y -> x

  test4 = 1 `k` 2

  infixl 5 %%

  (%%) :: Number -> Number -> Number
  (%%) x y = x * y + y

  test5 = 1 %% 2 %% 3

  test6 = ((\x -> x) `k` 2) 3

  (<+>) :: String -> String -> String
  (<+>) = \s1 s2 -> s1 ++ s2

  test7 = "Hello" <+> "World!"

  (@@) :: forall a b. (a -> b) -> a -> b
  (@@) = \f x -> f x

  foo :: String -> String
  foo = \s -> s

  test8 = foo @@ "Hello World"

  test9 = Main.foo @@ "Hello World"

  test10 = "Hello" `Main.bar` "World"

  (...) :: forall a. [a] -> [a] -> [a]
  (...) = \as -> \bs -> as

  test11 = [1, 2, 3] ... [4, 5, 6]

  test12 (<%>) a b = a <%> b

  test13 = \(<%>) a b -> a <%> b

  test14 :: Number -> Number -> Boolean
  test14 a b = a < b

  test15 :: Number -> Number -> Boolean
  test15 a b = const false $ a `test14` b

  test17 :: Number
  test17 = negate (-1)

  test18 :: Number
  test18 = negate $ negate 1

  test19 :: Number
  test19 = negate $ negate (-1)

  test20 :: Number
  test20 = 1 @ 2
    where
    (@) x y = x + y * y

  main = do
    let t1 = test1 1 2 (\x y -> x + y)
    let t2 = test2
    let t3 = test3
    let t4 = test4
    let t5 = test5
    let t6 = test6
    let t7 = test7
    let t8 = test8
    let t9 = test9
    let t10 = test10
    let t11 = test11
    let t12 = test12 k 1 2
    let t13 = test13 k 1 2
    let t14 = test14 1 2
    let t15 = test15 1 2
    let t17 = test17
    let t18 = test18
    let t19 = test19
    let t20 = test20
    trace "Done"