diff src/elab_util.sml @ 211:e86411f647c6

Initial type class support
author Adam Chlipala <adamc@hcoop.net>
date Sat, 16 Aug 2008 14:32:18 -0400
parents cc68da3801bc
children 0343557355fc
line wrap: on
line diff
--- a/src/elab_util.sml	Sat Aug 16 12:35:46 2008 -0400
+++ b/src/elab_util.sml	Sat Aug 16 14:32:18 2008 -0400
@@ -376,6 +376,14 @@
         S.Return _ => true
       | S.Continue _ => false
 
+fun mapB {kind, con, exp, bind} ctx e =
+    case mapfoldB {kind = fn k => fn () => S.Continue (kind k, ()),
+                   con = fn ctx => fn c => fn () => S.Continue (con ctx c, ()),
+                   exp = fn ctx => fn e => fn () => S.Continue (exp ctx e, ()),
+                   bind = bind} ctx e () of
+        S.Continue (e, ()) => e
+      | S.Return _ => raise Fail "ElabUtil.Exp.mapB: Impossible"
+
 end
 
 structure Sgn = struct
@@ -455,6 +463,11 @@
                 S.map2 (con ctx c,
                         fn c' =>
                            (SgiTable (tn, x, n, c'), loc))
+              | SgiClassAbs _ => S.return2 siAll
+              | SgiClass (x, n, c) =>
+                S.map2 (con ctx c,
+                        fn c' =>
+                           (SgiClass (x, n, c'), loc))
 
         and sg ctx s acc =
             S.bindP (sg' ctx s acc, sgn ctx)
@@ -478,7 +491,11 @@
                                                  | SgiSgn (x, _, sgn) =>
                                                    bind (ctx, Sgn (x, sgn))
                                                  | SgiConstraint _ => ctx
-                                                 | SgiTable _ => ctx,
+                                                 | SgiTable _ => ctx
+                                                 | SgiClassAbs (x, _) =>
+                                                   bind (ctx, NamedC (x, (KArrow ((KType, loc), (KType, loc)), loc)))
+                                                 | SgiClass (x, _, _) =>
+                                                   bind (ctx, NamedC (x, (KArrow ((KType, loc), (KType, loc)), loc))),
                                                sgi ctx si)) ctx sgis,
                      fn sgis' =>
                         (SgnConst sgis', loc))