src/HOL/Tools/BNF/bnf_fp_util.ML
changeset 59860 a979fc5db526
parent 59856 ed0ca9029021
parent 59859 f9d1442c70f3
child 59873 2d929c178283
equal deleted inserted replaced
59856:ed0ca9029021 59860:a979fc5db526
   627 
   627 
   628     fun flatten_tyargs Ass =
   628     fun flatten_tyargs Ass =
   629       subtract (op =) Xs (filter (fn T => exists (fn Ts => member (op =) Ts T) Ass) resBs) @ Xs;
   629       subtract (op =) Xs (filter (fn T => exists (fn Ts => member (op =) Ts T) Ass) resBs) @ Xs;
   630 
   630 
   631     fun raw_qualify base_b =
   631     fun raw_qualify base_b =
   632       let val (_, qs, n) = Binding.dest base_b;
   632       let
       
   633         val qs = Binding.path_of base_b;
       
   634         val n = Binding.name_of base_b;
   633       in
   635       in
   634         Binding.prefix_name rawN
   636         Binding.prefix_name rawN
   635         #> fold_rev (fn (s, mand) => Binding.qualify mand s) (qs @ [(n, true)])
   637         #> fold_rev (fn (s, mand) => Binding.qualify mand s) (qs @ [(n, true)])
   636         #> Binding.conceal
   638         #> Binding.concealed
   637       end;
   639       end;
   638 
   640 
   639     val ((bnfs, (deadss, livess)), accum) =
   641     val ((bnfs, (deadss, livess)), accum) =
   640       apfst (apsnd split_list o split_list)
   642       apfst (apsnd split_list o split_list)
   641         (@{fold_map 2}
   643         (@{fold_map 2}
   642           (fn b => bnf_of_typ Smart_Inline (raw_qualify b) flatten_tyargs Xs Ds0) bs rhsXs
   644           (fn b => bnf_of_typ Smart_Inline (raw_qualify b) flatten_tyargs Xs Ds0) bs rhsXs
   643           ((empty_comp_cache, empty_unfolds), lthy));
   645           ((empty_comp_cache, empty_unfolds), lthy));
   644 
   646 
   645     fun norm_qualify i = Binding.qualify true (Binding.name_of (nth bs (Int.max (0, i - 1))))
   647     fun norm_qualify i = Binding.qualify true (Binding.name_of (nth bs (Int.max (0, i - 1))))
   646       #> Binding.conceal;
   648       #> Binding.concealed;
   647 
   649 
   648     val Ass = map (map dest_TFree) livess;
   650     val Ass = map (map dest_TFree) livess;
   649     val Ds' = fold (fold Term.add_tfreesT) deadss [];
   651     val Ds' = fold (fold Term.add_tfreesT) deadss [];
   650     val Ds = union (op =) Ds' Ds0;
   652     val Ds = union (op =) Ds' Ds0;
   651     val missing = resBs |> fold (subtract (op =)) (Ds' :: Ass);
   653     val missing = resBs |> fold (subtract (op =)) (Ds' :: Ass);
   658       normalize_bnfs norm_qualify Ass Ds (K (resBs' @ Xs)) bnfs accum;
   660       normalize_bnfs norm_qualify Ass Ds (K (resBs' @ Xs)) bnfs accum;
   659 
   661 
   660     val Dss = @{map 3} (uncurry append oo curry swap oo map o nth) livess kill_poss deadss;
   662     val Dss = @{map 3} (uncurry append oo curry swap oo map o nth) livess kill_poss deadss;
   661 
   663 
   662     fun pre_qualify b = Binding.qualify false (Binding.name_of b)
   664     fun pre_qualify b = Binding.qualify false (Binding.name_of b)
   663       #> not (Config.get lthy' bnf_note_all) ? Binding.conceal;
   665       #> not (Config.get lthy' bnf_note_all) ? Binding.concealed;
   664 
   666 
   665     val ((pre_bnfs, (deadss, absT_infos)), lthy'') =
   667     val ((pre_bnfs, (deadss, absT_infos)), lthy'') =
   666       @{fold_map 4} (fn b => seal_bnf (pre_qualify b) unfold_set' (Binding.prefix_name preN b))
   668       @{fold_map 4} (fn b => seal_bnf (pre_qualify b) unfold_set' (Binding.prefix_name preN b))
   667         bs (not (null live_phantoms) :: replicate (nn - 1) false) Dss bnfs' lthy'
   669         bs (not (null live_phantoms) :: replicate (nn - 1) false) Dss bnfs' lthy'
   668       |>> split_list
   670       |>> split_list