-
Notifications
You must be signed in to change notification settings - Fork 464
/
Copy pathUncurriedAlways.res
117 lines (80 loc) · 1.95 KB
/
UncurriedAlways.res
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
@@uncurried
let foo = (x, y) => x + y
let z = foo(3, 4)
let bar = (x, y) => x + y
let b = bar(3, 4)
let w = 3->foo(4)
let a = 3->foo(4)
Js.log(a) // Test automatic uncurried application
let _ = Js.Array2.map([1], x => x + 1)
let ptl = foo(10, ...) // force partial application
let foo2 = (x, y) => x + y
let bar2: _ => _ = foo2(_, 3)
let foo3 = (x, y, z) => x + y + z
let bar3: _ => _ = foo3(_, 3, 4)
type cmp = Jsx.component<int>
let q: cmp = _ => Jsx.null // Check that subtyping works past type definitions
@inline
let inl = () => ()
@inline
let inl2 = (x, y) => x + y
module AllLabels = {
let foo = (~x, ~y, ~z) => (x, y, z)
let ptl = foo(~y="y", ...)
let a1 = ptl(~x="x", ~z="z")
Js.log2("a1:", a1)
}
module OptAtEnd = {
let foo = (~x, ~y, ~z, ~d="d=0") => (x, y, z, d)
let ptl = foo(~y="y", ...)
let b1 = ptl(~x="x", ~z="z")
Js.log2("b1:", b1)
let b2 = ptl(~x="x", ~z="z", ~d="d<-100")
Js.log2("b2:", b2)
}
module OptMixed = {
let foo = (~d1="d1=0", ~x, ~d2="d2=0", ~y, ~d3="d3=0", ~z, ~d4="d4=0", ~w, ~d5="d5=0") => (
d1,
x,
d2,
y,
d3,
z,
d4,
w,
d5,
)
let ptl = foo(~y="y", ~w="w", ...)
let c1 = ptl(~x="x", ~z="z")
Js.log2("c1:", c1)
let c2 = ptl(~x="x", ~z="z", ~d1="d1<-100")
Js.log2("c2:", c2)
let c3 = ptl(~x="x", ~z="z", ~d2="d2<-200", ~d4="d4<-400")
Js.log2("c3:", c3)
}
let fn = cb => {
cb()
}
fn(s => Js.log(#foo(s)))
let fn1 = (a, b, ()) => a() + b
let a = fn1(() => 1, 2, _)
module PartialApplication = {
let f3 = (~x, ~y, ~z) => {
Js.log(x)
x + y + z
}
let fx = f3(~x=1, ...)
let fy = f3(~y=1, ...)
let fz = f3(~z=1, ...)
let fxyz = f3(~x=1, ~y=1, ~z=1, ...)
}
module ReverseApplication = {
let hello1 = (y, f) => f(y)
let hello2 = (y, f) => f(y)
}
module Pipe = {
let f = (a, b, c) => a->(b, c)
let f2 = (a, b, c, d, e) => a(b)->(c(d), d(1, 2), e)->(((u, v, h)) => u + v + h)
let f3 = (foo, x) => foo(x)
let f4 = (x, f) => x->f(3)
}