From ac7c66e703f70f57c59697fd90504539c475244d Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Tue, 29 Jul 2008 13:32:07 -0400 Subject: Datatypes through monoize --- src/mono_util.sml | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'src/mono_util.sml') diff --git a/src/mono_util.sml b/src/mono_util.sml index 2395cc90..1232e7dd 100644 --- a/src/mono_util.sml +++ b/src/mono_util.sml @@ -258,7 +258,16 @@ fun mapfoldB {typ = fc, exp = fe, decl = fd, bind} = and mfd' ctx (dAll as (d, loc)) = case d of - DVal vi => + DDatatype (x, n, xncs) => + S.map2 (ListUtil.mapfold (fn (x, n, c) => + case c of + NONE => S.return2 (x, n, c) + | SOME c => + S.map2 (mft c, + fn c' => (x, n, SOME c'))) xncs, + fn xncs' => + (DDatatype (x, n, xncs'), loc)) + | DVal vi => S.map2 (mfvi ctx vi, fn vi' => (DVal vi', loc)) @@ -313,7 +322,22 @@ fun mapfoldB (all as {bind, ...}) = let val ctx' = case #1 d' of - DVal (x, n, t, e, s) => bind (ctx, NamedE (x, n, t, SOME e, s)) + DDatatype (x, n, xncs) => + let + val ctx = bind (ctx, NamedT (x, n, NONE)) + val t = (TNamed n, #2 d') + in + foldl (fn ((x, n, to), ctx) => + let + val t = case to of + NONE => t + | SOME t' => (TFun (t', t), #2 d') + in + bind (ctx, NamedE (x, n, t, NONE, "")) + end) + ctx xncs + end + | DVal (x, n, t, e, s) => bind (ctx, NamedE (x, n, t, SOME e, s)) | DValRec vis => foldl (fn ((x, n, t, e, s), ctx) => bind (ctx, NamedE (x, n, t, SOME e, s))) ctx vis | DExport _ => ctx -- cgit v1.2.3