src/Pure/theory.ML
changeset 15703 727ef1b8b3ee
parent 15570 8d8c70b41bab
child 15716 1291a8f2ccb1
equal deleted inserted replaced
15702:2677db44c795 15703:727ef1b8b3ee
   538 
   538 
   539 
   539 
   540 
   540 
   541 (** merge theories **)          (*exception ERROR*)
   541 (** merge theories **)          (*exception ERROR*)
   542 
   542 
   543 fun merge_sign (sg, thy) =
       
   544   Sign.nontriv_merge (sg, sign_of thy) handle TERM (msg, _) => error msg;
       
   545 
       
   546 (*merge list of theories from left to right, preparing extend*)
   543 (*merge list of theories from left to right, preparing extend*)
   547 fun prep_ext_merge thys =
   544 fun prep_ext_merge thys =
   548   if null thys then
   545   let
   549     error "Merge: no parent theories"
   546     val sign' = Sign.prep_ext_merge (map sign_of thys)
   550   else if exists is_draft thys then
   547 
   551     error "Attempt to merge draft theories"
   548     val depss = map (#const_deps o rep_theory) thys;
   552   else
   549     val deps' = Library.foldl (Graph.merge_acyclic (K true)) (hd depss, tl depss)
   553     let
   550       handle Graph.CYCLES namess => error (cycle_msg namess);
   554       val sign' =
   551 
   555         Library.foldl merge_sign (sign_of (hd thys), tl thys)
   552     val final_constss = map (#final_consts o rep_theory) thys;
   556         |> Sign.prep_ext
   553     val final_consts' =
   557         |> Sign.add_path "/";
   554       Library.foldl (Symtab.join (merge_final sign')) (hd final_constss, tl final_constss);
   558 
   555     val axioms' = Symtab.empty;
   559       val depss = map (#const_deps o rep_theory) thys;
   556 
   560       val deps' = Library.foldl (Graph.merge_acyclic (K true)) (hd depss, tl depss)
   557     fun eq_ora ((_, (_, s1: stamp)), (_, (_, s2))) = s1 = s2;
   561         handle Graph.CYCLES namess => error (cycle_msg namess);
   558     val oracles' =
   562 
   559       Symtab.make (gen_distinct eq_ora
   563       val final_constss = map (#final_consts o rep_theory) thys;
   560         (List.concat (map (Symtab.dest o #oracles o rep_theory) thys)))
   564       val final_consts' = Library.foldl (Symtab.join (merge_final sign')) (hd final_constss,
   561       handle Symtab.DUPS names => err_dup_oras names;
   565 								   tl final_constss);
   562 
   566       val axioms' = Symtab.empty;
   563     val parents' = gen_distinct eq_thy thys;
   567 
   564     val ancestors' =
   568       fun eq_ora ((_, (_, s1: stamp)), (_, (_, s2))) = s1 = s2;
   565       gen_distinct eq_thy (parents' @ List.concat (map ancestors_of thys));
   569       val oracles' =
   566   in
   570         Symtab.make (gen_distinct eq_ora
   567     make_theory sign' deps' final_consts' axioms' oracles' parents' ancestors'
   571           (List.concat (map (Symtab.dest o #oracles o rep_theory) thys)))
   568   end;
   572         handle Symtab.DUPS names => err_dup_oras names;
       
   573 
       
   574       val parents' = gen_distinct eq_thy thys;
       
   575       val ancestors' =
       
   576         gen_distinct eq_thy (parents' @ List.concat (map ancestors_of thys));
       
   577     in
       
   578       make_theory sign' deps' final_consts' axioms' oracles' parents' ancestors'
       
   579     end;
       
   580 
   569 
   581 
   570 
   582 end;
   571 end;
   583 
   572 
   584 structure BasicTheory: BASIC_THEORY = Theory;
   573 structure BasicTheory: BASIC_THEORY = Theory;