
diff -r 43d6e3730353 -r 0577afdb1732 Nominal/Parser.thy
--- a/Nominal/Parser.thy	Tue Mar 02 17:11:58 2010 +0100
+++ b/Nominal/Parser.thy	Tue Mar 02 17:48:41 2010 +0100
@@ -212,33 +212,51 @@
 ML {* 
 fun nominal_datatype2 dts bn_funs bn_eqs binds lthy =
 let
-  val (((raw_dt_names, (raw_bn_funs, raw_bn_eqs)), raw_binds), lthy2) =
+  val (((raw_dt_names, (raw_bn_funs_loc, raw_bn_eqs_loc)), raw_binds), lthy2) =
     raw_nominal_decls dts bn_funs bn_eqs binds lthy
+  val morphism_2_1 = ProofContext.export_morphism lthy2 lthy
+  val raw_bn_funs = map (Morphism.term morphism_2_1) raw_bn_funs_loc
+  val raw_bn_eqs = ProofContext.export lthy2 lthy raw_bn_eqs_loc
   val dtinfo = Datatype.the_info (ProofContext.theory_of lthy2) (hd raw_dt_names);
   val descr = #descr dtinfo;
+  val sorts = #sorts dtinfo;
+  val all_typs = map (fn i => typ_of_dtyp descr sorts (DtRec i)) (map fst descr)
   val all_full_tnames = map (fn (_, (n, _, _)) => n) descr;
   val dtinfos = map (Datatype.the_info (ProofContext.theory_of lthy2)) all_full_tnames;
   val inject = flat (map #inject dtinfos);
   val distinct = flat (map #distinct dtinfos);
+  val induct = #induct dtinfo;
   val inducts = #inducts dtinfo;
   val ((raw_perm_def, raw_perm_simps, perms), lthy3) =
     Local_Theory.theory_result (define_raw_perms dtinfo (length dts)) lthy2;
   val raw_binds_flat = map (map flat) raw_binds;
   val (((fv_ts_loc, fv_def_loc), alpha), lthy4) = define_fv_alpha dtinfo raw_binds_flat lthy3;
+  val alpha_ts_loc = #preds alpha
+  val morphism_4_3 = ProofContext.export_morphism lthy4 lthy3;
+  val alpha_ts = map (Morphism.term morphism_4_3) alpha_ts_loc;
+  val alpha_induct_loc = #induct alpha
   val dts_names = map (fn (i, (s, _, _)) => (s, i)) (#descr dtinfo);
-  val _ = tracing (PolyML.makestring dts_names);
   val bn_tys = map (domain_type o fastype_of) raw_bn_funs;
-  val _ = tracing (PolyML.makestring bn_tys);
   val bn_nos = map (dtyp_no_of_typ dts_names) bn_tys;
-  val _ = tracing (PolyML.makestring bn_nos);
   val bns = raw_bn_funs ~~ bn_nos;
   val alpha_intros = #intrs alpha;
   val alpha_cases = #elims alpha
   val alpha_inj_loc = build_alpha_inj alpha_intros (inject @ distinct) alpha_cases lthy4
   val (bv_eqvts, lthy5) = fold_map (build_bv_eqvt perms (raw_bn_eqs @ raw_perm_def) inducts) bns lthy4;
-
+  val (fv_eqvts, lthy6) = build_eqvts Binding.empty fv_ts_loc perms
+    ((flat (map snd bv_eqvts)) @ fv_def_loc @ raw_perm_def) induct lthy5;
+  val alpha_eqvt_loc = build_alpha_eqvts alpha_ts_loc perms 
+    (raw_perm_def @ alpha_inj_loc) alpha_induct_loc lthy6;
+  val alpha_eqvt = ProofContext.export lthy6 lthy2 alpha_eqvt_loc;
+  val alpha_equivp_loc = build_equivps alpha_ts_loc induct alpha_induct_loc
+    inject alpha_inj_loc distinct alpha_cases alpha_eqvt_loc lthy6;
+  val alpha_equivp = ProofContext.export lthy6 lthy2 alpha_equivp_loc;
+  val qty_names = map (fn (_, b, _, _) => b) dts;
+  val lthy7 = define_quotient_type
+    (map (fn ((b, t), alpha) => (([], b, NoSyn), (t, alpha))) ((qty_names ~~ all_typs) ~~ alpha_ts))
+    (ALLGOALS (resolve_tac alpha_equivp)) lthy6;
 in
-  ((raw_dt_names, raw_bn_funs, raw_bn_eqs, raw_binds), lthy5)
+  ((raw_dt_names, raw_bn_funs, raw_bn_eqs, raw_binds), lthy7)
 end
 *}
 




