comparison src/unnest.sml @ 455:d4a81273d4b1

Nested demo
author Adam Chlipala <adamc@hcoop.net>
date Tue, 04 Nov 2008 09:33:35 -0500
parents 787d4931fb07
children f542bc3133dc
comparison
equal deleted inserted replaced
454:9163f8014f9b 455:d4a81273d4b1
135 | _ => ctx} 135 | _ => ctx}
136 (0, nr) 136 (0, nr)
137 137
138 type state = { 138 type state = {
139 maxName : int, 139 maxName : int,
140 decls : decl list 140 decls : (string * int * con * exp) list
141 } 141 }
142 142
143 fun kind (k, st) = (k, st) 143 fun kind (k, st) = (k, st)
144 144
145 fun exp ((ks, ts), e as old, st : state) = 145 fun exp ((ks, ts), e as old, st : state) =
276 in 276 in
277 (x, n, t, e) 277 (x, n, t, e)
278 end) 278 end)
279 vis 279 vis
280 280
281 val d = (DValRec vis, #2 ed)
282
283 val ts = map (fn (x, _, t, _) => (x, t)) vis @ ts 281 val ts = map (fn (x, _, t, _) => (x, t)) vis @ ts
284 in 282 in
285 ([], (ts, maxName, d :: ds, subs)) 283 ([], (ts, maxName, vis @ ds, subs))
286 end) 284 end)
287 (ts, #maxName st, #decls st, []) eds 285 (ts, #maxName st, #decls st, []) eds
288 in 286 in
289 (ELet (eds, doSubst e subs), 287 (ELet (eds, doSubst e subs),
290 {maxName = maxName, 288 {maxName = maxName,
317 let 315 let
318 fun default () = ([all], st) 316 fun default () = ([all], st)
319 fun explore () = 317 fun explore () =
320 let 318 let
321 val (d, st) = unnestDecl st all 319 val (d, st) = unnestDecl st all
320
321 val ds =
322 case #1 d of
323 DValRec vis => [(DValRec (vis @ #decls st), #2 d)]
324 | _ => [(DValRec (#decls st), #2 d), d]
322 in 325 in
323 (rev (d :: #decls st), 326 (ds,
324 {maxName = #maxName st, 327 {maxName = #maxName st,
325 decls = []}) 328 decls = []})
326 end 329 end
327 in 330 in
328 case d of 331 case d of