src/ZF/inductive.ML
author paulson
Fri, 16 Feb 1996 18:00:47 +0100
changeset 1512 ce37c64244c0
parent 516 1957113f0d7d
permissions -rw-r--r--
Elimination of fully-functorial style. Type tactic changed to a type abbrevation (from a datatype). Constructor tactic and function apply deleted.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     1
(*  Title: 	ZF/inductive.ML
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     2
    ID:         $Id$
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     3
    Author: 	Lawrence C Paulson, Cambridge University Computer Laboratory
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     4
    Copyright   1993  University of Cambridge
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     5
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
     6
(Co)Inductive Definitions for Zermelo-Fraenkel Set Theory
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
     7
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
     8
Inductive definitions use least fixedpoints with standard products and sums
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
     9
Coinductive definitions use greatest fixedpoints with Quine products and sums
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    10
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    11
Sums are used only for mutual recursion;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    12
Products are used only to derive "streamlined" induction rules for relations
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    13
*)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    14
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
    15
local open Ind_Syntax
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
    16
in
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    17
structure Lfp =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    18
  struct
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    19
  val oper	= Const("lfp",      [iT,iT-->iT]--->iT)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    20
  val bnd_mono	= Const("bnd_mono", [iT,iT-->iT]--->oT)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    21
  val bnd_monoI	= bnd_monoI
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    22
  val subs	= def_lfp_subset
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    23
  val Tarski	= def_lfp_Tarski
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    24
  val induct	= def_induct
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    25
  end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    26
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    27
structure Standard_Prod =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    28
  struct
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    29
  val sigma	= Const("Sigma", [iT, iT-->iT]--->iT)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    30
  val pair	= Const("Pair", [iT,iT]--->iT)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    31
  val split_const	= Const("split", [[iT,iT]--->iT, iT]--->iT)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    32
  val fsplit_const	= Const("fsplit", [[iT,iT]--->oT, iT]--->oT)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    33
  val pair_iff	= Pair_iff
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    34
  val split_eq	= split
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    35
  val fsplitI	= fsplitI
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    36
  val fsplitD	= fsplitD
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    37
  val fsplitE	= fsplitE
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    38
  end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    39
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    40
structure Standard_Sum =
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    41
  struct
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    42
  val sum	= Const("op +", [iT,iT]--->iT)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    43
  val inl	= Const("Inl", iT-->iT)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    44
  val inr	= Const("Inr", iT-->iT)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    45
  val elim	= Const("case", [iT-->iT, iT-->iT, iT]--->iT)
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    46
  val case_inl	= case_Inl
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    47
  val case_inr	= case_Inr
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    48
  val inl_iff	= Inl_iff
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    49
  val inr_iff	= Inr_iff
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    50
  val distinct	= Inl_Inr_iff
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    51
  val distinct' = Inr_Inl_iff
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    52
  end;
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
    53
end;
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    54
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
    55
functor Ind_section_Fun (Inductive: sig include INDUCTIVE_ARG INDUCTIVE_I end) 
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
    56
  : sig include INTR_ELIM INDRULE end =
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    57
struct
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    58
structure Intr_elim = 
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
    59
    Intr_elim_Fun(structure Inductive=Inductive and Fp=Lfp and 
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    60
		  Pr=Standard_Prod and Su=Standard_Sum);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    61
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
    62
structure Indrule = Indrule_Fun (structure Inductive=Inductive and 
0
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    63
		                 Pr=Standard_Prod and Intr_elim=Intr_elim);
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    64
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    65
open Intr_elim Indrule
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    66
end;
a5a9c433f639 Initial revision
clasohm
parents:
diff changeset
    67
516
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
    68
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
    69
structure Ind = Add_inductive_def_Fun
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
    70
    (structure Fp=Lfp and Pr=Standard_Prod and Su=Standard_Sum);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
    71
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
    72
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
    73
signature INDUCTIVE_STRING =
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
    74
  sig
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
    75
  val thy_name   : string 		(*name of the new theory*)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
    76
  val rec_doms   : (string*string) list	(*recursion terms and their domains*)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
    77
  val sintrs     : string list		(*desired introduction rules*)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
    78
  end;
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
    79
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
    80
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
    81
(*For upwards compatibility: can be called directly from ML*)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
    82
functor Inductive_Fun
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
    83
 (Inductive: sig include INDUCTIVE_STRING INDUCTIVE_ARG end)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
    84
   : sig include INTR_ELIM INDRULE end =
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
    85
Ind_section_Fun
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
    86
   (open Inductive Ind_Syntax
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
    87
    val sign = sign_of thy;
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
    88
    val rec_tms = map (readtm sign iT o #1) rec_doms
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
    89
    and domts   = map (readtm sign iT o #2) rec_doms
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
    90
    and intr_tms = map (readtm sign propT) sintrs;
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
    91
    val thy = thy |> Ind.add_fp_def_i(rec_tms, domts, intr_tms) 
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
    92
                  |> add_thyname thy_name);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
    93
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
    94
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
    95
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
    96
local open Ind_Syntax
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
    97
in
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
    98
structure Gfp =
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
    99
  struct
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   100
  val oper	= Const("gfp",      [iT,iT-->iT]--->iT)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   101
  val bnd_mono	= Const("bnd_mono", [iT,iT-->iT]--->oT)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   102
  val bnd_monoI	= bnd_monoI
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   103
  val subs	= def_gfp_subset
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   104
  val Tarski	= def_gfp_Tarski
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   105
  val induct	= def_Collect_coinduct
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   106
  end;
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   107
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   108
structure Quine_Prod =
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   109
  struct
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   110
  val sigma	= Const("QSigma", [iT, iT-->iT]--->iT)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   111
  val pair	= Const("QPair", [iT,iT]--->iT)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   112
  val split_const	= Const("qsplit", [[iT,iT]--->iT, iT]--->iT)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   113
  val fsplit_const	= Const("qfsplit", [[iT,iT]--->oT, iT]--->oT)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   114
  val pair_iff	= QPair_iff
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   115
  val split_eq	= qsplit
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   116
  val fsplitI	= qfsplitI
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   117
  val fsplitD	= qfsplitD
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   118
  val fsplitE	= qfsplitE
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   119
  end;
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   120
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   121
structure Quine_Sum =
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   122
  struct
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   123
  val sum	= Const("op <+>", [iT,iT]--->iT)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   124
  val inl	= Const("QInl", iT-->iT)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   125
  val inr	= Const("QInr", iT-->iT)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   126
  val elim	= Const("qcase", [iT-->iT, iT-->iT, iT]--->iT)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   127
  val case_inl	= qcase_QInl
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   128
  val case_inr	= qcase_QInr
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   129
  val inl_iff	= QInl_iff
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   130
  val inr_iff	= QInr_iff
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   131
  val distinct	= QInl_QInr_iff
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   132
  val distinct' = QInr_QInl_iff
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   133
  end;
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   134
end;
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   135
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   136
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   137
signature COINDRULE =
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   138
  sig
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   139
  val coinduct : thm
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   140
  end;
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   141
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   142
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   143
functor CoInd_section_Fun
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   144
 (Inductive: sig include INDUCTIVE_ARG INDUCTIVE_I end) 
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   145
    : sig include INTR_ELIM COINDRULE end =
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   146
struct
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   147
structure Intr_elim = 
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   148
    Intr_elim_Fun(structure Inductive=Inductive and Fp=Gfp and 
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   149
		  Pr=Quine_Prod and Su=Quine_Sum);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   150
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   151
open Intr_elim 
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   152
val coinduct = raw_induct
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   153
end;
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   154
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   155
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   156
structure CoInd = 
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   157
    Add_inductive_def_Fun(structure Fp=Gfp and Pr=Quine_Prod and Su=Quine_Sum);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   158
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   159
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   160
(*For upwards compatibility: can be called directly from ML*)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   161
functor CoInductive_Fun
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   162
 (Inductive: sig include INDUCTIVE_STRING INDUCTIVE_ARG end)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   163
   : sig include INTR_ELIM COINDRULE end =
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   164
CoInd_section_Fun
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   165
   (open Inductive Ind_Syntax
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   166
    val sign = sign_of thy;
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   167
    val rec_tms = map (readtm sign iT o #1) rec_doms
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   168
    and domts   = map (readtm sign iT o #2) rec_doms
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   169
    and intr_tms = map (readtm sign propT) sintrs;
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   170
    val thy = thy |> CoInd.add_fp_def_i(rec_tms, domts, intr_tms) 
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   171
                  |> add_thyname thy_name);
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   172
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   173
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   174
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   175
(*For installing the theory section.   co is either "" or "Co"*)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   176
fun inductive_decl co =
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   177
  let open ThyParse Ind_Syntax
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   178
      fun mk_intr_name (s,_) =  (*the "op" cancels any infix status*)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   179
	  if Syntax.is_identifier s then "op " ^ s  else "_"
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   180
      fun mk_params (((((domains: (string*string) list, ipairs), 
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   181
			monos), con_defs), type_intrs), type_elims) =
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   182
        let val big_rec_name = space_implode "_" 
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   183
		             (map (scan_to_id o trim o #1) domains)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   184
	    and srec_tms = mk_list (map #1 domains)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   185
            and sdoms    = mk_list (map #2 domains)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   186
	    and sintrs   = mk_big_list (map snd ipairs)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   187
            val stri_name = big_rec_name ^ "_Intrnl"
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   188
        in
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   189
	   (";\n\n\
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   190
            \structure " ^ stri_name ^ " =\n\
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   191
            \ let open Ind_Syntax in\n\
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   192
            \  struct\n\
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   193
            \  val rec_tms\t= map (readtm (sign_of thy) iT) "
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   194
	                     ^ srec_tms ^ "\n\
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   195
            \  and domts\t= map (readtm (sign_of thy) iT) "
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   196
	                     ^ sdoms ^ "\n\
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   197
            \  and intr_tms\t= map (readtm (sign_of thy) propT)\n"
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   198
	                     ^ sintrs ^ "\n\
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   199
            \  end\n\
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   200
            \ end;\n\n\
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   201
            \val thy = thy |> " ^ co ^ "Ind.add_fp_def_i \n    (" ^ 
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   202
	       stri_name ^ ".rec_tms, " ^
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   203
               stri_name ^ ".domts, " ^
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   204
               stri_name ^ ".intr_tms)"
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   205
           ,
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   206
	    "structure " ^ big_rec_name ^ " =\n\
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   207
            \  struct\n\
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   208
            \  val _ = writeln \"" ^ co ^ 
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   209
	               "Inductive definition " ^ big_rec_name ^ "\"\n\
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   210
            \  structure Result = " ^ co ^ "Ind_section_Fun\n\
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   211
            \  (open " ^ stri_name ^ "\n\
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   212
            \   val thy\t\t= thy\n\
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   213
            \   val monos\t\t= " ^ monos ^ "\n\
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   214
            \   val con_defs\t\t= " ^ con_defs ^ "\n\
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   215
            \   val type_intrs\t= " ^ type_intrs ^ "\n\
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   216
            \   val type_elims\t= " ^ type_elims ^ ");\n\n\
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   217
            \  val " ^ mk_list (map mk_intr_name ipairs) ^ " = Result.intrs;\n\
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   218
            \  open Result\n\
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   219
            \  end\n"
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   220
	   )
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   221
	end
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   222
      val domains = "domains" $$-- repeat1 (string --$$ "<=" -- !! string)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   223
      val ipairs  = "intrs"   $$-- repeat1 (ident -- !! string)
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   224
      fun optstring s = optional (s $$-- string) "\"[]\"" >> trim
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   225
  in domains -- ipairs -- optstring "monos" -- optstring "con_defs"
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   226
             -- optstring "type_intrs" -- optstring "type_elims"
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   227
     >> mk_params
1957113f0d7d installation of new inductive/datatype sections
lcp
parents: 0
diff changeset
   228
  end;