35 -> local_theory -> theory |
35 -> local_theory -> theory |
36 val prove_instantiation_exit_result: (morphism -> 'a -> 'b) |
36 val prove_instantiation_exit_result: (morphism -> 'a -> 'b) |
37 -> (Proof.context -> 'b -> tactic) -> 'a -> local_theory -> 'b * theory |
37 -> (Proof.context -> 'b -> tactic) -> 'a -> local_theory -> 'b * theory |
38 val read_multi_arity: theory -> xstring list * xstring list * xstring |
38 val read_multi_arity: theory -> xstring list * xstring list * xstring |
39 -> string list * (string * sort) list * sort |
39 -> string list * (string * sort) list * sort |
40 val type_name: string -> string |
|
41 val instantiation_cmd: xstring list * xstring list * xstring -> theory -> local_theory |
40 val instantiation_cmd: xstring list * xstring list * xstring -> theory -> local_theory |
42 val instance_arity_cmd: xstring list * xstring list * xstring -> theory -> Proof.state |
41 val instance_arity_cmd: xstring list * xstring list * xstring -> theory -> Proof.state |
43 |
42 |
44 (*subclasses*) |
43 (*subclasses*) |
45 val classrel: class * class -> theory -> Proof.state |
44 val classrel: class * class -> theory -> Proof.state |
465 in if Vartab.is_empty tvartab then ts else (map o map_types) inst ts end; |
464 in if Vartab.is_empty tvartab then ts else (map o map_types) inst ts end; |
466 |
465 |
467 |
466 |
468 (* target *) |
467 (* target *) |
469 |
468 |
470 val sanitize_name = (*necessary as long as "dirty" type identifiers are permitted*) |
|
471 let |
|
472 fun is_valid s = Symbol.is_ascii_letter s orelse Symbol.is_ascii_digit s |
|
473 orelse s = "'" orelse s = "_"; |
|
474 val is_junk = not o is_valid andf Symbol.is_regular; |
|
475 val junk = Scan.many is_junk; |
|
476 val scan_valids = Symbol.scanner "Malformed input" |
|
477 ((junk |-- |
|
478 (Scan.optional (Scan.one Symbol.is_ascii_letter) "x" ^^ (Scan.many is_valid >> implode) |
|
479 --| junk)) |
|
480 ::: Scan.repeat ((Scan.many1 is_valid >> implode) --| junk)); |
|
481 in |
|
482 raw_explode #> scan_valids #> implode |
|
483 end; |
|
484 |
|
485 val type_name = sanitize_name o Long_Name.base_name; |
|
486 |
|
487 fun define_overloaded (c, U) v (b_def, rhs) = Local_Theory.background_theory_result |
469 fun define_overloaded (c, U) v (b_def, rhs) = Local_Theory.background_theory_result |
488 (AxClass.declare_overloaded (c, U) ##>> AxClass.define_overloaded b_def (c, rhs)) |
470 (AxClass.declare_overloaded (c, U) ##>> AxClass.define_overloaded b_def (c, rhs)) |
489 ##> (map_instantiation o apsnd) (filter_out (fn (_, (v', _)) => v' = v)) |
471 ##> (map_instantiation o apsnd) (filter_out (fn (_, (v', _)) => v' = v)) |
490 ##> Local_Theory.target synchronize_inst_syntax; |
472 ##> Local_Theory.target synchronize_inst_syntax; |
491 |
473 |
522 val _ = if null tycos then error "At least one arity must be given" else (); |
504 val _ = if null tycos then error "At least one arity must be given" else (); |
523 val class_params = these_params thy (filter (can (AxClass.get_info thy)) sort); |
505 val class_params = these_params thy (filter (can (AxClass.get_info thy)) sort); |
524 fun get_param tyco (param, (_, (c, ty))) = |
506 fun get_param tyco (param, (_, (c, ty))) = |
525 if can (AxClass.param_of_inst thy) (c, tyco) |
507 if can (AxClass.param_of_inst thy) (c, tyco) |
526 then NONE else SOME ((c, tyco), |
508 then NONE else SOME ((c, tyco), |
527 (param ^ "_" ^ type_name tyco, map_atyps (K (Type (tyco, map TFree vs))) ty)); |
509 (param ^ "_" ^ Long_Name.base_name tyco, map_atyps (K (Type (tyco, map TFree vs))) ty)); |
528 val params = map_product get_param tycos class_params |> map_filter I; |
510 val params = map_product get_param tycos class_params |> map_filter I; |
529 val primary_constraints = map (apsnd |
511 val primary_constraints = map (apsnd |
530 (map_atyps (K (TVar ((Name.aT, 0), [])))) o snd o snd) class_params; |
512 (map_atyps (K (TVar ((Name.aT, 0), [])))) o snd o snd) class_params; |
531 val algebra = Sign.classes_of thy |
513 val algebra = Sign.classes_of thy |
532 |> fold (fn tyco => Sorts.add_arities (Proof_Context.init_global thy) |
514 |> fold (fn tyco => Sorts.add_arities (Proof_Context.init_global thy) |