12 val DEADID_bnf: BNF_Def.bnf |
12 val DEADID_bnf: BNF_Def.bnf |
13 |
13 |
14 type unfold_set |
14 type unfold_set |
15 val empty_unfolds: unfold_set |
15 val empty_unfolds: unfold_set |
16 |
16 |
|
17 exception BAD_DEAD of typ * typ |
|
18 |
17 val bnf_of_typ: BNF_Def.const_policy -> (binding -> binding) -> |
19 val bnf_of_typ: BNF_Def.const_policy -> (binding -> binding) -> |
18 ((string * sort) list list -> (string * sort) list) -> typ -> unfold_set * Proof.context -> |
20 ((string * sort) list list -> (string * sort) list) -> (string * sort) list -> typ -> |
|
21 unfold_set * Proof.context -> |
19 (BNF_Def.bnf * (typ list * typ list)) * (unfold_set * Proof.context) |
22 (BNF_Def.bnf * (typ list * typ list)) * (unfold_set * Proof.context) |
20 val default_comp_sort: (string * sort) list list -> (string * sort) list |
23 val default_comp_sort: (string * sort) list list -> (string * sort) list |
21 val normalize_bnfs: (int -> binding -> binding) -> ''a list list -> ''a list -> |
24 val normalize_bnfs: (int -> binding -> binding) -> ''a list list -> ''a list -> |
22 (''a list list -> ''a list) -> BNF_Def.bnf list -> unfold_set -> Proof.context -> |
25 (''a list list -> ''a list) -> BNF_Def.bnf list -> unfold_set -> Proof.context -> |
23 (int list list * ''a list) * (BNF_Def.bnf list * (unfold_set * Proof.context)) |
26 (int list list * ''a list) * (BNF_Def.bnf list * (unfold_set * Proof.context)) |
643 (((((b, bnf_map), bnf_sets), Term.absdummy T bnf_bd'), bnf_wits), SOME bnf_rel) lthy; |
646 (((((b, bnf_map), bnf_sets), Term.absdummy T bnf_bd'), bnf_wits), SOME bnf_rel) lthy; |
644 in |
647 in |
645 ((bnf', deads), lthy') |
648 ((bnf', deads), lthy') |
646 end; |
649 end; |
647 |
650 |
648 fun bnf_of_typ _ _ _ (T as TFree _) accum = ((ID_bnf, ([], [T])), accum) |
651 exception BAD_DEAD of typ * typ; |
649 | bnf_of_typ _ _ _ (TVar _) _ = error "Unexpected schematic variable" |
652 |
650 | bnf_of_typ const_policy qualify' sort (T as Type (C, Ts)) (unfold_set, lthy) = |
653 fun bnf_of_typ _ _ _ _ (T as TFree _) accum = ((ID_bnf, ([], [T])), accum) |
|
654 | bnf_of_typ _ _ _ _ (TVar _) _ = error "Unexpected schematic variable" |
|
655 | bnf_of_typ const_policy qualify' sort Xs (T as Type (C, Ts)) (unfold_set, lthy) = |
651 let |
656 let |
|
657 fun check_bad_dead ((_, (deads, _)), _) = |
|
658 let val Ds = fold Term.add_tfreesT deads [] in |
|
659 (case Library.inter (op =) Ds Xs of [] => () |
|
660 | X :: _ => raise BAD_DEAD (TFree X, T)) |
|
661 end; |
|
662 |
652 val tfrees = Term.add_tfreesT T []; |
663 val tfrees = Term.add_tfreesT T []; |
653 val bnf_opt = if null tfrees then NONE else bnf_of lthy C; |
664 val bnf_opt = if null tfrees then NONE else bnf_of lthy C; |
654 in |
665 in |
655 (case bnf_opt of |
666 (case bnf_opt of |
656 NONE => ((DEADID_bnf, ([T], [])), (unfold_set, lthy)) |
667 NONE => ((DEADID_bnf, ([T], [])), (unfold_set, lthy)) |
677 (mk_T_of_bnf (replicate odead (TFree ("dead", []))) (replicate olive dummyT) bnf))); |
688 (mk_T_of_bnf (replicate odead (TFree ("dead", []))) (replicate olive dummyT) bnf))); |
678 val oDs = map (nth Ts) oDs_pos; |
689 val oDs = map (nth Ts) oDs_pos; |
679 val Ts' = map (nth Ts) (subtract (op =) oDs_pos (0 upto length Ts - 1)); |
690 val Ts' = map (nth Ts) (subtract (op =) oDs_pos (0 upto length Ts - 1)); |
680 val ((inners, (Dss, Ass)), (unfold_set', lthy')) = |
691 val ((inners, (Dss, Ass)), (unfold_set', lthy')) = |
681 apfst (apsnd split_list o split_list) |
692 apfst (apsnd split_list o split_list) |
682 (fold_map2 (fn i => bnf_of_typ Smart_Inline (qualify i) sort) |
693 (fold_map2 (fn i => bnf_of_typ Smart_Inline (qualify i) sort Xs) |
683 (if length Ts' = 1 then [0] else (1 upto length Ts')) Ts' (unfold_set, lthy)); |
694 (if length Ts' = 1 then [0] else (1 upto length Ts')) Ts' (unfold_set, lthy)); |
684 in |
695 in |
685 compose_bnf const_policy qualify sort bnf inners oDs Dss Ass (unfold_set', lthy') |
696 compose_bnf const_policy qualify sort bnf inners oDs Dss Ass (unfold_set', lthy') |
686 end) |
697 end) |
|
698 |> tap check_bad_dead |
687 end; |
699 end; |
688 |
700 |
689 end; |
701 end; |