blob: 57db7a925f48df4421eb436bb739ba9e5d9905b7 (
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
|
(.module:
[lux #*
[control
[functor (#+ Contravariant)]]])
(signature: #export (Equivalence a)
{#.doc "Equivalence for a type's instances."}
(: (-> a a Bit)
=))
(def: #export (product left right)
(All [l r] (-> (Equivalence l) (Equivalence r) (Equivalence [l r])))
(structure
(def: (= [a b] [x y])
(and (:: left = a x)
(:: right = b y)))))
(def: #export (sum left right)
(All [l r] (-> (Equivalence l) (Equivalence r) (Equivalence (| l r))))
(structure
(def: (= a|b x|y)
(case [a|b x|y]
[(0 a) (0 x)]
(:: left = a x)
[(1 b) (1 y)]
(:: right = b y)
_
#0))))
(def: #export (rec sub)
(All [a] (-> (-> (Equivalence a) (Equivalence a)) (Equivalence a)))
(structure
(def: (= left right)
(sub (rec sub) left right))))
(structure: #export contravariant (Contravariant Equivalence)
(def: (map-1 f equivalence)
(structure
(def: (= reference sample)
(:: equivalence = (f reference) (f sample))))))
|