src/HOLCF/Tools/pcpodef.ML
author huffman
Thu Nov 12 14:31:11 2009 -0800 (2009-11-12)
changeset 33646 d2f3104ca3d2
parent 33645 562635ab559b
child 33671 4b0f2599ed48
child 33678 2a2014cbb2a6
permissions -rw-r--r--
improved ML interface to pcpodef
haftmann@31738
     1
(*  Title:      HOLCF/Tools/pcpodef.ML
wenzelm@23152
     2
    Author:     Brian Huffman
wenzelm@23152
     3
wenzelm@23152
     4
Primitive domain definitions for HOLCF, similar to Gordon/HOL-style
haftmann@31738
     5
typedef (see also ~~/src/HOL/Tools/typedef.ML).
wenzelm@23152
     6
*)
wenzelm@23152
     7
haftmann@31738
     8
signature PCPODEF =
wenzelm@23152
     9
sig
huffman@33646
    10
  type cpo_info =
huffman@33646
    11
    { below_def: thm, adm: thm, cont_Rep: thm, cont_Abs: thm,
huffman@33646
    12
      lub: thm, thelub: thm, compact: thm }
huffman@33646
    13
  type pcpo_info =
huffman@33646
    14
    { Rep_strict: thm, Abs_strict: thm, Rep_strict_iff: thm, Abs_strict_iff: thm,
huffman@33646
    15
      Rep_defined: thm, Abs_defined: thm }
huffman@33646
    16
huffman@33646
    17
  val add_podef: bool -> binding option -> binding * string list * mixfix ->
huffman@33646
    18
    term -> (binding * binding) option -> tactic -> theory ->
huffman@33646
    19
    (Typedef.info * thm) * theory
huffman@33646
    20
  val add_cpodef: bool -> binding option -> binding * string list * mixfix ->
huffman@33646
    21
    term -> (binding * binding) option -> tactic * tactic -> theory ->
huffman@33646
    22
    (Typedef.info * cpo_info) * theory
huffman@33645
    23
  val add_pcpodef: bool -> binding option -> binding * string list * mixfix ->
huffman@33646
    24
    term -> (binding * binding) option -> tactic * tactic -> theory ->
huffman@33646
    25
    (Typedef.info * cpo_info * pcpo_info) * theory
huffman@33646
    26
huffman@33646
    27
  val cpodef_proof: (bool * binding) * (binding * string list * mixfix) * term
huffman@33646
    28
    * (binding * binding) option -> theory -> Proof.state
huffman@33646
    29
  val cpodef_proof_cmd: (bool * binding) * (binding * string list * mixfix) * string
huffman@33646
    30
    * (binding * binding) option -> theory -> Proof.state
wenzelm@30345
    31
  val pcpodef_proof: (bool * binding) * (binding * string list * mixfix) * term
wenzelm@30345
    32
    * (binding * binding) option -> theory -> Proof.state
wenzelm@30345
    33
  val pcpodef_proof_cmd: (bool * binding) * (binding * string list * mixfix) * string
wenzelm@30345
    34
    * (binding * binding) option -> theory -> Proof.state
wenzelm@23152
    35
end;
wenzelm@23152
    36
haftmann@31738
    37
structure Pcpodef :> PCPODEF =
wenzelm@23152
    38
struct
wenzelm@23152
    39
wenzelm@23152
    40
(** type definitions **)
wenzelm@23152
    41
huffman@33646
    42
type cpo_info =
huffman@33646
    43
  { below_def: thm, adm: thm, cont_Rep: thm, cont_Abs: thm,
huffman@33646
    44
    lub: thm, thelub: thm, compact: thm }
wenzelm@23152
    45
huffman@33646
    46
type pcpo_info =
huffman@33646
    47
  { Rep_strict: thm, Abs_strict: thm, Rep_strict_iff: thm, Abs_strict_iff: thm,
huffman@33646
    48
    Rep_defined: thm, Abs_defined: thm }
huffman@33646
    49
huffman@33646
    50
(* building terms *)
wenzelm@23152
    51
wenzelm@29060
    52
fun adm_const T = Const (@{const_name adm}, (T --> HOLogic.boolT) --> HOLogic.boolT);
wenzelm@23152
    53
fun mk_adm (x, T, P) = adm_const T $ absfree (x, T, P);
wenzelm@23152
    54
huffman@33646
    55
fun below_const T = Const (@{const_name below}, T --> T --> HOLogic.boolT);
huffman@33646
    56
huffman@33646
    57
(* manipulating theorems *)
huffman@33646
    58
huffman@33646
    59
fun fold_adm_mem thm NONE = thm
huffman@33646
    60
  | fold_adm_mem thm (SOME set_def) =
huffman@33646
    61
    let val rule = @{lemma "A == B ==> adm (%x. x : B) ==> adm (%x. x : A)" by simp}
huffman@33646
    62
    in rule OF [set_def, thm] end;
huffman@33646
    63
huffman@33646
    64
fun fold_UU_mem thm NONE = thm
huffman@33646
    65
  | fold_UU_mem thm (SOME set_def) =
huffman@33646
    66
    let val rule = @{lemma "A == B ==> UU : B ==> UU : A" by simp}
huffman@33646
    67
    in rule OF [set_def, thm] end;
huffman@33646
    68
huffman@33646
    69
(* proving class instances *)
huffman@33646
    70
huffman@33646
    71
fun prove_cpo
huffman@33646
    72
      (name: binding)
huffman@33646
    73
      (newT: typ)
huffman@33646
    74
      (Rep_name: binding, Abs_name: binding)
huffman@33646
    75
      (type_definition: thm)  (* type_definition Rep Abs A *)
huffman@33646
    76
      (set_def: thm option)   (* A == set *)
huffman@33646
    77
      (below_def: thm)        (* op << == %x y. Rep x << Rep y *)
huffman@33646
    78
      (admissible: thm)       (* adm (%x. x : set) *)
huffman@33646
    79
      (thy: theory)
huffman@33646
    80
    =
huffman@33646
    81
  let
huffman@33646
    82
    val admissible' = fold_adm_mem admissible set_def;
huffman@33646
    83
    val cpo_thms = map (Thm.transfer thy) [type_definition, below_def, admissible'];
huffman@33646
    84
    val (full_tname, Ts) = dest_Type newT;
huffman@33646
    85
    val lhs_sorts = map (snd o dest_TFree) Ts;
huffman@33646
    86
    val thy2 =
huffman@33646
    87
      thy
huffman@33646
    88
      |> AxClass.prove_arity (full_tname, lhs_sorts, @{sort cpo})
huffman@33646
    89
          (Tactic.rtac (@{thm typedef_cpo} OF cpo_thms) 1);
huffman@33646
    90
    val cpo_thms' = map (Thm.transfer thy2) cpo_thms;
huffman@33646
    91
    fun make thm = Drule.standard (thm OF cpo_thms');
huffman@33646
    92
    val ([adm, cont_Rep, cont_Abs, lub, thelub, compact], thy3) =
huffman@33646
    93
      thy2
huffman@33646
    94
      |> Sign.add_path (Binding.name_of name)
huffman@33646
    95
      |> PureThy.add_thms
huffman@33646
    96
        ([((Binding.prefix_name "adm_" name, admissible'), []),
huffman@33646
    97
          ((Binding.prefix_name "cont_" Rep_name, make @{thm typedef_cont_Rep}), []),
huffman@33646
    98
          ((Binding.prefix_name "cont_" Abs_name, make @{thm typedef_cont_Abs}), []),
huffman@33646
    99
          ((Binding.prefix_name "lub_" name, make @{thm typedef_lub}), []),
huffman@33646
   100
          ((Binding.prefix_name "thelub_" name, make @{thm typedef_thelub}), []),
huffman@33646
   101
          ((Binding.prefix_name "compact_" name, make @{thm typedef_compact}), [])])
huffman@33646
   102
      ||> Sign.parent_path;
huffman@33646
   103
    val cpo_info : cpo_info =
huffman@33646
   104
      { below_def = below_def, adm = admissible', cont_Rep = cont_Rep,
huffman@33646
   105
        cont_Abs = cont_Abs, lub = lub, thelub = thelub, compact = compact };
huffman@33646
   106
  in
huffman@33646
   107
    (cpo_info, thy3)
huffman@33646
   108
  end;
huffman@33646
   109
huffman@33646
   110
fun prove_pcpo
huffman@33646
   111
      (name: binding)
huffman@33646
   112
      (newT: typ)
huffman@33646
   113
      (Rep_name: binding, Abs_name: binding)
huffman@33646
   114
      (type_definition: thm)  (* type_definition Rep Abs A *)
huffman@33646
   115
      (set_def: thm option)   (* A == set *)
huffman@33646
   116
      (below_def: thm)        (* op << == %x y. Rep x << Rep y *)
huffman@33646
   117
      (UU_mem: thm)           (* UU : set *)
huffman@33646
   118
      (thy: theory)
huffman@33646
   119
    =
huffman@33646
   120
  let
huffman@33646
   121
    val UU_mem' = fold_UU_mem UU_mem set_def;
huffman@33646
   122
    val pcpo_thms = map (Thm.transfer thy) [type_definition, below_def, UU_mem'];
huffman@33646
   123
    val (full_tname, Ts) = dest_Type newT;
huffman@33646
   124
    val lhs_sorts = map (snd o dest_TFree) Ts;
huffman@33646
   125
    val thy2 = thy
huffman@33646
   126
      |> AxClass.prove_arity (full_tname, lhs_sorts, @{sort pcpo})
huffman@33646
   127
        (Tactic.rtac (@{thm typedef_pcpo} OF pcpo_thms) 1);
huffman@33646
   128
    val pcpo_thms' = map (Thm.transfer thy2) pcpo_thms;
huffman@33646
   129
    fun make thm = Drule.standard (thm OF pcpo_thms');
huffman@33646
   130
    val ([Rep_strict, Abs_strict, Rep_strict_iff, Abs_strict_iff,
huffman@33646
   131
          Rep_defined, Abs_defined], thy3) =
huffman@33646
   132
      thy2
huffman@33646
   133
      |> Sign.add_path (Binding.name_of name)
huffman@33646
   134
      |> PureThy.add_thms
huffman@33646
   135
        ([((Binding.suffix_name "_strict" Rep_name, make @{thm typedef_Rep_strict}), []),
huffman@33646
   136
          ((Binding.suffix_name "_strict" Abs_name, make @{thm typedef_Abs_strict}), []),
huffman@33646
   137
          ((Binding.suffix_name "_strict_iff" Rep_name, make @{thm typedef_Rep_strict_iff}), []),
huffman@33646
   138
          ((Binding.suffix_name "_strict_iff" Abs_name, make @{thm typedef_Abs_strict_iff}), []),
huffman@33646
   139
          ((Binding.suffix_name "_defined" Rep_name, make @{thm typedef_Rep_defined}), []),
huffman@33646
   140
          ((Binding.suffix_name "_defined" Abs_name, make @{thm typedef_Abs_defined}), [])])
huffman@33646
   141
      ||> Sign.parent_path;
huffman@33646
   142
    val pcpo_info =
huffman@33646
   143
      { Rep_strict = Rep_strict, Abs_strict = Abs_strict,
huffman@33646
   144
        Rep_strict_iff = Rep_strict_iff, Abs_strict_iff = Abs_strict_iff,
huffman@33646
   145
        Rep_defined = Rep_defined, Abs_defined = Abs_defined };
huffman@33646
   146
  in
huffman@33646
   147
    (pcpo_info, thy3)
huffman@33646
   148
  end;
huffman@33646
   149
huffman@33646
   150
(* prepare_cpodef *)
huffman@33646
   151
huffman@33646
   152
fun declare_type_name a =
huffman@33646
   153
  Variable.declare_constraints (Logic.mk_type (TFree (a, dummyS)));
huffman@33646
   154
huffman@33646
   155
fun prepare prep_term _ name (t, vs, mx) raw_set opt_morphs thy =
wenzelm@23152
   156
  let
wenzelm@29060
   157
    val _ = Theory.requires thy "Pcpodef" "pcpodefs";
wenzelm@23152
   158
    val ctxt = ProofContext.init thy;
wenzelm@30345
   159
wenzelm@23152
   160
    (*rhs*)
wenzelm@23152
   161
    val set = prep_term (ctxt |> fold declare_type_name vs) raw_set;
wenzelm@23152
   162
    val setT = Term.fastype_of set;
wenzelm@29060
   163
    val rhs_tfrees = Term.add_tfrees set [];
wenzelm@23152
   164
    val oldT = HOLogic.dest_setT setT handle TYPE _ =>
wenzelm@24920
   165
      error ("Not a set type: " ^ quote (Syntax.string_of_typ ctxt setT));
wenzelm@29060
   166
huffman@33646
   167
    (*lhs*)
huffman@33646
   168
    val defS = Sign.defaultS thy;
huffman@33646
   169
    val lhs_tfrees = map (fn v => (v, the_default defS (AList.lookup (op =) rhs_tfrees v))) vs;
huffman@33646
   170
    val lhs_sorts = map snd lhs_tfrees;
huffman@33646
   171
    val tname = Binding.map_name (Syntax.type_name mx) t;
huffman@33646
   172
    val full_tname = Sign.full_name thy tname;
huffman@33646
   173
    val newT = Type (full_tname, map TFree lhs_tfrees);
huffman@33646
   174
huffman@33646
   175
    val morphs = opt_morphs
huffman@33646
   176
      |> the_default (Binding.prefix_name "Rep_" name, Binding.prefix_name "Abs_" name);
huffman@33646
   177
  in
huffman@33646
   178
    (newT, oldT, set, morphs, lhs_sorts)
huffman@33646
   179
  end
huffman@33646
   180
huffman@33646
   181
fun add_podef def opt_name typ set opt_morphs tac thy =
huffman@33646
   182
  let
huffman@33646
   183
    val name = the_default (#1 typ) opt_name;
huffman@33646
   184
    val ((full_tname, info as {type_definition, set_def, Rep_name, ...}), thy2) = thy
huffman@33646
   185
      |> Typedef.add_typedef def opt_name typ set opt_morphs tac;
huffman@33646
   186
    val oldT = #rep_type info;
huffman@33646
   187
    val newT = #abs_type info;
huffman@33646
   188
    val lhs_tfrees = map dest_TFree (snd (dest_Type newT));
huffman@33646
   189
huffman@33646
   190
    val RepC = Const (Rep_name, newT --> oldT);
huffman@33646
   191
    val below_def = Logic.mk_equals (below_const newT,
huffman@33646
   192
      Abs ("x", newT, Abs ("y", newT, below_const oldT $ (RepC $ Bound 1) $ (RepC $ Bound 0))));
huffman@33646
   193
    val lthy3 = thy2
huffman@33646
   194
      |> Theory_Target.instantiation ([full_tname], lhs_tfrees, @{sort po});
huffman@33646
   195
    val below_def' = Syntax.check_term lthy3 below_def;
huffman@33646
   196
    val ((_, (_, below_definition')), lthy4) = lthy3
huffman@33646
   197
      |> Specification.definition (NONE,
huffman@33646
   198
          ((Binding.prefix_name "below_" (Binding.suffix_name "_def" name), []), below_def'));
huffman@33646
   199
    val ctxt_thy = ProofContext.init (ProofContext.theory_of lthy4);
huffman@33646
   200
    val below_definition = singleton (ProofContext.export lthy4 ctxt_thy) below_definition';
huffman@33646
   201
    val thy5 = lthy4
huffman@33646
   202
      |> Class.prove_instantiation_instance
huffman@33646
   203
          (K (Tactic.rtac (@{thm typedef_po} OF [type_definition, below_definition]) 1))
huffman@33646
   204
      |> LocalTheory.exit_global;
huffman@33646
   205
  in ((info, below_definition), thy5) end;
huffman@33646
   206
huffman@33646
   207
fun prepare_cpodef
huffman@33646
   208
      (prep_term: Proof.context -> 'a -> term)
huffman@33646
   209
      (def: bool)
huffman@33646
   210
      (name: binding)
huffman@33646
   211
      (typ: binding * string list * mixfix)
huffman@33646
   212
      (raw_set: 'a)
huffman@33646
   213
      (opt_morphs: (binding * binding) option)
huffman@33646
   214
      (thy: theory)
huffman@33646
   215
    : term * term * (thm -> thm -> theory -> (Typedef.info * cpo_info) * theory) =
huffman@33646
   216
  let
huffman@33646
   217
    val (newT, oldT, set, morphs as (Rep_name, Abs_name), lhs_sorts) =
huffman@33646
   218
      prepare prep_term def name typ raw_set opt_morphs thy;
huffman@33646
   219
wenzelm@29063
   220
    val goal_nonempty =
wenzelm@29063
   221
      HOLogic.mk_Trueprop (HOLogic.mk_exists ("x", oldT, HOLogic.mk_mem (Free ("x", oldT), set)));
wenzelm@29063
   222
    val goal_admissible =
wenzelm@29063
   223
      HOLogic.mk_Trueprop (mk_adm ("x", oldT, HOLogic.mk_mem (Free ("x", oldT), set)));
wenzelm@23152
   224
huffman@33646
   225
    fun cpodef_result nonempty admissible thy =
haftmann@28073
   226
      let
huffman@33646
   227
        val ((info as {type_definition, set_def, ...}, below_def), thy2) = thy
huffman@33646
   228
          |> add_podef def (SOME name) typ set opt_morphs (Tactic.rtac nonempty 1);
huffman@33646
   229
        val (cpo_info, thy3) = thy2
huffman@33646
   230
          |> prove_cpo name newT morphs type_definition set_def below_def admissible;
wenzelm@23152
   231
      in
huffman@33646
   232
        ((info, cpo_info), thy3)
wenzelm@23152
   233
      end;
wenzelm@29063
   234
  in
huffman@33646
   235
    (goal_nonempty, goal_admissible, cpodef_result)
wenzelm@29063
   236
  end
wenzelm@30345
   237
  handle ERROR msg =>
wenzelm@30345
   238
    cat_error msg ("The error(s) above occurred in cpodef " ^ quote (Binding.str_of name));
wenzelm@23152
   239
huffman@33646
   240
fun prepare_pcpodef
huffman@33646
   241
      (prep_term: Proof.context -> 'a -> term)
huffman@33646
   242
      (def: bool)
huffman@33646
   243
      (name: binding)
huffman@33646
   244
      (typ: binding * string list * mixfix)
huffman@33646
   245
      (raw_set: 'a)
huffman@33646
   246
      (opt_morphs: (binding * binding) option)
huffman@33646
   247
      (thy: theory)
huffman@33646
   248
    : term * term * (thm -> thm -> theory -> (Typedef.info * cpo_info * pcpo_info) * theory) =
huffman@33646
   249
  let
huffman@33646
   250
    val (newT, oldT, set, morphs as (Rep_name, Abs_name), lhs_sorts) =
huffman@33646
   251
      prepare prep_term def name typ raw_set opt_morphs thy;
huffman@33646
   252
huffman@33646
   253
    val goal_UU_mem =
huffman@33646
   254
      HOLogic.mk_Trueprop (HOLogic.mk_mem (Const (@{const_name UU}, oldT), set));
huffman@33646
   255
huffman@33646
   256
    val goal_admissible =
huffman@33646
   257
      HOLogic.mk_Trueprop (mk_adm ("x", oldT, HOLogic.mk_mem (Free ("x", oldT), set)));
huffman@33646
   258
huffman@33646
   259
    fun pcpodef_result UU_mem admissible thy =
huffman@33646
   260
      let
huffman@33646
   261
        val tac = Tactic.rtac exI 1 THEN Tactic.rtac UU_mem 1;
huffman@33646
   262
        val ((info as {type_definition, set_def, ...}, below_def), thy2) = thy
huffman@33646
   263
          |> add_podef def (SOME name) typ set opt_morphs tac;
huffman@33646
   264
        val (cpo_info, thy3) = thy2
huffman@33646
   265
          |> prove_cpo name newT morphs type_definition set_def below_def admissible;
huffman@33646
   266
        val (pcpo_info, thy4) = thy3
huffman@33646
   267
          |> prove_pcpo name newT morphs type_definition set_def below_def UU_mem;
huffman@33646
   268
      in
huffman@33646
   269
        ((info, cpo_info, pcpo_info), thy4)
huffman@33646
   270
      end;
huffman@33646
   271
  in
huffman@33646
   272
    (goal_UU_mem, goal_admissible, pcpodef_result)
huffman@33646
   273
  end
huffman@33646
   274
  handle ERROR msg =>
huffman@33646
   275
    cat_error msg ("The error(s) above occurred in pcpodef " ^ quote (Binding.str_of name));
huffman@33646
   276
wenzelm@23152
   277
huffman@33645
   278
(* tactic interface *)
huffman@33645
   279
huffman@33646
   280
fun add_cpodef def opt_name typ set opt_morphs (tac1, tac2) thy =
huffman@33646
   281
  let
huffman@33646
   282
    val name = the_default (#1 typ) opt_name;
huffman@33646
   283
    val (goal1, goal2, cpodef_result) =
huffman@33646
   284
      prepare_cpodef Syntax.check_term def name typ set opt_morphs thy;
huffman@33646
   285
    val thm1 = Goal.prove_global thy [] [] goal1 (K tac1)
huffman@33646
   286
      handle ERROR msg => cat_error msg
huffman@33646
   287
        ("Failed to prove non-emptiness of " ^ quote (Syntax.string_of_term_global thy set));
huffman@33646
   288
    val thm2 = Goal.prove_global thy [] [] goal2 (K tac2)
huffman@33646
   289
      handle ERROR msg => cat_error msg
huffman@33646
   290
        ("Failed to prove admissibility of " ^ quote (Syntax.string_of_term_global thy set));
huffman@33646
   291
  in cpodef_result thm1 thm2 thy end;
huffman@33645
   292
huffman@33646
   293
fun add_pcpodef def opt_name typ set opt_morphs (tac1, tac2) thy =
huffman@33645
   294
  let
huffman@33645
   295
    val name = the_default (#1 typ) opt_name;
huffman@33645
   296
    val (goal1, goal2, pcpodef_result) =
huffman@33646
   297
      prepare_pcpodef Syntax.check_term def name typ set opt_morphs thy;
huffman@33646
   298
    val thm1 = Goal.prove_global thy [] [] goal1 (K tac1)
huffman@33645
   299
      handle ERROR msg => cat_error msg
huffman@33645
   300
        ("Failed to prove non-emptiness of " ^ quote (Syntax.string_of_term_global thy set));
huffman@33646
   301
    val thm2 = Goal.prove_global thy [] [] goal2 (K tac2)
huffman@33645
   302
      handle ERROR msg => cat_error msg
huffman@33645
   303
        ("Failed to prove admissibility of " ^ quote (Syntax.string_of_term_global thy set));
huffman@33645
   304
  in pcpodef_result thm1 thm2 thy end;
huffman@33645
   305
huffman@33645
   306
wenzelm@29060
   307
(* proof interface *)
wenzelm@29060
   308
wenzelm@29060
   309
local
wenzelm@23152
   310
huffman@33646
   311
fun gen_cpodef_proof prep_term ((def, name), typ, set, opt_morphs) thy =
wenzelm@23152
   312
  let
wenzelm@29063
   313
    val (goal1, goal2, make_result) =
huffman@33646
   314
      prepare_cpodef prep_term def name typ set opt_morphs thy;
huffman@33646
   315
    fun after_qed [[th1, th2]] = ProofContext.theory (snd o make_result th1 th2);
huffman@33646
   316
  in Proof.theorem_i NONE after_qed [[(goal1, []), (goal2, [])]] (ProofContext.init thy) end;
huffman@33646
   317
huffman@33646
   318
fun gen_pcpodef_proof prep_term ((def, name), typ, set, opt_morphs) thy =
huffman@33646
   319
  let
huffman@33646
   320
    val (goal1, goal2, make_result) =
huffman@33646
   321
      prepare_pcpodef prep_term def name typ set opt_morphs thy;
huffman@33646
   322
    fun after_qed [[th1, th2]] = ProofContext.theory (snd o make_result th1 th2);
wenzelm@29063
   323
  in Proof.theorem_i NONE after_qed [[(goal1, []), (goal2, [])]] (ProofContext.init thy) end;
wenzelm@23152
   324
wenzelm@29060
   325
in
wenzelm@29060
   326
huffman@33646
   327
fun cpodef_proof x = gen_cpodef_proof Syntax.check_term x;
huffman@33646
   328
fun cpodef_proof_cmd x = gen_cpodef_proof Syntax.read_term x;
wenzelm@23152
   329
huffman@33646
   330
fun pcpodef_proof x = gen_pcpodef_proof Syntax.check_term x;
huffman@33646
   331
fun pcpodef_proof_cmd x = gen_pcpodef_proof Syntax.read_term x;
wenzelm@29060
   332
wenzelm@29060
   333
end;
wenzelm@29060
   334
wenzelm@23152
   335
wenzelm@23152
   336
wenzelm@23152
   337
(** outer syntax **)
wenzelm@23152
   338
wenzelm@23152
   339
local structure P = OuterParse and K = OuterKeyword in
wenzelm@23152
   340
wenzelm@23152
   341
val typedef_proof_decl =
wenzelm@23152
   342
  Scan.optional (P.$$$ "(" |--
wenzelm@30345
   343
      ((P.$$$ "open" >> K false) -- Scan.option P.binding || P.binding >> (fn s => (true, SOME s)))
wenzelm@23152
   344
        --| P.$$$ ")") (true, NONE) --
wenzelm@30345
   345
    (P.type_args -- P.binding) -- P.opt_infix -- (P.$$$ "=" |-- P.term) --
wenzelm@30345
   346
    Scan.option (P.$$$ "morphisms" |-- P.!!! (P.binding -- P.binding));
wenzelm@23152
   347
wenzelm@23152
   348
fun mk_pcpodef_proof pcpo ((((((def, opt_name), (vs, t)), mx), A), morphs)) =
wenzelm@29060
   349
  (if pcpo then pcpodef_proof_cmd else cpodef_proof_cmd)
wenzelm@30345
   350
    ((def, the_default (Binding.map_name (Syntax.type_name mx) t) opt_name), (t, vs, mx), A, morphs);
wenzelm@23152
   351
wenzelm@24867
   352
val _ =
wenzelm@23152
   353
  OuterSyntax.command "pcpodef" "HOLCF type definition (requires admissibility proof)" K.thy_goal
wenzelm@23152
   354
    (typedef_proof_decl >>
wenzelm@23152
   355
      (Toplevel.print oo (Toplevel.theory_to_proof o mk_pcpodef_proof true)));
wenzelm@23152
   356
wenzelm@24867
   357
val _ =
wenzelm@23152
   358
  OuterSyntax.command "cpodef" "HOLCF type definition (requires admissibility proof)" K.thy_goal
wenzelm@23152
   359
    (typedef_proof_decl >>
wenzelm@23152
   360
      (Toplevel.print oo (Toplevel.theory_to_proof o mk_pcpodef_proof false)));
wenzelm@23152
   361
wenzelm@23152
   362
end;
wenzelm@23152
   363
wenzelm@23152
   364
end;