src/HOLCF/Tools/repdef.ML
author wenzelm
Fri, 19 Mar 2010 00:43:49 +0100
changeset 35840 01d7c4ba9050
parent 35527 f4282471461d
child 35904 0c13e28e5e41
permissions -rw-r--r--
allow sort constraints in HOL/typedef and related HOLCF variants;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
     1
(*  Title:      HOLCF/Tools/repdef.ML
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
     2
    Author:     Brian Huffman
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
     3
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
     4
Defining representable domains using algebraic deflations.
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
     5
*)
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
     6
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
     7
signature REPDEF =
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
     8
sig
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
     9
  type rep_info =
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    10
    { emb_def: thm, prj_def: thm, approx_def: thm, REP: thm }
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    11
35840
01d7c4ba9050 allow sort constraints in HOL/typedef and related HOLCF variants;
wenzelm
parents: 35527
diff changeset
    12
  val add_repdef: bool -> binding option -> binding * (string * sort) list * mixfix ->
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    13
    term -> (binding * binding) option -> theory ->
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    14
    (Typedef.info * Pcpodef.cpo_info * Pcpodef.pcpo_info * rep_info) * theory
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    15
35840
01d7c4ba9050 allow sort constraints in HOL/typedef and related HOLCF variants;
wenzelm
parents: 35527
diff changeset
    16
  val repdef_cmd: (bool * binding) * (binding * (string * string option) list * mixfix) * string
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    17
    * (binding * binding) option -> theory -> theory
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    18
end;
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    19
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    20
structure Repdef :> REPDEF =
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    21
struct
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    22
35527
f4282471461d fixrec and repdef modules import holcf_library
huffman
parents: 35525
diff changeset
    23
open HOLCF_Library;
f4282471461d fixrec and repdef modules import holcf_library
huffman
parents: 35525
diff changeset
    24
f4282471461d fixrec and repdef modules import holcf_library
huffman
parents: 35525
diff changeset
    25
infixr 6 ->>;
f4282471461d fixrec and repdef modules import holcf_library
huffman
parents: 35525
diff changeset
    26
infix -->>;
f4282471461d fixrec and repdef modules import holcf_library
huffman
parents: 35525
diff changeset
    27
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    28
(** type definitions **)
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    29
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    30
type rep_info =
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    31
  { emb_def: thm, prj_def: thm, approx_def: thm, REP: thm };
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    32
35527
f4282471461d fixrec and repdef modules import holcf_library
huffman
parents: 35525
diff changeset
    33
(* building types and terms *)
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    34
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    35
val udomT = @{typ udom};
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    36
fun alg_deflT T = Type (@{type_name alg_defl}, [T]);
35527
f4282471461d fixrec and repdef modules import holcf_library
huffman
parents: 35525
diff changeset
    37
fun emb_const T = Const (@{const_name emb}, T ->> udomT);
f4282471461d fixrec and repdef modules import holcf_library
huffman
parents: 35525
diff changeset
    38
fun prj_const T = Const (@{const_name prj}, udomT ->> T);
f4282471461d fixrec and repdef modules import holcf_library
huffman
parents: 35525
diff changeset
    39
fun approx_const T = Const (@{const_name approx}, natT --> (T ->> T));
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    40
35527
f4282471461d fixrec and repdef modules import holcf_library
huffman
parents: 35525
diff changeset
    41
fun cast_const T = Const (@{const_name cast}, alg_deflT T ->> T ->> T);
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    42
fun mk_cast (t, x) =
35527
f4282471461d fixrec and repdef modules import holcf_library
huffman
parents: 35525
diff changeset
    43
  capply_const (udomT, udomT)
f4282471461d fixrec and repdef modules import holcf_library
huffman
parents: 35525
diff changeset
    44
  $ (capply_const (alg_deflT udomT, udomT ->> udomT) $ cast_const udomT $ t)
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    45
  $ x;
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    46
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    47
(* manipulating theorems *)
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    48
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    49
(* proving class instances *)
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    50
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    51
fun declare_type_name a =
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    52
  Variable.declare_constraints (Logic.mk_type (TFree (a, dummyS)));
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    53
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    54
fun gen_add_repdef
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    55
      (prep_term: Proof.context -> 'a -> term)
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    56
      (def: bool)
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    57
      (name: binding)
35840
01d7c4ba9050 allow sort constraints in HOL/typedef and related HOLCF variants;
wenzelm
parents: 35527
diff changeset
    58
      (typ as (tname, raw_args, mx) : binding * (string * sort) list * mixfix)
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    59
      (raw_defl: 'a)
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    60
      (opt_morphs: (binding * binding) option)
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    61
      (thy: theory)
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    62
    : (Typedef.info * Pcpodef.cpo_info * Pcpodef.pcpo_info * rep_info) * theory =
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    63
  let
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    64
    val _ = Theory.requires thy "Representable" "repdefs";
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    65
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    66
    (*rhs*)
35840
01d7c4ba9050 allow sort constraints in HOL/typedef and related HOLCF variants;
wenzelm
parents: 35527
diff changeset
    67
    val (_, tmp_lthy) =
01d7c4ba9050 allow sort constraints in HOL/typedef and related HOLCF variants;
wenzelm
parents: 35527
diff changeset
    68
      thy |> Theory.copy |> Theory_Target.init NONE
01d7c4ba9050 allow sort constraints in HOL/typedef and related HOLCF variants;
wenzelm
parents: 35527
diff changeset
    69
      |> Typedecl.predeclare_constraints (tname, raw_args, mx);
01d7c4ba9050 allow sort constraints in HOL/typedef and related HOLCF variants;
wenzelm
parents: 35527
diff changeset
    70
    val defl = prep_term tmp_lthy raw_defl;
01d7c4ba9050 allow sort constraints in HOL/typedef and related HOLCF variants;
wenzelm
parents: 35527
diff changeset
    71
    val tmp_lthy' = tmp_lthy |> Variable.declare_constraints defl;
01d7c4ba9050 allow sort constraints in HOL/typedef and related HOLCF variants;
wenzelm
parents: 35527
diff changeset
    72
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    73
    val deflT = Term.fastype_of defl;
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    74
    val _ = if deflT = @{typ "udom alg_defl"} then ()
35840
01d7c4ba9050 allow sort constraints in HOL/typedef and related HOLCF variants;
wenzelm
parents: 35527
diff changeset
    75
            else error ("Not type udom alg_defl: " ^ quote (Syntax.string_of_typ tmp_lthy deflT));
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    76
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    77
    (*lhs*)
35840
01d7c4ba9050 allow sort constraints in HOL/typedef and related HOLCF variants;
wenzelm
parents: 35527
diff changeset
    78
    val lhs_tfrees = map (fn (a, _) => (a, ProofContext.default_sort tmp_lthy' (a, ~1))) raw_args;
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    79
    val lhs_sorts = map snd lhs_tfrees;
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    80
    val full_tname = Sign.full_name thy tname;
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    81
    val newT = Type (full_tname, map TFree lhs_tfrees);
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    82
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    83
    (*morphisms*)
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    84
    val morphs = opt_morphs
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    85
      |> the_default (Binding.prefix_name "Rep_" name, Binding.prefix_name "Abs_" name);
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    86
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    87
    (*set*)
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    88
    val in_defl = @{term "in_deflation :: udom => udom alg_defl => bool"};
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    89
    val set = HOLogic.Collect_const udomT $ Abs ("x", udomT, in_defl $ Bound 0 $ defl);
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    90
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    91
    (*pcpodef*)
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    92
    val tac1 = rtac @{thm CollectI} 1 THEN rtac @{thm bottom_in_deflation} 1;
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    93
    val tac2 = rtac @{thm adm_mem_Collect_in_deflation} 1;
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    94
    val ((info, cpo_info, pcpo_info), thy2) = thy
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    95
      |> Pcpodef.add_pcpodef def (SOME name) typ set (SOME morphs) (tac1, tac2);
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    96
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    97
    (*definitions*)
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    98
    val Rep_const = Const (#Rep_name info, newT --> udomT);
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
    99
    val Abs_const = Const (#Abs_name info, udomT --> newT);
35527
f4282471461d fixrec and repdef modules import holcf_library
huffman
parents: 35525
diff changeset
   100
    val emb_eqn = Logic.mk_equals (emb_const newT, cabs_const (newT, udomT) $ Rep_const);
f4282471461d fixrec and repdef modules import holcf_library
huffman
parents: 35525
diff changeset
   101
    val prj_eqn = Logic.mk_equals (prj_const newT, cabs_const (udomT, newT) $
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   102
      Abs ("x", udomT, Abs_const $ mk_cast (defl, Bound 0)));
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   103
    val repdef_approx_const =
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   104
      Const (@{const_name repdef_approx}, (newT --> udomT) --> (udomT --> newT)
35527
f4282471461d fixrec and repdef modules import holcf_library
huffman
parents: 35525
diff changeset
   105
        --> alg_deflT udomT --> natT --> (newT ->> newT));
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   106
    val approx_eqn = Logic.mk_equals (approx_const newT,
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   107
      repdef_approx_const $ Rep_const $ Abs_const $ defl);
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   108
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   109
    (*instantiate class rep*)
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   110
    val name_def = Binding.suffix_name "_def" name;
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   111
    val ([emb_ldef, prj_ldef, approx_ldef], lthy3) = thy2
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   112
      |> Theory_Target.instantiation ([full_tname], lhs_tfrees, @{sort rep})
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   113
      |> fold_map Specification.definition
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   114
          [ (NONE, ((Binding.prefix_name "emb_" name_def, []), emb_eqn))
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   115
          , (NONE, ((Binding.prefix_name "prj_" name_def, []), prj_eqn))
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   116
          , (NONE, ((Binding.prefix_name "approx_" name_def, []), approx_eqn)) ]
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   117
      |>> map (snd o snd);
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   118
    val ctxt_thy = ProofContext.init (ProofContext.theory_of lthy3);
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   119
    val [emb_def, prj_def, approx_def] =
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   120
      ProofContext.export lthy3 ctxt_thy [emb_ldef, prj_ldef, approx_ldef];
33826
7f12ab745298 make repdef work without (open) option
huffman
parents: 33812
diff changeset
   121
    val type_definition_thm =
7f12ab745298 make repdef work without (open) option
huffman
parents: 33812
diff changeset
   122
      MetaSimplifier.rewrite_rule
7f12ab745298 make repdef work without (open) option
huffman
parents: 33812
diff changeset
   123
        (the_list (#set_def info))
7f12ab745298 make repdef work without (open) option
huffman
parents: 33812
diff changeset
   124
        (#type_definition info);
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   125
    val typedef_thms =
33826
7f12ab745298 make repdef work without (open) option
huffman
parents: 33812
diff changeset
   126
      [type_definition_thm, #below_def cpo_info, emb_def, prj_def, approx_def];
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   127
    val thy4 = lthy3
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   128
      |> Class.prove_instantiation_instance
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   129
          (K (Tactic.rtac (@{thm typedef_rep_class} OF typedef_thms) 1))
33681
cddea85bc87b LocalTheory -> Local_Theory
huffman
parents: 33679
diff changeset
   130
      |> Local_Theory.exit_global;
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   131
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   132
    (*other theorems*)
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   133
    val typedef_thms' = map (Thm.transfer thy4)
33826
7f12ab745298 make repdef work without (open) option
huffman
parents: 33812
diff changeset
   134
      [type_definition_thm, #below_def cpo_info, emb_def, prj_def];
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   135
    val ([REP_thm], thy5) = thy4
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   136
      |> Sign.add_path (Binding.name_of name)
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   137
      |> PureThy.add_thms
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   138
        [((Binding.prefix_name "REP_" name,
35021
c839a4c670c6 renamed old-style Drule.standard to Drule.export_without_context, to emphasize that this is in no way a standard operation;
wenzelm
parents: 33826
diff changeset
   139
          Drule.export_without_context (@{thm typedef_REP} OF typedef_thms')), [])]
35203
ef65a2218c31 Sign.restore_naming -- slightly more robust;
wenzelm
parents: 35129
diff changeset
   140
      ||> Sign.restore_naming thy4;
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   141
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   142
    val rep_info =
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   143
      { emb_def = emb_def, prj_def = prj_def, approx_def = approx_def, REP = REP_thm };
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   144
  in
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   145
    ((info, cpo_info, pcpo_info, rep_info), thy5)
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   146
  end
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   147
  handle ERROR msg =>
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   148
    cat_error msg ("The error(s) above occurred in repdef " ^ quote (Binding.str_of name));
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   149
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   150
fun add_repdef def opt_name typ defl opt_morphs thy =
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   151
  let
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   152
    val name = the_default (#1 typ) opt_name;
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   153
  in
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   154
    gen_add_repdef Syntax.check_term def name typ defl opt_morphs thy
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   155
  end;
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   156
35840
01d7c4ba9050 allow sort constraints in HOL/typedef and related HOLCF variants;
wenzelm
parents: 35527
diff changeset
   157
fun repdef_cmd ((def, name), (b, raw_args, mx), A, morphs) thy =
01d7c4ba9050 allow sort constraints in HOL/typedef and related HOLCF variants;
wenzelm
parents: 35527
diff changeset
   158
  let
01d7c4ba9050 allow sort constraints in HOL/typedef and related HOLCF variants;
wenzelm
parents: 35527
diff changeset
   159
    val ctxt = ProofContext.init thy;
01d7c4ba9050 allow sort constraints in HOL/typedef and related HOLCF variants;
wenzelm
parents: 35527
diff changeset
   160
    val args = map (apsnd (Typedecl.read_constraint ctxt)) raw_args;
01d7c4ba9050 allow sort constraints in HOL/typedef and related HOLCF variants;
wenzelm
parents: 35527
diff changeset
   161
  in snd (gen_add_repdef Syntax.read_term def name (b, args, mx) A morphs thy) end;
01d7c4ba9050 allow sort constraints in HOL/typedef and related HOLCF variants;
wenzelm
parents: 35527
diff changeset
   162
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   163
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   164
(** outer syntax **)
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   165
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   166
local structure P = OuterParse and K = OuterKeyword in
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   167
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   168
val repdef_decl =
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   169
  Scan.optional (P.$$$ "(" |--
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   170
      ((P.$$$ "open" >> K false) -- Scan.option P.binding || P.binding >> (fn s => (true, SOME s)))
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   171
        --| P.$$$ ")") (true, NONE) --
35840
01d7c4ba9050 allow sort constraints in HOL/typedef and related HOLCF variants;
wenzelm
parents: 35527
diff changeset
   172
    (P.type_args_constrained -- P.binding) -- P.opt_mixfix -- (P.$$$ "=" |-- P.term) --
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   173
    Scan.option (P.$$$ "morphisms" |-- P.!!! (P.binding -- P.binding));
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   174
35840
01d7c4ba9050 allow sort constraints in HOL/typedef and related HOLCF variants;
wenzelm
parents: 35527
diff changeset
   175
fun mk_repdef ((((((def, opt_name), (args, t)), mx), A), morphs)) =
01d7c4ba9050 allow sort constraints in HOL/typedef and related HOLCF variants;
wenzelm
parents: 35527
diff changeset
   176
  repdef_cmd ((def, the_default t opt_name), (t, args, mx), A, morphs);
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   177
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   178
val _ =
33812
10c335383c8b thy_decl outer syntax for repdef
huffman
parents: 33681
diff changeset
   179
  OuterSyntax.command "repdef" "HOLCF definition of representable domains" K.thy_decl
33679
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   180
    (repdef_decl >>
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   181
      (Toplevel.print oo (Toplevel.theory o mk_repdef)));
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   182
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   183
end;
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   184
331712879666 automate definition of representable domains from algebraic deflations
huffman
parents:
diff changeset
   185
end;