src/Pure/Isar/code.ML
changeset 75399 cdf84288d93c
parent 75353 05f7f5454cb6
child 77702 b5fbe9837aee
equal deleted inserted replaced
75398:a58718427bff 75399:cdf84288d93c
   229   | associated_abstype _ = NONE;
   229   | associated_abstype _ = NONE;
   230 
   230 
   231 
   231 
   232 (* cases *)
   232 (* cases *)
   233 
   233 
   234 type case_schema = int * (int * string option list);
   234 type case_schema = int * (int * (string * int) option list);
   235 
   235 
   236 datatype case_spec =
   236 datatype case_spec =
   237     No_Case
   237     No_Case
   238   | Case of {schema: case_schema, tycos: string list, cong: thm}
   238   | Case of {schema: case_schema, tycos: string list, cong: thm}
   239   | Undefined;
   239   | Undefined;
   240 
   240 
   241 fun associated_datatypes (Case {tycos, schema = (_, (_, raw_cos)), ...}) = (tycos, map_filter I raw_cos)
   241 fun associated_datatypes (Case {tycos, schema = (_, (_, raw_cos)), ...}) = (tycos, map fst (map_filter I raw_cos))
   242   | associated_datatypes _ = ([], []);
   242   | associated_datatypes _ = ([], []);
   243 
   243 
   244 
   244 
   245 (** background theory data store **)
   245 (** background theory data store **)
   246 
   246 
  1233                     (Pretty.str (string_of_const thy c)
  1233                     (Pretty.str (string_of_const thy c)
  1234                       :: Pretty.str "of"
  1234                       :: Pretty.str "of"
  1235                       :: map (Pretty.quote o Syntax.pretty_typ_global thy) tys)) cos)
  1235                       :: map (Pretty.quote o Syntax.pretty_typ_global thy) tys)) cos)
  1236       );
  1236       );
  1237     fun pretty_case_param NONE = "<ignored>"
  1237     fun pretty_case_param NONE = "<ignored>"
  1238       | pretty_case_param (SOME c) = string_of_const thy c
  1238       | pretty_case_param (SOME (c, _)) = string_of_const thy c
  1239     fun pretty_case (const, Case {schema = (_, (_, [])), ...}) =
  1239     fun pretty_case (const, Case {schema = (_, (_, [])), ...}) =
  1240           Pretty.str (string_of_const thy const)
  1240           Pretty.str (string_of_const thy const)
  1241       | pretty_case (const, Case {schema = (_, (_, cos)), ...}) =
  1241       | pretty_case (const, Case {schema = (_, (_, cos)), ...}) =
  1242           (Pretty.block o Pretty.breaks) [
  1242           (Pretty.block o Pretty.breaks) [
  1243             Pretty.str (string_of_const thy const), Pretty.str "with",
  1243             Pretty.str (string_of_const thy const), Pretty.str "with",
  1509       (map_filter o Option.map) (fn c => (c, get_type_of_constr c)) cos;
  1509       (map_filter o Option.map) (fn c => (c, get_type_of_constr c)) cos;
  1510     val _ = case map_filter (fn (c, NONE) => SOME c | _ => NONE) cos_with_tycos of
  1510     val _ = case map_filter (fn (c, NONE) => SOME c | _ => NONE) cos_with_tycos of
  1511         [] => ()
  1511         [] => ()
  1512       | cs => error ("Non-constructor(s) in case certificate: " ^ commas_quote cs);
  1512       | cs => error ("Non-constructor(s) in case certificate: " ^ commas_quote cs);
  1513     val tycos = distinct (op =) (map_filter snd cos_with_tycos);
  1513     val tycos = distinct (op =) (map_filter snd cos_with_tycos);
  1514     val schema = (1 + Int.max (1, length cos), (k, cos));
  1514     val schema = (1 + Int.max (1, length cos),
       
  1515       (k, (map o Option.map) (fn c => (c, args_number thy c)) cos));
  1515     val cong = case_cong thy case_const schema;
  1516     val cong = case_cong thy case_const schema;
  1516   in
  1517   in
  1517     thy
  1518     thy
  1518     |> modify_specs (map_cases (History.register case_const
  1519     |> modify_specs (map_cases (History.register case_const
  1519          (Case {schema = schema, tycos = tycos, cong = cong}))
  1520          (Case {schema = schema, tycos = tycos, cong = cong}))