src/HOLCF/Tools/pcpodef.ML
author wenzelm
Sat Mar 13 14:43:04 2010 +0100 (2010-03-13)
changeset 35742 eb8d2f668bfc
parent 35351 7425aece4ee3
child 35840 01d7c4ba9050
permissions -rw-r--r--
global typedef;
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@33678
    90
    (* transfer thms so that they will know about the new cpo instance *)
huffman@33646
    91
    val cpo_thms' = map (Thm.transfer thy2) cpo_thms;
wenzelm@35021
    92
    fun make thm = Drule.export_without_context (thm OF cpo_thms');
huffman@33646
    93
    val ([adm, cont_Rep, cont_Abs, lub, thelub, compact], thy3) =
huffman@33646
    94
      thy2
huffman@33646
    95
      |> Sign.add_path (Binding.name_of name)
huffman@33646
    96
      |> PureThy.add_thms
huffman@33646
    97
        ([((Binding.prefix_name "adm_" name, admissible'), []),
huffman@33646
    98
          ((Binding.prefix_name "cont_" Rep_name, make @{thm typedef_cont_Rep}), []),
huffman@33646
    99
          ((Binding.prefix_name "cont_" Abs_name, make @{thm typedef_cont_Abs}), []),
huffman@33646
   100
          ((Binding.prefix_name "lub_" name, make @{thm typedef_lub}), []),
huffman@33646
   101
          ((Binding.prefix_name "thelub_" name, make @{thm typedef_thelub}), []),
huffman@33646
   102
          ((Binding.prefix_name "compact_" name, make @{thm typedef_compact}), [])])
wenzelm@35203
   103
      ||> Sign.restore_naming thy2;
huffman@33646
   104
    val cpo_info : cpo_info =
huffman@33646
   105
      { below_def = below_def, adm = admissible', cont_Rep = cont_Rep,
huffman@33646
   106
        cont_Abs = cont_Abs, lub = lub, thelub = thelub, compact = compact };
huffman@33646
   107
  in
huffman@33646
   108
    (cpo_info, thy3)
huffman@33646
   109
  end;
huffman@33646
   110
huffman@33646
   111
fun prove_pcpo
huffman@33646
   112
      (name: binding)
huffman@33646
   113
      (newT: typ)
huffman@33646
   114
      (Rep_name: binding, Abs_name: binding)
huffman@33646
   115
      (type_definition: thm)  (* type_definition Rep Abs A *)
huffman@33646
   116
      (set_def: thm option)   (* A == set *)
huffman@33646
   117
      (below_def: thm)        (* op << == %x y. Rep x << Rep y *)
huffman@33646
   118
      (UU_mem: thm)           (* UU : set *)
huffman@33646
   119
      (thy: theory)
huffman@33646
   120
    =
huffman@33646
   121
  let
huffman@33646
   122
    val UU_mem' = fold_UU_mem UU_mem set_def;
huffman@33646
   123
    val pcpo_thms = map (Thm.transfer thy) [type_definition, below_def, UU_mem'];
huffman@33646
   124
    val (full_tname, Ts) = dest_Type newT;
huffman@33646
   125
    val lhs_sorts = map (snd o dest_TFree) Ts;
huffman@33646
   126
    val thy2 = thy
huffman@33646
   127
      |> AxClass.prove_arity (full_tname, lhs_sorts, @{sort pcpo})
huffman@33646
   128
        (Tactic.rtac (@{thm typedef_pcpo} OF pcpo_thms) 1);
huffman@33646
   129
    val pcpo_thms' = map (Thm.transfer thy2) pcpo_thms;
wenzelm@35021
   130
    fun make thm = Drule.export_without_context (thm OF pcpo_thms');
huffman@33646
   131
    val ([Rep_strict, Abs_strict, Rep_strict_iff, Abs_strict_iff,
huffman@33646
   132
          Rep_defined, Abs_defined], thy3) =
huffman@33646
   133
      thy2
huffman@33646
   134
      |> Sign.add_path (Binding.name_of name)
huffman@33646
   135
      |> PureThy.add_thms
huffman@33646
   136
        ([((Binding.suffix_name "_strict" Rep_name, make @{thm typedef_Rep_strict}), []),
huffman@33646
   137
          ((Binding.suffix_name "_strict" Abs_name, make @{thm typedef_Abs_strict}), []),
huffman@33646
   138
          ((Binding.suffix_name "_strict_iff" Rep_name, make @{thm typedef_Rep_strict_iff}), []),
huffman@33646
   139
          ((Binding.suffix_name "_strict_iff" Abs_name, make @{thm typedef_Abs_strict_iff}), []),
huffman@33646
   140
          ((Binding.suffix_name "_defined" Rep_name, make @{thm typedef_Rep_defined}), []),
huffman@33646
   141
          ((Binding.suffix_name "_defined" Abs_name, make @{thm typedef_Abs_defined}), [])])
wenzelm@35203
   142
      ||> Sign.restore_naming thy2;
huffman@33646
   143
    val pcpo_info =
huffman@33646
   144
      { Rep_strict = Rep_strict, Abs_strict = Abs_strict,
huffman@33646
   145
        Rep_strict_iff = Rep_strict_iff, Abs_strict_iff = Abs_strict_iff,
huffman@33646
   146
        Rep_defined = Rep_defined, Abs_defined = Abs_defined };
huffman@33646
   147
  in
huffman@33646
   148
    (pcpo_info, thy3)
huffman@33646
   149
  end;
huffman@33646
   150
huffman@33646
   151
(* prepare_cpodef *)
huffman@33646
   152
huffman@33646
   153
fun declare_type_name a =
huffman@33646
   154
  Variable.declare_constraints (Logic.mk_type (TFree (a, dummyS)));
huffman@33646
   155
wenzelm@35129
   156
fun prepare prep_term name (tname, vs, mx) raw_set opt_morphs thy =
wenzelm@23152
   157
  let
wenzelm@29060
   158
    val _ = Theory.requires thy "Pcpodef" "pcpodefs";
wenzelm@23152
   159
    val ctxt = ProofContext.init thy;
wenzelm@30345
   160
wenzelm@23152
   161
    (*rhs*)
wenzelm@23152
   162
    val set = prep_term (ctxt |> fold declare_type_name vs) raw_set;
wenzelm@23152
   163
    val setT = Term.fastype_of set;
wenzelm@29060
   164
    val rhs_tfrees = Term.add_tfrees set [];
wenzelm@23152
   165
    val oldT = HOLogic.dest_setT setT handle TYPE _ =>
wenzelm@24920
   166
      error ("Not a set type: " ^ quote (Syntax.string_of_typ ctxt setT));
wenzelm@29060
   167
huffman@33646
   168
    (*lhs*)
huffman@33646
   169
    val defS = Sign.defaultS thy;
huffman@33646
   170
    val lhs_tfrees = map (fn v => (v, the_default defS (AList.lookup (op =) rhs_tfrees v))) vs;
huffman@33646
   171
    val full_tname = Sign.full_name thy tname;
huffman@33646
   172
    val newT = Type (full_tname, map TFree lhs_tfrees);
huffman@33646
   173
huffman@33646
   174
    val morphs = opt_morphs
huffman@33646
   175
      |> the_default (Binding.prefix_name "Rep_" name, Binding.prefix_name "Abs_" name);
huffman@33646
   176
  in
huffman@33678
   177
    (newT, oldT, set, morphs)
huffman@33646
   178
  end
huffman@33646
   179
huffman@33646
   180
fun add_podef def opt_name typ set opt_morphs tac thy =
huffman@33646
   181
  let
huffman@33646
   182
    val name = the_default (#1 typ) opt_name;
huffman@33646
   183
    val ((full_tname, info as {type_definition, set_def, Rep_name, ...}), thy2) = thy
wenzelm@35742
   184
      |> Typedef.add_typedef_global def opt_name typ set opt_morphs tac;
huffman@33646
   185
    val oldT = #rep_type info;
huffman@33646
   186
    val newT = #abs_type info;
huffman@33646
   187
    val lhs_tfrees = map dest_TFree (snd (dest_Type newT));
huffman@33646
   188
huffman@33646
   189
    val RepC = Const (Rep_name, newT --> oldT);
huffman@33678
   190
    val below_eqn = Logic.mk_equals (below_const newT,
huffman@33646
   191
      Abs ("x", newT, Abs ("y", newT, below_const oldT $ (RepC $ Bound 1) $ (RepC $ Bound 0))));
huffman@33646
   192
    val lthy3 = thy2
huffman@33646
   193
      |> Theory_Target.instantiation ([full_tname], lhs_tfrees, @{sort po});
huffman@33678
   194
    val ((_, (_, below_ldef)), lthy4) = lthy3
huffman@33646
   195
      |> Specification.definition (NONE,
huffman@33678
   196
          ((Binding.prefix_name "below_" (Binding.suffix_name "_def" name), []), below_eqn));
huffman@33646
   197
    val ctxt_thy = ProofContext.init (ProofContext.theory_of lthy4);
huffman@33678
   198
    val below_def = singleton (ProofContext.export lthy4 ctxt_thy) below_ldef;
huffman@33646
   199
    val thy5 = lthy4
huffman@33646
   200
      |> Class.prove_instantiation_instance
huffman@33678
   201
          (K (Tactic.rtac (@{thm typedef_po} OF [type_definition, below_def]) 1))
wenzelm@33671
   202
      |> Local_Theory.exit_global;
huffman@33678
   203
  in ((info, below_def), thy5) end;
huffman@33646
   204
huffman@33646
   205
fun prepare_cpodef
huffman@33646
   206
      (prep_term: Proof.context -> 'a -> term)
huffman@33646
   207
      (def: bool)
huffman@33646
   208
      (name: binding)
huffman@33646
   209
      (typ: binding * string list * mixfix)
huffman@33646
   210
      (raw_set: 'a)
huffman@33646
   211
      (opt_morphs: (binding * binding) option)
huffman@33646
   212
      (thy: theory)
huffman@33646
   213
    : term * term * (thm -> thm -> theory -> (Typedef.info * cpo_info) * theory) =
huffman@33646
   214
  let
huffman@33678
   215
    val (newT, oldT, set, morphs as (Rep_name, Abs_name)) =
huffman@33678
   216
      prepare prep_term name typ raw_set opt_morphs thy;
huffman@33646
   217
wenzelm@29063
   218
    val goal_nonempty =
wenzelm@29063
   219
      HOLogic.mk_Trueprop (HOLogic.mk_exists ("x", oldT, HOLogic.mk_mem (Free ("x", oldT), set)));
wenzelm@29063
   220
    val goal_admissible =
wenzelm@29063
   221
      HOLogic.mk_Trueprop (mk_adm ("x", oldT, HOLogic.mk_mem (Free ("x", oldT), set)));
wenzelm@23152
   222
huffman@33646
   223
    fun cpodef_result nonempty admissible thy =
haftmann@28073
   224
      let
huffman@33646
   225
        val ((info as {type_definition, set_def, ...}, below_def), thy2) = thy
huffman@33646
   226
          |> add_podef def (SOME name) typ set opt_morphs (Tactic.rtac nonempty 1);
huffman@33646
   227
        val (cpo_info, thy3) = thy2
huffman@33646
   228
          |> prove_cpo name newT morphs type_definition set_def below_def admissible;
wenzelm@23152
   229
      in
huffman@33646
   230
        ((info, cpo_info), thy3)
wenzelm@23152
   231
      end;
wenzelm@29063
   232
  in
huffman@33646
   233
    (goal_nonempty, goal_admissible, cpodef_result)
wenzelm@29063
   234
  end
wenzelm@30345
   235
  handle ERROR msg =>
wenzelm@30345
   236
    cat_error msg ("The error(s) above occurred in cpodef " ^ quote (Binding.str_of name));
wenzelm@23152
   237
huffman@33646
   238
fun prepare_pcpodef
huffman@33646
   239
      (prep_term: Proof.context -> 'a -> term)
huffman@33646
   240
      (def: bool)
huffman@33646
   241
      (name: binding)
huffman@33646
   242
      (typ: binding * string list * mixfix)
huffman@33646
   243
      (raw_set: 'a)
huffman@33646
   244
      (opt_morphs: (binding * binding) option)
huffman@33646
   245
      (thy: theory)
huffman@33646
   246
    : term * term * (thm -> thm -> theory -> (Typedef.info * cpo_info * pcpo_info) * theory) =
huffman@33646
   247
  let
huffman@33678
   248
    val (newT, oldT, set, morphs as (Rep_name, Abs_name)) =
huffman@33678
   249
      prepare prep_term name typ raw_set opt_morphs thy;
huffman@33646
   250
huffman@33646
   251
    val goal_UU_mem =
huffman@33646
   252
      HOLogic.mk_Trueprop (HOLogic.mk_mem (Const (@{const_name UU}, oldT), set));
huffman@33646
   253
huffman@33646
   254
    val goal_admissible =
huffman@33646
   255
      HOLogic.mk_Trueprop (mk_adm ("x", oldT, HOLogic.mk_mem (Free ("x", oldT), set)));
huffman@33646
   256
huffman@33646
   257
    fun pcpodef_result UU_mem admissible thy =
huffman@33646
   258
      let
huffman@33646
   259
        val tac = Tactic.rtac exI 1 THEN Tactic.rtac UU_mem 1;
huffman@33646
   260
        val ((info as {type_definition, set_def, ...}, below_def), thy2) = thy
huffman@33646
   261
          |> add_podef def (SOME name) typ set opt_morphs tac;
huffman@33646
   262
        val (cpo_info, thy3) = thy2
huffman@33646
   263
          |> prove_cpo name newT morphs type_definition set_def below_def admissible;
huffman@33646
   264
        val (pcpo_info, thy4) = thy3
huffman@33646
   265
          |> prove_pcpo name newT morphs type_definition set_def below_def UU_mem;
huffman@33646
   266
      in
huffman@33646
   267
        ((info, cpo_info, pcpo_info), thy4)
huffman@33646
   268
      end;
huffman@33646
   269
  in
huffman@33646
   270
    (goal_UU_mem, goal_admissible, pcpodef_result)
huffman@33646
   271
  end
huffman@33646
   272
  handle ERROR msg =>
huffman@33646
   273
    cat_error msg ("The error(s) above occurred in pcpodef " ^ quote (Binding.str_of name));
huffman@33646
   274
wenzelm@23152
   275
huffman@33645
   276
(* tactic interface *)
huffman@33645
   277
huffman@33646
   278
fun add_cpodef def opt_name typ set opt_morphs (tac1, tac2) thy =
huffman@33646
   279
  let
huffman@33646
   280
    val name = the_default (#1 typ) opt_name;
huffman@33646
   281
    val (goal1, goal2, cpodef_result) =
huffman@33646
   282
      prepare_cpodef Syntax.check_term def name typ set opt_morphs thy;
huffman@33646
   283
    val thm1 = Goal.prove_global thy [] [] goal1 (K tac1)
huffman@33646
   284
      handle ERROR msg => cat_error msg
huffman@33646
   285
        ("Failed to prove non-emptiness of " ^ quote (Syntax.string_of_term_global thy set));
huffman@33646
   286
    val thm2 = Goal.prove_global thy [] [] goal2 (K tac2)
huffman@33646
   287
      handle ERROR msg => cat_error msg
huffman@33646
   288
        ("Failed to prove admissibility of " ^ quote (Syntax.string_of_term_global thy set));
huffman@33646
   289
  in cpodef_result thm1 thm2 thy end;
huffman@33645
   290
huffman@33646
   291
fun add_pcpodef def opt_name typ set opt_morphs (tac1, tac2) thy =
huffman@33645
   292
  let
huffman@33645
   293
    val name = the_default (#1 typ) opt_name;
huffman@33645
   294
    val (goal1, goal2, pcpodef_result) =
huffman@33646
   295
      prepare_pcpodef Syntax.check_term def name typ set opt_morphs thy;
huffman@33646
   296
    val thm1 = Goal.prove_global thy [] [] goal1 (K tac1)
huffman@33645
   297
      handle ERROR msg => cat_error msg
huffman@33645
   298
        ("Failed to prove non-emptiness of " ^ quote (Syntax.string_of_term_global thy set));
huffman@33646
   299
    val thm2 = Goal.prove_global thy [] [] goal2 (K tac2)
huffman@33645
   300
      handle ERROR msg => cat_error msg
huffman@33645
   301
        ("Failed to prove admissibility of " ^ quote (Syntax.string_of_term_global thy set));
huffman@33645
   302
  in pcpodef_result thm1 thm2 thy end;
huffman@33645
   303
huffman@33645
   304
wenzelm@29060
   305
(* proof interface *)
wenzelm@29060
   306
wenzelm@29060
   307
local
wenzelm@23152
   308
huffman@33646
   309
fun gen_cpodef_proof prep_term ((def, name), typ, set, opt_morphs) thy =
wenzelm@23152
   310
  let
wenzelm@29063
   311
    val (goal1, goal2, make_result) =
huffman@33646
   312
      prepare_cpodef prep_term def name typ set opt_morphs thy;
huffman@33646
   313
    fun after_qed [[th1, th2]] = ProofContext.theory (snd o make_result th1 th2);
huffman@33646
   314
  in Proof.theorem_i NONE after_qed [[(goal1, []), (goal2, [])]] (ProofContext.init thy) end;
huffman@33646
   315
huffman@33646
   316
fun gen_pcpodef_proof prep_term ((def, name), typ, set, opt_morphs) thy =
huffman@33646
   317
  let
huffman@33646
   318
    val (goal1, goal2, make_result) =
huffman@33646
   319
      prepare_pcpodef prep_term def name typ set opt_morphs thy;
huffman@33646
   320
    fun after_qed [[th1, th2]] = ProofContext.theory (snd o make_result th1 th2);
wenzelm@29063
   321
  in Proof.theorem_i NONE after_qed [[(goal1, []), (goal2, [])]] (ProofContext.init thy) end;
wenzelm@23152
   322
wenzelm@29060
   323
in
wenzelm@29060
   324
huffman@33646
   325
fun cpodef_proof x = gen_cpodef_proof Syntax.check_term x;
huffman@33646
   326
fun cpodef_proof_cmd x = gen_cpodef_proof Syntax.read_term x;
wenzelm@23152
   327
huffman@33646
   328
fun pcpodef_proof x = gen_pcpodef_proof Syntax.check_term x;
huffman@33646
   329
fun pcpodef_proof_cmd x = gen_pcpodef_proof Syntax.read_term x;
wenzelm@29060
   330
wenzelm@29060
   331
end;
wenzelm@29060
   332
wenzelm@23152
   333
wenzelm@23152
   334
wenzelm@23152
   335
(** outer syntax **)
wenzelm@23152
   336
wenzelm@23152
   337
local structure P = OuterParse and K = OuterKeyword in
wenzelm@23152
   338
wenzelm@23152
   339
val typedef_proof_decl =
wenzelm@23152
   340
  Scan.optional (P.$$$ "(" |--
wenzelm@30345
   341
      ((P.$$$ "open" >> K false) -- Scan.option P.binding || P.binding >> (fn s => (true, SOME s)))
wenzelm@23152
   342
        --| P.$$$ ")") (true, NONE) --
wenzelm@35351
   343
    (P.type_args -- P.binding) -- P.opt_mixfix -- (P.$$$ "=" |-- P.term) --
wenzelm@30345
   344
    Scan.option (P.$$$ "morphisms" |-- P.!!! (P.binding -- P.binding));
wenzelm@23152
   345
wenzelm@23152
   346
fun mk_pcpodef_proof pcpo ((((((def, opt_name), (vs, t)), mx), A), morphs)) =
wenzelm@29060
   347
  (if pcpo then pcpodef_proof_cmd else cpodef_proof_cmd)
wenzelm@35129
   348
    ((def, the_default t opt_name), (t, vs, mx), A, morphs);
wenzelm@23152
   349
wenzelm@24867
   350
val _ =
wenzelm@23152
   351
  OuterSyntax.command "pcpodef" "HOLCF type definition (requires admissibility proof)" K.thy_goal
wenzelm@23152
   352
    (typedef_proof_decl >>
wenzelm@23152
   353
      (Toplevel.print oo (Toplevel.theory_to_proof o mk_pcpodef_proof true)));
wenzelm@23152
   354
wenzelm@24867
   355
val _ =
wenzelm@23152
   356
  OuterSyntax.command "cpodef" "HOLCF type definition (requires admissibility proof)" K.thy_goal
wenzelm@23152
   357
    (typedef_proof_decl >>
wenzelm@23152
   358
      (Toplevel.print oo (Toplevel.theory_to_proof o mk_pcpodef_proof false)));
wenzelm@23152
   359
wenzelm@23152
   360
end;
wenzelm@23152
   361
wenzelm@23152
   362
end;