src/HOLCF/Tools/repdef.ML
changeset 40494 db8a09daba7b
parent 40491 6de5839e2fb3
child 40510 638943ad5bdc
equal deleted inserted replaced
40493:c45a3f8a86ea 40494:db8a09daba7b
    12       prj_def : thm,
    12       prj_def : thm,
    13       defl_def : thm,
    13       defl_def : thm,
    14       liftemb_def : thm,
    14       liftemb_def : thm,
    15       liftprj_def : thm,
    15       liftprj_def : thm,
    16       liftdefl_def : thm,
    16       liftdefl_def : thm,
    17       DEFL : thm,
    17       DEFL : thm
    18       LIFTDEFL : thm
       
    19     }
    18     }
    20 
    19 
    21   val add_repdef: bool -> binding option -> binding * (string * sort) list * mixfix ->
    20   val add_repdef: bool -> binding option -> binding * (string * sort) list * mixfix ->
    22     term -> (binding * binding) option -> theory ->
    21     term -> (binding * binding) option -> theory ->
    23     (Typedef.info * Pcpodef.cpo_info * Pcpodef.pcpo_info * rep_info) * theory
    22     (Typedef.info * Pcpodef.cpo_info * Pcpodef.pcpo_info * rep_info) * theory
    42     prj_def : thm,
    41     prj_def : thm,
    43     defl_def : thm,
    42     defl_def : thm,
    44     liftemb_def : thm,
    43     liftemb_def : thm,
    45     liftprj_def : thm,
    44     liftprj_def : thm,
    46     liftdefl_def : thm,
    45     liftdefl_def : thm,
    47     DEFL : thm,
    46     DEFL : thm
    48     LIFTDEFL : thm
       
    49   };
    47   };
    50 
    48 
    51 (* building types and terms *)
    49 (* building types and terms *)
    52 
    50 
    53 val udomT = @{typ udom};
    51 val udomT = @{typ udom};
   149     val liftprj_bind = (Binding.prefix_name "liftprj_" name_def, []);
   147     val liftprj_bind = (Binding.prefix_name "liftprj_" name_def, []);
   150     val liftdefl_bind = (Binding.prefix_name "liftdefl_" name_def, []);
   148     val liftdefl_bind = (Binding.prefix_name "liftdefl_" name_def, []);
   151 
   149 
   152     (*instantiate class rep*)
   150     (*instantiate class rep*)
   153     val lthy = thy
   151     val lthy = thy
   154       |> Class.instantiation ([full_tname], lhs_tfrees, @{sort bifinite});
   152       |> Class.instantiation ([full_tname], lhs_tfrees, @{sort liftdomain});
   155     val ((_, (_, emb_ldef)), lthy) =
   153     val ((_, (_, emb_ldef)), lthy) =
   156         Specification.definition (NONE, (emb_bind, emb_eqn)) lthy;
   154         Specification.definition (NONE, (emb_bind, emb_eqn)) lthy;
   157     val ((_, (_, prj_ldef)), lthy) =
   155     val ((_, (_, prj_ldef)), lthy) =
   158         Specification.definition (NONE, (prj_bind, prj_eqn)) lthy;
   156         Specification.definition (NONE, (prj_bind, prj_eqn)) lthy;
   159     val ((_, (_, defl_ldef)), lthy) =
   157     val ((_, (_, defl_ldef)), lthy) =
   183           (K (Tactic.rtac (@{thm typedef_rep_class} OF typedef_thms) 1))
   181           (K (Tactic.rtac (@{thm typedef_rep_class} OF typedef_thms) 1))
   184       |> Local_Theory.exit_global;
   182       |> Local_Theory.exit_global;
   185 
   183 
   186     (*other theorems*)
   184     (*other theorems*)
   187     val defl_thm' = Thm.transfer thy defl_def;
   185     val defl_thm' = Thm.transfer thy defl_def;
   188     val liftdefl_thm' = Thm.transfer thy liftdefl_def;
       
   189     val (DEFL_thm, thy) = thy
   186     val (DEFL_thm, thy) = thy
   190       |> Sign.add_path (Binding.name_of name)
   187       |> Sign.add_path (Binding.name_of name)
   191       |> Global_Theory.add_thm
   188       |> Global_Theory.add_thm
   192          ((Binding.prefix_name "DEFL_" name,
   189          ((Binding.prefix_name "DEFL_" name,
   193           Drule.zero_var_indexes (@{thm typedef_DEFL} OF [defl_thm'])), [])
   190           Drule.zero_var_indexes (@{thm typedef_DEFL} OF [defl_thm'])), [])
   194       ||> Sign.restore_naming thy;
   191       ||> Sign.restore_naming thy;
   195     val (LIFTDEFL_thm, thy) = thy
       
   196       |> Sign.add_path (Binding.name_of name)
       
   197       |> Global_Theory.add_thm
       
   198          ((Binding.prefix_name "LIFTDEFL_" name,
       
   199           Drule.zero_var_indexes (@{thm typedef_LIFTDEFL} OF [liftdefl_thm'])), [])
       
   200       ||> Sign.restore_naming thy;
       
   201 
   192 
   202     val rep_info =
   193     val rep_info =
   203       { emb_def = emb_def, prj_def = prj_def, defl_def = defl_def,
   194       { emb_def = emb_def, prj_def = prj_def, defl_def = defl_def,
   204         liftemb_def = liftemb_def, liftprj_def = liftprj_def,
   195         liftemb_def = liftemb_def, liftprj_def = liftprj_def,
   205         liftdefl_def = liftdefl_def,
   196         liftdefl_def = liftdefl_def, DEFL = DEFL_thm };
   206         DEFL = DEFL_thm, LIFTDEFL = LIFTDEFL_thm };
       
   207   in
   197   in
   208     ((info, cpo_info, pcpo_info, rep_info), thy)
   198     ((info, cpo_info, pcpo_info, rep_info), thy)
   209   end
   199   end
   210   handle ERROR msg =>
   200   handle ERROR msg =>
   211     cat_error msg ("The error(s) above occurred in repdef " ^ quote (Binding.str_of name));
   201     cat_error msg ("The error(s) above occurred in repdef " ^ quote (Binding.str_of name));