src/HOL/Tools/Old_Datatype/old_datatype.ML
author blanchet
Wed, 03 Jan 2018 11:06:29 +0100
changeset 67333 ac0b81ca3ed5
parent 67320 6afba546f0e5
permissions -rw-r--r--
removed old 'add_datatype' ML functions
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
58112
8081087096ad renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents: 58111
diff changeset
     1
(*  Title:      HOL/Tools/Old_Datatype/old_datatype.ML
11539
0f17da240450 tuned headers;
wenzelm
parents: 11345
diff changeset
     2
    Author:     Stefan Berghofer, TU Muenchen
5177
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
     3
67333
ac0b81ca3ed5 removed old 'add_datatype' ML functions
blanchet
parents: 67320
diff changeset
     4
Pieces left from the old datatype package.
5177
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
     5
*)
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
     6
58112
8081087096ad renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents: 58111
diff changeset
     7
signature OLD_DATATYPE =
6360
83573ae0f22c outer syntax for 'datatype';
wenzelm
parents: 6305
diff changeset
     8
sig
58114
4e5a43b0e7dd tuned signatures
blanchet
parents: 58112
diff changeset
     9
  include OLD_DATATYPE_COMMON
4e5a43b0e7dd tuned signatures
blanchet
parents: 58112
diff changeset
    10
45909
6fe61da4c467 tuned signature;
wenzelm
parents: 45901
diff changeset
    11
  val distinct_lemma: thm
45839
43a5b86bc102 'datatype' specifications allow explicit sort constraints;
wenzelm
parents: 45822
diff changeset
    12
  type spec_cmd =
58114
4e5a43b0e7dd tuned signatures
blanchet
parents: 58112
diff changeset
    13
    (binding * (string * string option) list * mixfix) * (binding * string list * mixfix) list
45839
43a5b86bc102 'datatype' specifications allow explicit sort constraints;
wenzelm
parents: 45822
diff changeset
    14
  val read_specs: spec_cmd list -> theory -> spec list * Proof.context
43a5b86bc102 'datatype' specifications allow explicit sort constraints;
wenzelm
parents: 45822
diff changeset
    15
  val check_specs: spec list -> theory -> spec list * Proof.context
32717
0e787c721fa3 re-established reasonable inner outline for module
haftmann
parents: 32712
diff changeset
    16
end;
0e787c721fa3 re-established reasonable inner outline for module
haftmann
parents: 32712
diff changeset
    17
58112
8081087096ad renamed modules defining old datatypes, as a step towards having 'datatype_new' take 'datatype's place
blanchet
parents: 58111
diff changeset
    18
structure Old_Datatype : OLD_DATATYPE =
33963
977b94b64905 renamed former datatype.ML to datatype_data.ML; datatype.ML provides uniform view on datatype.ML and datatype_rep_proofs.ML
haftmann
parents: 33959
diff changeset
    19
struct
5177
0d3a168e4d44 New datatype definition package
berghofe
parents:
diff changeset
    20
45909
6fe61da4c467 tuned signature;
wenzelm
parents: 45901
diff changeset
    21
val distinct_lemma = @{lemma "f x \<noteq> f y ==> x \<noteq> y" by iprover};
45839
43a5b86bc102 'datatype' specifications allow explicit sort constraints;
wenzelm
parents: 45822
diff changeset
    22
43a5b86bc102 'datatype' specifications allow explicit sort constraints;
wenzelm
parents: 45822
diff changeset
    23
type spec_cmd =
43a5b86bc102 'datatype' specifications allow explicit sort constraints;
wenzelm
parents: 45822
diff changeset
    24
  (binding * (string * string option) list * mixfix) * (binding * string list * mixfix) list;
43a5b86bc102 'datatype' specifications allow explicit sort constraints;
wenzelm
parents: 45822
diff changeset
    25
43a5b86bc102 'datatype' specifications allow explicit sort constraints;
wenzelm
parents: 45822
diff changeset
    26
fun parse_spec ctxt ((b, args, mx), constrs) =
43a5b86bc102 'datatype' specifications allow explicit sort constraints;
wenzelm
parents: 45822
diff changeset
    27
  ((b, map (apsnd (Typedecl.read_constraint ctxt)) args, mx),
43a5b86bc102 'datatype' specifications allow explicit sort constraints;
wenzelm
parents: 45822
diff changeset
    28
    constrs |> map (fn (c, Ts, mx') => (c, map (Syntax.parse_typ ctxt) Ts, mx')));
43a5b86bc102 'datatype' specifications allow explicit sort constraints;
wenzelm
parents: 45822
diff changeset
    29
58114
4e5a43b0e7dd tuned signatures
blanchet
parents: 58112
diff changeset
    30
fun check_specs ctxt (specs: Old_Datatype_Aux.spec list) =
45839
43a5b86bc102 'datatype' specifications allow explicit sort constraints;
wenzelm
parents: 45822
diff changeset
    31
  let
43a5b86bc102 'datatype' specifications allow explicit sort constraints;
wenzelm
parents: 45822
diff changeset
    32
    fun prep_spec ((tname, args, mx), constrs) tys =
43a5b86bc102 'datatype' specifications allow explicit sort constraints;
wenzelm
parents: 45822
diff changeset
    33
      let
43a5b86bc102 'datatype' specifications allow explicit sort constraints;
wenzelm
parents: 45822
diff changeset
    34
        val (args', tys1) = chop (length args) tys;
43a5b86bc102 'datatype' specifications allow explicit sort constraints;
wenzelm
parents: 45822
diff changeset
    35
        val (constrs', tys3) = (constrs, tys1) |-> fold_map (fn (cname, cargs, mx') => fn tys2 =>
43a5b86bc102 'datatype' specifications allow explicit sort constraints;
wenzelm
parents: 45822
diff changeset
    36
          let val (cargs', tys3) = chop (length cargs) tys2;
43a5b86bc102 'datatype' specifications allow explicit sort constraints;
wenzelm
parents: 45822
diff changeset
    37
          in ((cname, cargs', mx'), tys3) end);
43a5b86bc102 'datatype' specifications allow explicit sort constraints;
wenzelm
parents: 45822
diff changeset
    38
      in (((tname, map dest_TFree args', mx), constrs'), tys3) end;
43a5b86bc102 'datatype' specifications allow explicit sort constraints;
wenzelm
parents: 45822
diff changeset
    39
43a5b86bc102 'datatype' specifications allow explicit sort constraints;
wenzelm
parents: 45822
diff changeset
    40
    val all_tys =
43a5b86bc102 'datatype' specifications allow explicit sort constraints;
wenzelm
parents: 45822
diff changeset
    41
      specs |> maps (fn ((_, args, _), cs) => map TFree args @ maps #2 cs)
43a5b86bc102 'datatype' specifications allow explicit sort constraints;
wenzelm
parents: 45822
diff changeset
    42
      |> Syntax.check_typs ctxt;
43a5b86bc102 'datatype' specifications allow explicit sort constraints;
wenzelm
parents: 45822
diff changeset
    43
43a5b86bc102 'datatype' specifications allow explicit sort constraints;
wenzelm
parents: 45822
diff changeset
    44
  in #1 (fold_map prep_spec specs all_tys) end;
43a5b86bc102 'datatype' specifications allow explicit sort constraints;
wenzelm
parents: 45822
diff changeset
    45
43a5b86bc102 'datatype' specifications allow explicit sort constraints;
wenzelm
parents: 45822
diff changeset
    46
fun prep_specs parse raw_specs thy =
43a5b86bc102 'datatype' specifications allow explicit sort constraints;
wenzelm
parents: 45822
diff changeset
    47
  let
43a5b86bc102 'datatype' specifications allow explicit sort constraints;
wenzelm
parents: 45822
diff changeset
    48
    val ctxt = thy
43a5b86bc102 'datatype' specifications allow explicit sort constraints;
wenzelm
parents: 45822
diff changeset
    49
      |> Sign.add_types_global (map (fn ((b, args, mx), _) => (b, length args, mx)) raw_specs)
43a5b86bc102 'datatype' specifications allow explicit sort constraints;
wenzelm
parents: 45822
diff changeset
    50
      |> Proof_Context.init_global
43a5b86bc102 'datatype' specifications allow explicit sort constraints;
wenzelm
parents: 45822
diff changeset
    51
      |> fold (fn ((_, args, _), _) => fold (fn (a, _) =>
43a5b86bc102 'datatype' specifications allow explicit sort constraints;
wenzelm
parents: 45822
diff changeset
    52
          Variable.declare_typ (TFree (a, dummyS))) args) raw_specs;
43a5b86bc102 'datatype' specifications allow explicit sort constraints;
wenzelm
parents: 45822
diff changeset
    53
    val specs = check_specs ctxt (map (parse ctxt) raw_specs);
43a5b86bc102 'datatype' specifications allow explicit sort constraints;
wenzelm
parents: 45822
diff changeset
    54
  in (specs, ctxt) end;
43a5b86bc102 'datatype' specifications allow explicit sort constraints;
wenzelm
parents: 45822
diff changeset
    55
43a5b86bc102 'datatype' specifications allow explicit sort constraints;
wenzelm
parents: 45822
diff changeset
    56
val read_specs = prep_specs parse_spec;
43a5b86bc102 'datatype' specifications allow explicit sort constraints;
wenzelm
parents: 45822
diff changeset
    57
val check_specs = prep_specs (K I);
43a5b86bc102 'datatype' specifications allow explicit sort constraints;
wenzelm
parents: 45822
diff changeset
    58
58114
4e5a43b0e7dd tuned signatures
blanchet
parents: 58112
diff changeset
    59
open Old_Datatype_Aux;
4e5a43b0e7dd tuned signatures
blanchet
parents: 58112
diff changeset
    60
33968
f94fb13ecbb3 modernized structures and tuned headers of datatype package modules; joined former datatype.ML and datatype_rep_proofs.ML
haftmann
parents: 33963
diff changeset
    61
end;