blob: 9a3bf40dcfcfb86dbeb321c642c8fda66af52a43 (
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
|
(.module:
{#.doc "Functionality for working with tuples (particularly 2-tuples/pairs)."}
[library
[lux #*
[abstract
[equivalence (#+ Equivalence)]
[hash (#+ Hash)]]]])
(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)]))
(implementation: .public (equivalence left right)
(All [l r] (-> (Equivalence l) (Equivalence r) (Equivalence [l r])))
(def: (= [rl rr] [sl sr])
(and (\ left = rl sl)
(\ right = rr sr))))
(def: .public (hash left right)
(All [l r] (-> (Hash l) (Hash r) (Hash [l r])))
(implementation
(def: &equivalence
(..equivalence (\ left &equivalence)
(\ right &equivalence)))
(def: (hash [leftV rightV])
("lux i64 +"
(\ left hash leftV)
(\ right hash rightV)))))
|