27 val record_quick_and_dirty_sensitive: bool ref |
27 val record_quick_and_dirty_sensitive: bool ref |
28 val updateN: string |
28 val updateN: string |
29 val ext_typeN: string |
29 val ext_typeN: string |
30 val last_extT: typ -> (string * typ list) option |
30 val last_extT: typ -> (string * typ list) option |
31 val dest_recTs : typ -> (string * typ list) list |
31 val dest_recTs : typ -> (string * typ list) list |
|
32 val get_extT_fields: Sign.sg -> typ -> (string * typ) list |
|
33 val get_recT_fields: Sign.sg -> typ -> (string * typ) list |
32 val get_extension: Sign.sg -> Symtab.key -> (string * typ list) option |
34 val get_extension: Sign.sg -> Symtab.key -> (string * typ list) option |
33 val get_extinjects: Sign.sg -> thm list |
35 val get_extinjects: Sign.sg -> thm list |
|
36 val get_simpset: Sign.sg -> simpset |
34 val print_records: theory -> unit |
37 val print_records: theory -> unit |
35 val add_record: string list * string -> string option -> (string * string * mixfix) list |
38 val add_record: string list * string -> string option -> (string * string * mixfix) list |
36 -> theory -> theory |
39 -> theory -> theory |
37 val add_record_i: string list * string -> (typ list * string) option |
40 val add_record_i: string list * string -> (typ list * string) option |
38 -> (string * typ * mixfix) list -> theory -> theory |
41 -> (string * typ * mixfix) list -> theory -> theory |
397 in RecordsData.put data thy end; |
400 in RecordsData.put data thy end; |
398 |
401 |
399 fun get_extfields sg name = |
402 fun get_extfields sg name = |
400 Symtab.lookup (#extfields (RecordsData.get_sg sg), name); |
403 Symtab.lookup (#extfields (RecordsData.get_sg sg), name); |
401 |
404 |
|
405 fun get_extT_fields sg T = |
|
406 let val {extfields,...} = RecordsData.get_sg sg; |
|
407 in Symtab.lookup_multi (extfields,fst (fst (dest_recT T))) |
|
408 end; |
|
409 |
|
410 fun get_fields extfields T = |
|
411 foldl (fn (xs,(eN,_))=>xs@(Symtab.lookup_multi (extfields,eN))) |
|
412 ([],(dest_recTs T)); |
|
413 |
|
414 fun get_recT_fields sg T = |
|
415 let val {extfields,...} = RecordsData.get_sg sg; |
|
416 in get_fields extfields T |
|
417 end; |
|
418 |
402 (* access 'fieldext' *) |
419 (* access 'fieldext' *) |
403 |
420 |
404 fun add_fieldext extname_types fields thy = |
421 fun add_fieldext extname_types fields thy = |
405 let |
422 let |
406 val {records, sel_upd, equalities, extinjects, extsplit, splits, extfields, fieldext} = |
423 val {records, sel_upd, equalities, extinjects, extsplit, splits, extfields, fieldext} = |
784 end |
801 end |
785 | _ => error "RecordPackage.prove_split_simp:code should never been reached") |
802 | _ => error "RecordPackage.prove_split_simp:code should never been reached") |
786 |
803 |
787 |
804 |
788 |
805 |
789 local |
806 |
790 fun get_fields extfields T = |
|
791 foldl (fn (xs,(eN,_))=>xs@(map fst (Symtab.lookup_multi (extfields,eN)))) |
|
792 ([],(dest_recTs T)); |
|
793 in |
|
794 (* record_simproc *) |
807 (* record_simproc *) |
795 (* Simplifies selections of an record update: |
808 (* Simplifies selections of an record update: |
796 * (1) S (r(|S:=k|)) = k respectively |
809 * (1) S (r(|S:=k|)) = k respectively |
797 * (2) S (r(|X:=k|)) = S r |
810 * (2) S (r(|X:=k|)) = S r |
798 * The simproc skips multiple updates at once, eg: |
811 * The simproc skips multiple updates at once, eg: |
822 val rv = mk_abs_var "r" r |
835 val rv = mk_abs_var "r" r |
823 val rb = Bound 0 |
836 val rb = Bound 0 |
824 val kv = mk_abs_var "k" k |
837 val kv = mk_abs_var "k" k |
825 val kb = Bound 1 |
838 val kb = Bound 1 |
826 in Some (upd$kb$rb,kb,[kv,rv],true) end |
839 in Some (upd$kb$rb,kb,[kv,rv],true) end |
827 else if u_name mem (get_fields extfields rangeS) |
840 else if u_name mem (map fst (get_fields extfields rangeS)) |
828 orelse s mem (get_fields extfields updT) |
841 orelse s mem (map fst (get_fields extfields updT)) |
829 then None |
842 then None |
830 else (case mk_eq_terms r of |
843 else (case mk_eq_terms r of |
831 Some (trm,trm',vars,update_s) |
844 Some (trm,trm',vars,update_s) |
832 => let |
845 => let |
833 val kv = mk_abs_var "k" k |
846 val kv = mk_abs_var "k" k |
873 |
886 |
874 fun mk_abs_var x t = (x, fastype_of t); |
887 fun mk_abs_var x t = (x, fastype_of t); |
875 fun sel_name u = NameSpace.base (unsuffix updateN u); |
888 fun sel_name u = NameSpace.base (unsuffix updateN u); |
876 |
889 |
877 fun seed s (upd as Const (more,Type(_,[mT,_]))$ k $ r) = |
890 fun seed s (upd as Const (more,Type(_,[mT,_]))$ k $ r) = |
878 if s mem (get_fields extfields mT) then upd else seed s r |
891 if s mem (map fst (get_fields extfields mT)) then upd else seed s r |
879 | seed _ r = r; |
892 | seed _ r = r; |
880 |
893 |
881 fun grow u uT k vars (sprout,skeleton) = |
894 fun grow u uT k vars (sprout,skeleton) = |
882 if sel_name u = moreN |
895 if sel_name u = moreN |
883 then let val kv = mk_abs_var "k" k; |
896 then let val kv = mk_abs_var "k" k; |
959 => Some (prove_split_simp sg T |
972 => Some (prove_split_simp sg T |
960 (list_all(vars,(Logic.mk_equals (trm,trm'))))) |
973 (list_all(vars,(Logic.mk_equals (trm,trm'))))) |
961 | _ => None) |
974 | _ => None) |
962 end |
975 end |
963 | _ => None)); |
976 | _ => None)); |
964 end |
|
965 |
977 |
966 (* record_eq_simproc *) |
978 (* record_eq_simproc *) |
967 (* looks up the most specific record-equality. |
979 (* looks up the most specific record-equality. |
968 * Note on efficiency: |
980 * Note on efficiency: |
969 * Testing equality of records boils down to the test of equality of all components. |
981 * Testing equality of records boils down to the test of equality of all components. |
1427 val all_variants = parent_variants @ variants; |
1439 val all_variants = parent_variants @ variants; |
1428 val all_vars = parent_vars @ vars; |
1440 val all_vars = parent_vars @ vars; |
1429 val all_named_vars = (parent_names ~~ parent_vars) @ named_vars; |
1441 val all_named_vars = (parent_names ~~ parent_vars) @ named_vars; |
1430 |
1442 |
1431 |
1443 |
1432 val zeta = variant alphas "'z"; |
1444 val zeta = variant alphas "'z"; |
1433 val moreT = TFree (zeta, HOLogic.typeS); |
1445 val moreT = TFree (zeta, HOLogic.typeS); |
1434 val more = Free (moreN, moreT); |
1446 val more = Free (moreN, moreT); |
1435 val full_moreN = full moreN; |
1447 val full_moreN = full moreN; |
1436 val bfields_more = bfields @ [(moreN,moreT)]; |
1448 val bfields_more = bfields @ [(moreN,moreT)]; |
1437 val fields_more = fields @ [(full_moreN,moreT)]; |
1449 val fields_more = fields @ [(full_moreN,moreT)]; |