aboutsummaryrefslogtreecommitdiff
path: root/new-luxc/source/luxc/synthesizer/structure.lux
blob: 403817c535282167d64ae60e3733be1b0c84ec02 (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
(;module:
  lux
  (luxc (lang ["la" analysis])))

(def: #export (unfold-tuple tuple)
  (-> la;Analysis (List la;Analysis))
  (case tuple
    (#la;Product left right)
    (#;Cons left (unfold-tuple right))

    _
    (list tuple)))

(def: #export (unfold-variant variant)
  (-> (Either la;Analysis la;Analysis) [Nat Bool la;Analysis])
  (loop [so-far +0
         variantA variant]
    (case variantA
      (#;Left valueA)
      (case valueA
        (#la;Sum choice)
        (recur (n.inc so-far) choice)

        _
        [so-far false valueA])
      
      (#;Right valueA)
      [(n.inc so-far) true valueA])))