src/Pure/Tools/codegen_consts.ML
author haftmann
Thu, 10 May 2007 10:22:17 +0200
changeset 22921 475ff421a6a3
parent 22737 d87ccbcc2702
child 23691 cedf9610b71d
permissions -rw-r--r--
consts in consts_code Isar commands are now referred to by usual term syntax
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
20387
haftmann
parents:
diff changeset
     1
(*  Title:      Pure/Tools/codegen_consts.ML
haftmann
parents:
diff changeset
     2
    ID:         $Id$
haftmann
parents:
diff changeset
     3
    Author:     Florian Haftmann, TU Muenchen
haftmann
parents:
diff changeset
     4
20855
9f60d493c8fe clarified header comments
haftmann
parents: 20704
diff changeset
     5
Identifying constants by name plus normalized type instantantiation schemes.
22197
461130ccfef4 clarified code
haftmann
parents: 22183
diff changeset
     6
Convenient data structures for constants.  Auxiliary.
20387
haftmann
parents:
diff changeset
     7
*)
haftmann
parents:
diff changeset
     8
haftmann
parents:
diff changeset
     9
signature CODEGEN_CONSTS =
haftmann
parents:
diff changeset
    10
sig
22921
475ff421a6a3 consts in consts_code Isar commands are now referred to by usual term syntax
haftmann
parents: 22737
diff changeset
    11
  type const = string * string option (*constant name, possibly instance*)
20387
haftmann
parents:
diff changeset
    12
  val const_ord: const * const -> order
haftmann
parents:
diff changeset
    13
  val eq_const: const * const -> bool
haftmann
parents:
diff changeset
    14
  structure Consttab: TABLE
22554
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
    15
  val const_of_cexpr: theory -> string * typ -> const
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
    16
  val string_of_typ: theory -> typ -> string
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
    17
  val string_of_const: theory -> const -> string
22921
475ff421a6a3 consts in consts_code Isar commands are now referred to by usual term syntax
haftmann
parents: 22737
diff changeset
    18
  val read_bare_const: theory -> string -> string * typ
22554
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
    19
  val read_const: theory -> string -> const
22737
haftmann
parents: 22554
diff changeset
    20
  val read_const_exprs: theory -> (const list -> const list)
haftmann
parents: 22554
diff changeset
    21
    -> string list -> const list
22554
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
    22
22508
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
    23
  val co_of_const: theory -> const
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
    24
    -> string * ((string * sort) list * (string * typ list))
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
    25
  val co_of_const': theory -> const
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
    26
    -> (string * ((string * sort) list * (string * typ list))) option
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
    27
  val cos_of_consts: theory -> const list
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
    28
    -> string * ((string * sort) list * (string * typ list) list)
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
    29
  val const_of_co: theory -> string -> (string * sort) list
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
    30
    -> string * typ list -> const
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
    31
  val consts_of_cos: theory -> string -> (string * sort) list
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
    32
    -> (string * typ list) list -> const list
22554
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
    33
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
    34
  val typargs: theory -> string * typ -> typ list
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
    35
  val typ_sort_inst: Sorts.algebra -> typ * sort
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
    36
    -> sort Vartab.table -> sort Vartab.table
20387
haftmann
parents:
diff changeset
    37
end;
haftmann
parents:
diff changeset
    38
haftmann
parents:
diff changeset
    39
structure CodegenConsts: CODEGEN_CONSTS =
haftmann
parents:
diff changeset
    40
struct
haftmann
parents:
diff changeset
    41
haftmann
parents:
diff changeset
    42
haftmann
parents:
diff changeset
    43
(* basic data structures *)
haftmann
parents:
diff changeset
    44
22554
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
    45
type const = string * string option;
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
    46
val const_ord = prod_ord fast_string_ord (option_ord string_ord);
20387
haftmann
parents:
diff changeset
    47
val eq_const = is_equal o const_ord;
haftmann
parents:
diff changeset
    48
haftmann
parents:
diff changeset
    49
structure Consttab =
haftmann
parents:
diff changeset
    50
  TableFun(
22554
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
    51
    type key = const;
20387
haftmann
parents:
diff changeset
    52
    val ord = const_ord;
haftmann
parents:
diff changeset
    53
  );
haftmann
parents:
diff changeset
    54
22197
461130ccfef4 clarified code
haftmann
parents: 22183
diff changeset
    55
fun string_of_typ thy = setmp show_sorts true (Sign.string_of_typ thy);
461130ccfef4 clarified code
haftmann
parents: 22183
diff changeset
    56
20387
haftmann
parents:
diff changeset
    57
22554
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
    58
(* conversion between constant expressions and constants *)
20387
haftmann
parents:
diff changeset
    59
22554
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
    60
fun const_of_cexpr thy (c_ty as (c, _)) =
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
    61
  case AxClass.class_of_param thy c
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
    62
   of SOME class => (case Sign.const_typargs thy c_ty
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
    63
       of [Type (tyco, _)] => if can (Sorts.mg_domain (Sign.classes_of thy) tyco) [class]
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
    64
              then (c, SOME tyco)
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
    65
              else (c, NONE)
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
    66
        | [_] => (c, NONE))
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
    67
    | NONE => (c, NONE);
20387
haftmann
parents:
diff changeset
    68
22554
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
    69
fun string_of_const thy (c, NONE) = Sign.extern_const thy c
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
    70
  | string_of_const thy (c, SOME tyco) = Sign.extern_const thy c
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
    71
      ^ " " ^ enclose "[" "]" (Sign.extern_type thy tyco);
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
    72
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
    73
22737
haftmann
parents: 22554
diff changeset
    74
(* reading constants as terms and wildcards pattern *)
22554
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
    75
22921
475ff421a6a3 consts in consts_code Isar commands are now referred to by usual term syntax
haftmann
parents: 22737
diff changeset
    76
fun read_bare_const thy raw_t =
20387
haftmann
parents:
diff changeset
    77
  let
22554
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
    78
    val t = Sign.read_term thy raw_t;
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
    79
  in case try dest_Const t
22921
475ff421a6a3 consts in consts_code Isar commands are now referred to by usual term syntax
haftmann
parents: 22737
diff changeset
    80
   of SOME c_ty => c_ty
22554
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
    81
    | NONE => error ("Not a constant: " ^ Sign.string_of_term thy t)
22197
461130ccfef4 clarified code
haftmann
parents: 22183
diff changeset
    82
  end;
461130ccfef4 clarified code
haftmann
parents: 22183
diff changeset
    83
22921
475ff421a6a3 consts in consts_code Isar commands are now referred to by usual term syntax
haftmann
parents: 22737
diff changeset
    84
fun read_const thy = const_of_cexpr thy o read_bare_const thy;
475ff421a6a3 consts in consts_code Isar commands are now referred to by usual term syntax
haftmann
parents: 22737
diff changeset
    85
22737
haftmann
parents: 22554
diff changeset
    86
local
haftmann
parents: 22554
diff changeset
    87
haftmann
parents: 22554
diff changeset
    88
fun consts_of thy some_thyname =
haftmann
parents: 22554
diff changeset
    89
  let
haftmann
parents: 22554
diff changeset
    90
    val this_thy = Option.map theory some_thyname |> the_default thy;
haftmann
parents: 22554
diff changeset
    91
    val cs = Symtab.fold (fn (c, (_, NONE)) => cons c | _ => I)
haftmann
parents: 22554
diff changeset
    92
      ((snd o #constants o Consts.dest o #consts o Sign.rep_sg) this_thy) [];
haftmann
parents: 22554
diff changeset
    93
    fun classop c = case AxClass.class_of_param thy c
haftmann
parents: 22554
diff changeset
    94
     of NONE => [(c, NONE)]
haftmann
parents: 22554
diff changeset
    95
      | SOME class => Symtab.fold
haftmann
parents: 22554
diff changeset
    96
          (fn (tyco, classes) => if AList.defined (op =) classes class
haftmann
parents: 22554
diff changeset
    97
            then cons (c, SOME tyco) else I)
haftmann
parents: 22554
diff changeset
    98
          ((#arities o Sorts.rep_algebra o Sign.classes_of) this_thy)
haftmann
parents: 22554
diff changeset
    99
          [(c, NONE)];
haftmann
parents: 22554
diff changeset
   100
    val consts = maps classop cs;
haftmann
parents: 22554
diff changeset
   101
    fun test_instance thy (class, tyco) =
haftmann
parents: 22554
diff changeset
   102
      can (Sorts.mg_domain (Sign.classes_of thy) tyco) [class]
haftmann
parents: 22554
diff changeset
   103
    fun belongs_here thyname (c, NONE) =
haftmann
parents: 22554
diff changeset
   104
          not (exists (fn thy' => Sign.declared_const thy' c) (Theory.parents_of this_thy))
haftmann
parents: 22554
diff changeset
   105
      | belongs_here thyname (c, SOME tyco) =
haftmann
parents: 22554
diff changeset
   106
          let
haftmann
parents: 22554
diff changeset
   107
            val SOME class = AxClass.class_of_param thy c
haftmann
parents: 22554
diff changeset
   108
          in not (exists (fn thy' => test_instance thy' (class, tyco))
haftmann
parents: 22554
diff changeset
   109
            (Theory.parents_of this_thy))
haftmann
parents: 22554
diff changeset
   110
          end;
haftmann
parents: 22554
diff changeset
   111
  in case some_thyname
haftmann
parents: 22554
diff changeset
   112
   of NONE => consts
haftmann
parents: 22554
diff changeset
   113
    | SOME thyname => filter (belongs_here thyname) consts
haftmann
parents: 22554
diff changeset
   114
  end;
haftmann
parents: 22554
diff changeset
   115
haftmann
parents: 22554
diff changeset
   116
fun read_const_expr thy "*" = ([], consts_of thy NONE)
haftmann
parents: 22554
diff changeset
   117
  | read_const_expr thy s = if String.isSuffix ".*" s
haftmann
parents: 22554
diff changeset
   118
      then ([], consts_of thy (SOME (unsuffix ".*" s)))
haftmann
parents: 22554
diff changeset
   119
      else ([read_const thy s], []);
haftmann
parents: 22554
diff changeset
   120
haftmann
parents: 22554
diff changeset
   121
in
haftmann
parents: 22554
diff changeset
   122
haftmann
parents: 22554
diff changeset
   123
fun read_const_exprs thy select =
haftmann
parents: 22554
diff changeset
   124
  (op @) o apsnd select o pairself flat o split_list o map (read_const_expr thy);
haftmann
parents: 22554
diff changeset
   125
haftmann
parents: 22554
diff changeset
   126
end; (*local*)
20387
haftmann
parents:
diff changeset
   127
22554
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
   128
(* conversion between constants, constant expressions and datatype constructors *)
22508
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   129
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   130
fun const_of_co thy tyco vs (co, tys) =
22554
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
   131
  const_of_cexpr thy (co, tys ---> Type (tyco, map TFree vs));
22508
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   132
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   133
fun consts_of_cos thy tyco vs cos =
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   134
  let
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   135
    val dty = Type (tyco, map TFree vs);
22554
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
   136
    fun mk_co (co, tys) = const_of_cexpr thy (co, tys ---> dty);
22508
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   137
  in map mk_co cos end;
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   138
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   139
local
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   140
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   141
exception BAD of string;
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   142
22554
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
   143
fun mg_typ_of_const thy (c, NONE) = Sign.the_const_type thy c
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
   144
  | mg_typ_of_const thy (c, SOME tyco) =
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
   145
      let
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
   146
        val SOME class = AxClass.class_of_param thy c;
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
   147
        val ty = Sign.the_const_type thy c;
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
   148
          (*an approximation*)
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
   149
        val sorts = Sorts.mg_domain (Sign.classes_of thy) tyco [class]
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
   150
          handle CLASS_ERROR => raise BAD ("No such instance: " ^ tyco ^ " :: " ^ class
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
   151
            ^ ",\nrequired for overloaded constant " ^ c);
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
   152
        val vs = Name.invents Name.context "'a" (length sorts);
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
   153
      in map_atyps (K (Type (tyco, map (fn v => TVar ((v, 0), [])) vs))) ty end;
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
   154
22508
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   155
fun gen_co_of_const thy const =
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   156
  let
22554
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
   157
    val (c, _) = const;
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
   158
    val ty = (Logic.unvarifyT o mg_typ_of_const thy) const;
22508
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   159
    fun err () = raise BAD
22554
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
   160
     ("Illegal type for datatype constructor: " ^ string_of_typ thy ty);
22508
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   161
    val (tys, ty') = strip_type ty;
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   162
    val (tyco, vs) = ((apsnd o map) dest_TFree o dest_Type) ty'
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   163
      handle TYPE _ => err ();
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   164
    val sorts = if has_duplicates (eq_fst op =) vs then err ()
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   165
      else map snd vs;
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   166
    val vs_names = Name.invent_list [] "'a" (length vs);
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   167
    val vs_map = map fst vs ~~ vs_names;
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   168
    val vs' = vs_names ~~ sorts;
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   169
    val tys' = (map o map_type_tfree) (fn (v, sort) =>
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   170
      (TFree ((the o AList.lookup (op =) vs_map) v, sort))) tys
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   171
      handle Option => err ();
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   172
  in (tyco, (vs', (c, tys'))) end;
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   173
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   174
in
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   175
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   176
fun co_of_const thy const = gen_co_of_const thy const handle BAD msg => error msg;
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   177
fun co_of_const' thy const = SOME (gen_co_of_const thy const) handle BAD msg => NONE;
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   178
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   179
end;
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   180
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   181
fun cos_of_consts thy consts =
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   182
  let
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   183
    val raw_cos  = map (co_of_const thy) consts;
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   184
    val (tyco, (vs_names, sorts_cos)) = if (length o distinct (eq_fst op =)) raw_cos = 1
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   185
      then ((fst o hd) raw_cos, ((map fst o fst o snd o hd) raw_cos,
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   186
        map ((apfst o map) snd o snd) raw_cos))
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   187
      else error ("Term constructors not referring to the same type: "
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   188
        ^ commas (map (string_of_const thy) consts));
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   189
    val sorts = foldr1 ((uncurry o map2 o curry o Sorts.inter_sort) (Sign.classes_of thy))
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   190
      (map fst sorts_cos);
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   191
    val cos = map snd sorts_cos;
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   192
    val vs = vs_names ~~ sorts;
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   193
  in (tyco, (vs, cos)) end;
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   194
6ee2edbce31c added concept for term constructors
haftmann
parents: 22400
diff changeset
   195
22554
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
   196
(* dictionary values *)
20387
haftmann
parents:
diff changeset
   197
22554
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
   198
fun typargs thy (c_ty as (c, ty)) =
20387
haftmann
parents:
diff changeset
   199
  let
22554
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
   200
    val opt_class = AxClass.class_of_param thy c;
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
   201
    val tys = Sign.const_typargs thy (c, ty);
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
   202
  in case (opt_class, tys)
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
   203
   of (SOME class, ty as [Type (tyco, tys')]) =>
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
   204
        if can (Sorts.mg_domain (Sign.classes_of thy) tyco) [class]
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
   205
        then tys' else ty
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
   206
    | _ => tys
20387
haftmann
parents:
diff changeset
   207
  end;
haftmann
parents:
diff changeset
   208
22554
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
   209
fun typ_sort_inst algebra =
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
   210
  let
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
   211
    val inters = Sorts.inter_sort algebra;
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
   212
    fun match _ [] = I
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
   213
      | match (TVar (v, S)) S' = Vartab.map_default (v, []) (fn S'' => inters (S, inters (S', S'')))
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
   214
      | match (Type (a, Ts)) S =
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
   215
          fold2 match Ts (Sorts.mg_domain algebra a S)
d1499fff65d8 simplified constant representation in code generator
haftmann
parents: 22508
diff changeset
   216
  in uncurry match end;
20387
haftmann
parents:
diff changeset
   217
haftmann
parents:
diff changeset
   218
end;