blob: b9142713ceb4ad46f7e87d1fbc7a0fb4390965e8 (
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
|
(;module:
lux
(lux (control monad
pipe)
(data text/format
[product])
[macro #+ Monad<Lux>]
[type]
(type ["tc" check]))
(luxc ["&" base]
(lang analysis)))
(def: #export (with-unknown-type action)
(All [a] (-> (Lux Analysis) (Lux [Type Analysis])))
(do Monad<Lux>
[[var-id var-type] (&;with-type-env
tc;create)
analysis (&;with-expected-type var-type
action)
analysis-type (&;with-type-env
(tc;clean var-id var-type))
_ (&;with-type-env
(tc;delete var-id))]
(wrap [analysis-type analysis])))
(def: #export (with-var body)
(All [a] (-> (-> [Nat Type] (Lux a)) (Lux a)))
(do Monad<Lux>
[[id var] (&;with-type-env
tc;create)
output (body [id var])
_ (&;with-type-env
(tc;delete id))]
(wrap output)))
(def: #export (variant-out-of-bounds-error type size tag)
(All [a] (-> Type Nat Nat (Lux a)))
(&;fail (format "Trying to create variant with tag beyond type's limitations." "\n"
" Tag: " (%i (nat-to-int tag)) "\n"
"Size: " (%i (nat-to-int size)) "\n"
"Type: " (%type type))))
|