blob: 6c1143dc21d374be6470d0abb2ed3fa24586a229 (
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
|
(.require
[library
[lux (.except left right)
[abstract
[equivalence (.only Equivalence)]
[hash (.only Hash)]]]])
(with_template [<name>]
[(def .public (<name> [left right])
(All (_ left right)
(-> [left right] <name>))
<name>)]
[left]
[right]
)
... https://en.wikipedia.org/wiki/Currying
(def .public (curried f)
(All (_ a b c)
(-> (-> [a b] c)
(-> a b c)))
(function (_ x y)
(f [x y])))
(def .public (uncurried f)
(All (_ a b c)
(-> (-> a b c)
(-> [a b] c)))
(function (_ xy)
(let [[x y] xy]
(f x y))))
(def .public (swapped [left right])
(All (_ left right) (-> [left right] [right left]))
[right left])
(def .public (then f g)
(All (_ a b c d)
(-> (-> a c) (-> b d)
(-> [a b] [c d])))
(function (_ [x y])
[(f x) (g y)]))
(def .public (forked f g)
(All (_ a l r)
(-> (-> a l) (-> a r)
(-> a [l r])))
(function (_ x)
[(f x) (g x)]))
(def .public (equivalence left right)
(All (_ l r) (-> (Equivalence l) (Equivalence r) (Equivalence [l r])))
(implementation
(def (= [rl rr] [sl sr])
(and (at left = rl sl)
(at right = rr sr)))))
(def .public (hash left right)
(All (_ l r) (-> (Hash l) (Hash r) (Hash [l r])))
(implementation
(def equivalence
(..equivalence (at left equivalence)
(at right equivalence)))
(def (hash [leftV rightV])
("lux i64 +"
(at left hash leftV)
(at right hash rightV)))))
|