src/Pure/Tools/codegen_thingol.ML
changeset 20456 42be3a46dcd8
parent 20439 1bf42b262a38
child 20466 7c20ddbd911b
equal deleted inserted replaced
20455:e671d9eac6c8 20456:42be3a46dcd8
    14 infixr 3 `|-->;
    14 infixr 3 `|-->;
    15 
    15 
    16 signature BASIC_CODEGEN_THINGOL =
    16 signature BASIC_CODEGEN_THINGOL =
    17 sig
    17 sig
    18   type vname = string;
    18   type vname = string;
    19   type sortcontext = ClassPackage.sortcontext;
    19   datatype inst =
    20   datatype iclasslookup =
    20       Instance of string * inst list list
    21       Instance of string * iclasslookup list list
    21     | Context of class list * (vname * int);
    22     | Lookup of class list * (vname * int);
       
    23   datatype itype =
    22   datatype itype =
    24       `%% of string * itype list
    23       `%% of string * itype list
    25     | `-> of itype * itype
    24     | `-> of itype * itype
    26     | ITyVar of vname;
    25     | ITyVar of vname;
    27   datatype iterm =
    26   datatype iterm =
    28       IConst of string * (iclasslookup list list * itype)
    27       IConst of string * (inst list list * itype)
    29     | IVar of vname
    28     | IVar of vname
    30     | `$ of iterm * iterm
    29     | `$ of iterm * iterm
    31     | `|-> of (vname * itype) * iterm
    30     | `|-> of (vname * itype) * iterm
    32     | INum of IntInf.int (*non-negative!*) * iterm
    31     | INum of IntInf.int (*non-negative!*) * iterm
    33     | IChar of string (*length one!*) * iterm
    32     | IChar of string (*length one!*) * iterm
    50   val unfold_fun: itype -> itype list * itype;
    49   val unfold_fun: itype -> itype list * itype;
    51   val unfold_app: iterm -> iterm * iterm list;
    50   val unfold_app: iterm -> iterm * iterm list;
    52   val unfold_abs: iterm -> (iterm * itype) list * iterm;
    51   val unfold_abs: iterm -> (iterm * itype) list * iterm;
    53   val unfold_let: iterm -> ((iterm * itype) * iterm) list * iterm;
    52   val unfold_let: iterm -> ((iterm * itype) * iterm) list * iterm;
    54   val unfold_const_app: iterm ->
    53   val unfold_const_app: iterm ->
    55     ((string * (iclasslookup list list * itype)) * iterm list) option;
    54     ((string * (inst list list * itype)) * iterm list) option;
    56   val add_constnames: iterm -> string list -> string list;
    55   val add_constnames: iterm -> string list -> string list;
    57   val add_varnames: iterm -> string list -> string list;
    56   val add_varnames: iterm -> string list -> string list;
    58   val is_pat: (string -> bool) -> iterm -> bool;
    57   val is_pat: (string -> bool) -> iterm -> bool;
    59   val vars_distinct: iterm list -> bool;
    58   val vars_distinct: iterm list -> bool;
    60   val map_pure: (iterm -> 'a) -> iterm -> 'a;
    59   val map_pure: (iterm -> 'a) -> iterm -> 'a;
    61   val eta_expand: (string * (iclasslookup list list * itype)) * iterm list -> int -> iterm;
    60   val eta_expand: (string * (inst list list * itype)) * iterm list -> int -> iterm;
    62   val resolve_tycos: (string -> string) -> itype * iterm list -> itype * iterm list;
    61   val resolve_tycos: (string -> string) -> itype * iterm list -> itype * iterm list;
    63   val resolve_consts: (string -> string) -> iterm -> iterm;
    62   val resolve_consts: (string -> string) -> iterm -> iterm;
    64 
    63 
    65   type funn = (iterm list * iterm) list * (sortcontext * itype);
    64   type typscheme = (vname * sort) list * itype;
    66   type datatyp = sortcontext * (string * itype list) list;
       
    67   datatype def =
    65   datatype def =
    68       Bot
    66       Bot
    69     | Fun of funn
    67     | Fun of (iterm list * iterm) list * typscheme
    70     | Typesyn of sortcontext * itype
    68     | Typesyn of typscheme
    71     | Datatype of datatyp
    69     | Datatype of (vname * sort) list * (string * itype list) list
    72     | Datatypecons of string
    70     | Datatypecons of string
    73     | Class of class list * (vname * (string * (sortcontext * itype)) list)
    71     | Class of class list * (vname * (string * itype) list)
    74     | Classmember of class
    72     | Classmember of class
    75     | Classinst of (class * (string * (vname * sort) list))
    73     | Classinst of (class * (string * (vname * sort) list))
    76           * ((class * iclasslookup list) list
    74           * ((class * inst list) list
    77         * (string * iterm) list);
    75         * (string * iterm) list);
    78   type module;
    76   type module;
    79   type transact;
    77   type transact;
    80   type 'dst transact_fin;
    78   type 'dst transact_fin;
    81   val pretty_def: def -> Pretty.T;
    79   val pretty_def: def -> Pretty.T;
    95     -> string -> transact -> transact;
    93     -> string -> transact -> transact;
    96   val succeed: 'a -> transact -> 'a transact_fin;
    94   val succeed: 'a -> transact -> 'a transact_fin;
    97   val fail: string -> transact -> 'a transact_fin;
    95   val fail: string -> transact -> 'a transact_fin;
    98   val message: string -> (transact -> 'a) -> transact -> 'a;
    96   val message: string -> (transact -> 'a) -> transact -> 'a;
    99   val start_transact: string option -> (transact -> 'a * transact) -> module -> 'a * module;
    97   val start_transact: string option -> (transact -> 'a * transact) -> module -> 'a * module;
   100   val elim_classes: module -> funn -> (iterm list * iterm) list * itype;
    98   val elim_classes: module -> (iterm list * iterm) list * typscheme -> (iterm list * iterm) list * itype;
   101 
    99 
   102   val debug: bool ref;
   100   val debug: bool ref;
   103   val debug_msg: ('a -> string) -> 'a -> 'a;
   101   val debug_msg: ('a -> string) -> 'a -> 'a;
   104   val soft_exc: bool ref;
   102   val soft_exc: bool ref;
   105 
   103 
   138 
   136 
   139 (* language representation *)
   137 (* language representation *)
   140 
   138 
   141 type vname = string;
   139 type vname = string;
   142 
   140 
   143 type sortcontext = ClassPackage.sortcontext;
   141 datatype inst =
   144 datatype iclasslookup =
   142     Instance of string * inst list list
   145     Instance of string * iclasslookup list list
   143   | Context of class list * (vname * int);
   146   | Lookup of class list * (vname * int);
       
   147 
   144 
   148 datatype itype =
   145 datatype itype =
   149     `%% of string * itype list
   146     `%% of string * itype list
   150   | `-> of itype * itype
   147   | `-> of itype * itype
   151   | ITyVar of vname;
   148   | ITyVar of vname;
   152 
   149 
   153 datatype iterm =
   150 datatype iterm =
   154     IConst of string * (iclasslookup list list * itype)
   151     IConst of string * (inst list list * itype)
   155   | IVar of vname
   152   | IVar of vname
   156   | `$ of iterm * iterm
   153   | `$ of iterm * iterm
   157   | `|-> of (vname * itype) * iterm
   154   | `|-> of (vname * itype) * iterm
   158   | INum of IntInf.int * iterm
   155   | INum of IntInf.int * iterm
   159   | IChar of string * iterm
   156   | IChar of string * iterm
   175 
   172 
   176     v, c, co, clsop also annotated with types usw.
   173     v, c, co, clsop also annotated with types usw.
   177 
   174 
   178   constructs:
   175   constructs:
   179     sort                    sort
   176     sort                    sort
   180     sort context            sctxt, vs (variables with sorts)
   177     type parameters         vs
   181     type                    ty
   178     type                    ty
       
   179     type schemes            tysm
   182     term                    t
   180     term                    t
   183     (term as pattern)       p
   181     (term as pattern)       p
   184     instance (classs, tyco) inst
   182     instance (classs, tyco) inst
   185  *)
   183  *)
   186 
   184 
   187 val op `--> = Library.foldr (op `->);
   185 val op `--> = Library.foldr (op `->);
   188 val op `$$ = Library.foldl (op `$);
   186 val op `$$ = Library.foldl (op `$);
   189 val op `|--> = Library.foldr (op `|->);
   187 val op `|--> = Library.foldr (op `|->);
   190 
   188 
   191 val pretty_sortcontext =
   189 val pretty_typparms =
   192   Pretty.list "(" ")" o Pretty.commas o map (fn (v, sort) => (Pretty.block o Pretty.breaks)
   190   Pretty.list "(" ")" o Pretty.commas o map (fn (v, sort) => (Pretty.block o Pretty.breaks)
   193     [Pretty.str v, Pretty.str "::", Pretty.enum "&" "" "" (map Pretty.str sort)]);
   191     [Pretty.str v, Pretty.str "::", Pretty.enum "&" "" "" (map Pretty.str sort)]);
   194 
   192 
   195 fun pretty_itype (tyco `%% tys) =
   193 fun pretty_itype (tyco `%% tys) =
   196       Pretty.enum "" "(" ")" (Pretty.str tyco :: map pretty_itype tys)
   194       Pretty.enum "" "(" ")" (Pretty.str tyco :: map pretty_itype tys)
   254   | map_itype f (tyco `%% tys) =
   252   | map_itype f (tyco `%% tys) =
   255       tyco `%% map f tys
   253       tyco `%% map f tys
   256   | map_itype f (ty1 `-> ty2) =
   254   | map_itype f (ty1 `-> ty2) =
   257       f ty1 `-> f ty2;
   255       f ty1 `-> f ty2;
   258 
   256 
   259 fun eq_ityp ((sctxt1, ty1), (sctxt2, ty2)) =
   257 fun eq_ityp ((vs1, ty1), (vs2, ty2)) =
   260   let
   258   let
   261     exception NO_MATCH;
   259     exception NO_MATCH;
   262     fun eq_sctxt subs sctxt1 sctxt2 =
   260     fun eq_typparms subs vs1 vs2 =
   263       map (fn (v : string, sort : string list) => case AList.lookup (op =) subs v
   261       map (fn (v : string, sort : string list) => case AList.lookup (op =) subs v
   264        of NONE => raise NO_MATCH
   262        of NONE => raise NO_MATCH
   265         | SOME (v' : string) => case AList.lookup (op =) sctxt2 v'
   263         | SOME (v' : string) => case AList.lookup (op =) vs2 v'
   266            of NONE => raise NO_MATCH
   264            of NONE => raise NO_MATCH
   267             | SOME sort' => if sort <> sort' then raise NO_MATCH else ()) sctxt1
   265             | SOME sort' => if sort <> sort' then raise NO_MATCH else ()) vs1
   268     fun eq (ITyVar v1) (ITyVar v2) subs =
   266     fun eq (ITyVar v1) (ITyVar v2) subs =
   269           (case AList.lookup (op =) subs v1
   267           (case AList.lookup (op =) subs v1
   270            of NONE => subs |> AList.update (op =) (v1, v2)
   268            of NONE => subs |> AList.update (op =) (v1, v2)
   271             | SOME v1' =>
   269             | SOME v1' =>
   272                 if v1' <> v2
   270                 if v1' <> v2
   278           else subs |> fold2 eq tys1 tys2
   276           else subs |> fold2 eq tys1 tys2
   279       | eq (ty11 `-> ty12) (ty21 `-> ty22) subs =
   277       | eq (ty11 `-> ty12) (ty21 `-> ty22) subs =
   280           subs |> eq ty11 ty21 |> eq ty12 ty22
   278           subs |> eq ty11 ty21 |> eq ty12 ty22
   281       | eq _ _ _ = raise NO_MATCH;
   279       | eq _ _ _ = raise NO_MATCH;
   282   in
   280   in
   283     (eq ty1 ty2 []; true)
   281     (eq_typparms vs1 vs2; eq ty1 ty2 []; true)
   284     handle NO_MATCH => false
   282     handle NO_MATCH => false
   285   end;
   283   end;
   286 
   284 
   287 fun instant_itype f =
   285 fun instant_itype f =
   288   let
   286   let
   289     fun instant (ITyVar v) = f v
   287     fun instant (ITyVar v) = f v
   290       | instant ty = map_itype instant ty;
   288       | instant ty = map_itype instant ty;
   291   in instant end;
   289   in instant end;
   292 
   290 
   293 fun is_pat is_cons (IConst (c, ([], _))) = is_cons c
   291 fun is_pat is_cons (IConst (c, _)) = is_cons c
   294   | is_pat _ (IVar _) = true
   292   | is_pat _ (IVar _) = true
   295   | is_pat is_cons (t1 `$ t2) =
   293   | is_pat is_cons (t1 `$ t2) =
   296       is_pat is_cons t1 andalso is_pat is_cons t2
   294       is_pat is_cons t1 andalso is_pat is_cons t2
   297   | is_pat _ (INum _) = true
   295   | is_pat _ (INum _) = true
   298   | is_pat _ (IChar _) = true
   296   | is_pat _ (IChar _) = true
   378 
   376 
   379 (** language module system - definitions, modules, transactions **)
   377 (** language module system - definitions, modules, transactions **)
   380 
   378 
   381 (* type definitions *)
   379 (* type definitions *)
   382 
   380 
   383 type funn = (iterm list * iterm) list * (sortcontext * itype);
   381 type typscheme = (vname * sort) list * itype;
   384 type datatyp = sortcontext * (string * itype list) list;
       
   385 
       
   386 datatype def =
   382 datatype def =
   387     Bot
   383     Bot
   388   | Fun of funn
   384   | Fun of (iterm list * iterm) list * typscheme
   389   | Typesyn of sortcontext * itype
   385   | Typesyn of typscheme
   390   | Datatype of datatyp
   386   | Datatype of (vname * sort) list * (string * itype list) list
   391   | Datatypecons of string
   387   | Datatypecons of string
   392   | Class of class list * (vname * (string * (sortcontext * itype)) list)
   388   | Class of class list * (vname * (string * itype) list)
   393   | Classmember of class
   389   | Classmember of class
   394   | Classinst of (class * (string * (vname * sort) list))
   390   | Classinst of (class * (string * (vname * sort) list))
   395           * ((class * iclasslookup list) list
   391         * ((class * inst list) list
   396         * (string * iterm) list);
   392       * (string * iterm) list);
   397 
   393 
   398 datatype node = Def of def | Module of node Graph.T;
   394 datatype node = Def of def | Module of node Graph.T;
   399 type module = node Graph.T;
   395 type module = node Graph.T;
   400 type transact = Graph.key option * module;
   396 type transact = Graph.key option * module;
   401 type 'dst transact_fin = 'dst * module;
   397 type 'dst transact_fin = 'dst * module;
   405 
   401 
   406 (* simple diagnosis *)
   402 (* simple diagnosis *)
   407 
   403 
   408 fun pretty_def Bot =
   404 fun pretty_def Bot =
   409       Pretty.str "<Bot>"
   405       Pretty.str "<Bot>"
   410   | pretty_def (Fun (eqs, (sortctxt, ty))) =
   406   | pretty_def (Fun (eqs, (vs, ty))) =
   411       Pretty.enum " |" "" "" (
   407       Pretty.enum " |" "" "" (
   412         map (fn (ps, body) =>
   408         map (fn (ps, body) =>
   413           Pretty.block [
   409           Pretty.block [
   414             Pretty.enum "," "[" "]" (map pretty_iterm ps),
   410             Pretty.enum "," "[" "]" (map pretty_iterm ps),
   415             Pretty.str " |->",
   411             Pretty.str " |->",
   416             Pretty.brk 1,
   412             Pretty.brk 1,
   417             pretty_iterm body,
   413             pretty_iterm body,
   418             Pretty.str "::",
   414             Pretty.str "::",
   419             pretty_sortcontext sortctxt,
   415             pretty_typparms vs,
   420             Pretty.str "/",
   416             Pretty.str "/",
   421             pretty_itype ty
   417             pretty_itype ty
   422           ]) eqs
   418           ]) eqs
   423         )
   419         )
   424   | pretty_def (Typesyn (vs, ty)) =
   420   | pretty_def (Typesyn (vs, ty)) =
   425       Pretty.block [
   421       Pretty.block [
   426         pretty_sortcontext vs,
   422         pretty_typparms vs,
   427         Pretty.str " |=> ",
   423         Pretty.str " |=> ",
   428         pretty_itype ty
   424         pretty_itype ty
   429       ]
   425       ]
   430   | pretty_def (Datatype (vs, cs)) =
   426   | pretty_def (Datatype (vs, cs)) =
   431       Pretty.block [
   427       Pretty.block [
   432         pretty_sortcontext vs,
   428         pretty_typparms vs,
   433         Pretty.str " |=> ",
   429         Pretty.str " |=> ",
   434         Pretty.enum " |" "" ""
   430         Pretty.enum " |" "" ""
   435           (map (fn (c, tys) => (Pretty.block o Pretty.breaks)
   431           (map (fn (c, tys) => (Pretty.block o Pretty.breaks)
   436             (Pretty.str c :: map pretty_itype tys)) cs)
   432             (Pretty.str c :: map pretty_itype tys)) cs)
   437       ]
   433       ]
   441       Pretty.block [
   437       Pretty.block [
   442         Pretty.str ("class var " ^ v ^ " extending "),
   438         Pretty.str ("class var " ^ v ^ " extending "),
   443         Pretty.enum "," "[" "]" (map Pretty.str supcls),
   439         Pretty.enum "," "[" "]" (map Pretty.str supcls),
   444         Pretty.str " with ",
   440         Pretty.str " with ",
   445         Pretty.enum "," "[" "]"
   441         Pretty.enum "," "[" "]"
   446           (map (fn (m, (_, ty)) => Pretty.block
   442           (map (fn (m, ty) => Pretty.block
   447             [Pretty.str (m ^ "::"), pretty_itype ty]) mems)
   443             [Pretty.str (m ^ "::"), pretty_itype ty]) mems)
   448       ]
   444       ]
   449   | pretty_def (Classmember clsname) =
   445   | pretty_def (Classmember clsname) =
   450       Pretty.block [
   446       Pretty.block [
   451         Pretty.str "class member belonging to ",
   447         Pretty.str "class member belonging to ",
   703 
   699 
   704 (*
   700 (*
   705 fun flat_funs_datatypes modl =
   701 fun flat_funs_datatypes modl =
   706   map (
   702   map (
   707    fn def as (_, Datatype _) => def
   703    fn def as (_, Datatype _) => def
   708     | (name, Fun (eqs, (sctxt, ty))) => let
   704     | (name, Fun (eqs, (vs, ty))) => let
   709           val vs = fold (fn (rhs, lhs) => fold add_varnames rhs #> add_varnames lhs) eqs [];
   705           val vs = fold (fn (rhs, lhs) => fold add_varnames rhs #> add_varnames lhs) eqs [];
   710           fun fold_map_snd f (x, ys) = fold_map f ys #-> (fn zs => pair (x, zs));
   706           fun fold_map_snd f (x, ys) = fold_map f ys #-> (fn zs => pair (x, zs));
   711           fun all_ops_of class = [] : (class * (string * itype) list) list
   707           fun all_ops_of class = [] : (class * (string * itype) list) list
   712             (*FIXME; itype within current context*);
   708             (*FIXME; itype within current context*);
   713           fun name_ops class = 
   709           fun name_ops class = 
   714             (fold_map o fold_map_snd)
   710             (fold_map o fold_map_snd)
   715               (fn (c, ty) => Name.variants [c] #-> (fn [v] => pair (c, (ty, v)))) (all_ops_of class);
   711               (fn (c, ty) => Name.variants [c] #-> (fn [v] => pair (c, (ty, v)))) (all_ops_of class);
   716           (*FIXME: should contain superclasses only once*)
   712           (*FIXME: should contain superclasses only once*)
   717           val (octxt, _) = (fold_map o fold_map_snd) name_ops sctxt
   713           val (octxt, _) = (fold_map o fold_map_snd) name_ops vs
   718             (Name.make_context vs);
   714             (Name.make_context vs);
   719           (* --> (iterm * itype) list *)
   715           (* --> (iterm * itype) list *)
   720           fun flat_classlookup (Instance (inst, lss)) =
   716           fun flat_classlookup (Instance (inst, lss)) =
   721                 (case get_def modl inst
   717                 (case get_def modl inst
   722                  of (Classinst (_, (suparities, ops)))
   718                  of (Classinst (_, (suparities, ops)))
   723                       => maps (maps flat_classlookup o snd) suparities @ map (apsnd flat_iterm) ops
   719                       => maps (maps flat_classlookup o snd) suparities @ map (apsnd flat_iterm) ops
   724                   | _ => error ("Bad instance: " ^ quote inst))
   720                   | _ => error ("Bad instance: " ^ quote inst))
   725             | flat_classlookup (Lookup (classes, (v, k))) =
   721             | flat_classlookup (Context (classes, (v, k))) =
   726                 let
   722                 let
   727                   val parm_map = nth ((the o AList.lookup (op =) octxt) v)
   723                   val parm_map = nth ((the o AList.lookup (op =) octxt) v)
   728                     (if k = ~1 then 0 else k);
   724                     (if k = ~1 then 0 else k);
   729                 in map (apfst IVar o swap o snd) (case classes
   725                 in map (apfst IVar o swap o snd) (case classes
   730                  of class::_ => (the o AList.lookup (op =) parm_map) class
   726                  of class::_ => (the o AList.lookup (op =) parm_map) class
   752             ([], maps ((maps o maps) (map (fst o snd) o snd) o snd) octxt `--> ty)))
   748             ([], maps ((maps o maps) (map (fst o snd) o snd) o snd) octxt `--> ty)))
   753         end
   749         end
   754   ) (flat_module modl);
   750   ) (flat_module modl);
   755 *)
   751 *)
   756 
   752 
   757 val add_deps_of_sortctxt =
   753 val add_deps_of_typparms =
   758   fold (fn (v : vname, sort : sort) => fold (insert (op =)) sort);
   754   fold (fn (v : vname, sort : sort) => fold (insert (op =)) sort);
   759 
   755 
   760 fun add_deps_of_classlookup (Instance (tyco, lss)) =
   756 fun add_deps_of_classlookup (Instance (tyco, lss)) =
   761       insert (op =) tyco
   757       insert (op =) tyco
   762       #> (fold o fold) add_deps_of_classlookup lss
   758       #> (fold o fold) add_deps_of_classlookup lss
   763   | add_deps_of_classlookup (Lookup (clss, _)) =
   759   | add_deps_of_classlookup (Context (clss, _)) =
   764       fold (insert (op =)) clss;
   760       fold (insert (op =)) clss;
   765 
   761 
   766 fun add_deps_of_type (tyco `%% tys) =
   762 fun add_deps_of_type (tyco `%% tys) =
   767       insert (op =) tyco
   763       insert (op =) tyco
   768       #> fold add_deps_of_type tys
   764       #> fold add_deps_of_type tys
   790   | add_deps_of_term (ICase (_, e)) =
   786   | add_deps_of_term (ICase (_, e)) =
   791       add_deps_of_term e;
   787       add_deps_of_term e;
   792 
   788 
   793 fun deps_of Bot =
   789 fun deps_of Bot =
   794       []
   790       []
   795   | deps_of (Fun (eqs, (sctxt, ty))) =
   791   | deps_of (Fun (eqs, (vs, ty))) =
   796       []
   792       []
   797       |> add_deps_of_sortctxt sctxt
   793       |> add_deps_of_typparms vs
   798       |> add_deps_of_type ty
   794       |> add_deps_of_type ty
   799       |> fold (fn (lhs, rhs) => fold add_deps_of_term lhs #> add_deps_of_term rhs) eqs
   795       |> fold (fn (lhs, rhs) => fold add_deps_of_term lhs #> add_deps_of_term rhs) eqs
   800   | deps_of (Typesyn (sctxt, ty)) =
   796   | deps_of (Typesyn (vs, ty)) =
   801       []
   797       []
   802       |> add_deps_of_sortctxt sctxt
   798       |> add_deps_of_typparms vs
   803       |> add_deps_of_type ty
   799       |> add_deps_of_type ty
   804   | deps_of (Datatype (sctxt, cos)) =
   800   | deps_of (Datatype (vs, cos)) =
   805       []
   801       []
   806       |> add_deps_of_sortctxt sctxt
   802       |> add_deps_of_typparms vs
   807       |> fold (fn (c, tys) => insert (op =) c #> fold add_deps_of_type tys) cos
   803       |> fold (fn (c, tys) => insert (op =) c #> fold add_deps_of_type tys) cos
   808   | deps_of (Datatypecons dtco) =
   804   | deps_of (Datatypecons dtco) =
   809       [dtco]
   805       [dtco]
   810   | deps_of (Class (supclss, (_, memdecls))) =
   806   | deps_of (Class (supclss, (_, memdecls))) =
   811       []
   807       []
   812       |> fold (insert (op =)) supclss
   808       |> fold (insert (op =)) supclss
   813       |> fold (fn (name, (sctxt, ty)) =>
   809       |> fold (fn (name, ty) =>
   814             insert (op =) name
   810             insert (op =) name
   815             #> add_deps_of_sortctxt sctxt
       
   816             #> add_deps_of_type ty
   811             #> add_deps_of_type ty
   817       ) memdecls
   812       ) memdecls
   818   | deps_of (Classmember class) =
   813   | deps_of (Classmember class) =
   819       [class]
   814       [class]
   820   | deps_of (Classinst ((class, (tyco, sctxt)), (suparities, memdefs))) =
   815   | deps_of (Classinst ((class, (tyco, vs)), (suparities, memdefs))) =
   821       []
   816       []
   822       |> insert (op =) class
   817       |> insert (op =) class
   823       |> insert (op =) tyco
   818       |> insert (op =) tyco
   824       |> add_deps_of_sortctxt sctxt
   819       |> add_deps_of_typparms vs
   825       |> fold (fn (supclass, ls) =>
   820       |> fold (fn (supclass, ls) =>
   826             insert (op =) supclass
   821             insert (op =) supclass
   827             #> fold add_deps_of_classlookup ls
   822             #> fold add_deps_of_classlookup ls
   828       ) suparities
   823       ) suparities
   829       |> fold (fn (name, e) =>
   824       |> fold (fn (name, e) =>
  1059   let
  1054   let
  1060     val name = "VALUE";
  1055     val name = "VALUE";
  1061     val sname = NameSpace.pack [shallow, name];
  1056     val sname = NameSpace.pack [shallow, name];
  1062   in
  1057   in
  1063     modl
  1058     modl
  1064     |> add_def (sname, Fun ([([], e)], ([("a", [])], ITyVar "a")))
  1059     |> add_def (sname, Fun ([([], e)], ([("_", [])], ITyVar "_")))
  1065     |> fold (curry add_dep sname) (add_deps_of_term e [])
  1060     |> fold (curry add_dep sname) (add_deps_of_term e [])
  1066     |> pair name
  1061     |> pair name
  1067   end;
  1062   end;
  1068 
  1063 
  1069 
  1064 
  1070 (** eliminating classes in definitions **)
  1065 (** eliminating classes in definitions **)
  1071 
  1066 
  1072 fun elim_classes modl (eqs, (sortctxt, ty)) =
  1067 fun elim_classes modl (eqs, (vs, ty)) =
  1073   let
  1068   let
  1074     fun elim_expr _ = ();
  1069     fun elim_expr _ = ();
  1075   in (error ""; (eqs, ty)) end;
  1070   in (error ""; (eqs, ty)) end;
  1076 
  1071 
  1077 (** generic serialization **)
  1072 (** generic serialization **)