aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/source/luxc/analyser/common.lux
blob: 7a9e5dbf834e72a4962cd7183c5557701d3847f8 (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
(;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] (&;within-type-env
                        TC;create-var)
     analysis (&;with-expected-type var-type
                action)
     analysis-type (&;within-type-env
                    (TC;clean var-id var-type))
     _ (&;within-type-env
        (TC;delete-var var-id))]
    (wrap [analysis-type analysis])))

(def: #export (with-var body)
  (All [a] (-> (-> [Nat Type] (Lux a)) (Lux a)))
  (do Monad<Lux>
    [[id var] (&;within-type-env TC;create-var)
     output (body [id var])
     _ (&;within-type-env (TC;delete-var id))]
    (wrap output)))