blob: 87dccc9f5954ff995ef585fe0885ade998d6ee50 (
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
|
(.module:
[lux (#- primitive)
[control
[monad (#+ do)]
pipe]
[data
["." error]
[text
format]]
[compiler
[default
["." phase
["." analysis (#+ Analysis)]
["//" synthesis (#+ Synthesis)
["." expression]]
[extension
["." bundle]]]]]
[math
["r" random]]
test])
(def: #export primitive
(r.Random Analysis)
(do r.monad
[primitive (: (r.Random analysis.Primitive)
($_ r.or
(wrap [])
r.bit
r.nat
r.int
r.rev
r.frac
(r.unicode 5)))]
(wrap (#analysis.Primitive primitive))))
(def: #export (corresponds? analysis synthesis)
(-> Analysis Synthesis Bit)
(case [synthesis analysis]
[(#//.Primitive (#//.Text valueS))
(#analysis.Primitive (#analysis.Unit valueA))]
(is? valueS (:coerce Text valueA))
[(#//.Primitive (#//.Bit valueS))
(#analysis.Primitive (#analysis.Bit valueA))]
(is? valueS valueA)
[(#//.Primitive (#//.I64 valueS))
(#analysis.Primitive (#analysis.Nat valueA))]
(is? (.i64 valueS) (.i64 valueA))
[(#//.Primitive (#//.I64 valueS))
(#analysis.Primitive (#analysis.Int valueA))]
(is? (.i64 valueS) (.i64 valueA))
[(#//.Primitive (#//.I64 valueS))
(#analysis.Primitive (#analysis.Rev valueA))]
(is? (.i64 valueS) (.i64 valueA))
[(#//.Primitive (#//.F64 valueS))
(#analysis.Primitive (#analysis.Frac valueA))]
(is? valueS valueA)
[(#//.Primitive (#//.Text valueS))
(#analysis.Primitive (#analysis.Text valueA))]
(is? valueS valueA)
_
#0))
(context: "Primitives."
(<| (times 100)
(do @
[|bit| r.bit
|nat| r.nat
|int| r.int
|rev| r.rev
|frac| r.frac
|text| (r.unicode 5)]
(`` ($_ seq
(~~ (do-template [<desc> <analysis> <synthesis> <sample>]
[(test (format "Can synthesize " <desc> ".")
(|> (#analysis.Primitive (<analysis> <sample>))
expression.phase
(phase.run [bundle.empty //.init])
(case> (#error.Success (#//.Primitive (<synthesis> value)))
(is? <sample> value)
_
#0)))]
["unit" #analysis.Unit #//.Text //.unit]
["bit" #analysis.Bit #//.Bit |bit|]
["nat" #analysis.Nat #//.I64 (.i64 |nat|)]
["int" #analysis.Int #//.I64 (.i64 |int|)]
["rev" #analysis.Rev #//.I64 (.i64 |rev|)]
["frac" #analysis.Frac #//.F64 |frac|]
["text" #analysis.Text #//.Text |text|])))))))
|