Mercurial > urweb
diff src/specialize.sml @ 194:df5fd8f6913a
A multi-parameter datatype all the way through
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Sat, 09 Aug 2008 08:47:36 -0400 |
parents | 8a70e2919e86 |
children | e21d0dddda09 |
line wrap: on
line diff
--- a/src/specialize.sml Fri Aug 08 17:55:51 2008 -0400 +++ b/src/specialize.sml Sat Aug 09 08:47:36 2008 -0400 @@ -77,10 +77,13 @@ SOME dt' => (#name dt', #constructors dt', st) | NONE => let + (*val () = Print.prefaces "Args" [("args", Print.p_list (CorePrint.p_con CoreEnv.empty) args)]*) + val n' = #count st + val nxs = length args - 1 fun sub t = ListUtil.foldli (fn (i, arg, t) => - subConInCon (i, arg) t) t args + subConInCon (nxs - i, arg) t) t args val (cons, (count, cmap)) = ListUtil.foldlMap (fn ((x, n, to), (count, cmap)) => @@ -240,28 +243,32 @@ fun specialize file = let fun doDecl (all as (d, _), st : state) = - case d of - DDatatype (x, n, xs, xnts) => - ([all], {count = #count st, - datatypes = IM.insert (#datatypes st, n, - {name = x, - params = length xs, - constructors = xnts, - specializations = CM.empty}), - constructors = foldl (fn ((_, n', _), constructors) => - IM.insert (constructors, n', n)) - (#constructors st) xnts, - decls = []}) - | _ => - let - val (d, st) = specDecl st all - in - (rev (d :: #decls st), - {count = #count st, - datatypes = #datatypes st, - constructors = #constructors st, - decls = []}) - end + let + (*val () = Print.preface ("decl:", CorePrint.p_decl CoreEnv.empty all)*) + in + case d of + DDatatype (x, n, xs, xnts) => + ([all], {count = #count st, + datatypes = IM.insert (#datatypes st, n, + {name = x, + params = length xs, + constructors = xnts, + specializations = CM.empty}), + constructors = foldl (fn ((_, n', _), constructors) => + IM.insert (constructors, n', n)) + (#constructors st) xnts, + decls = []}) + | _ => + let + val (d, st) = specDecl st all + in + (rev (d :: #decls st), + {count = #count st, + datatypes = #datatypes st, + constructors = #constructors st, + decls = []}) + end + end val (ds, _) = ListUtil.foldlMapConcat doDecl {count = U.File.maxName file + 1,