Move towards standard functions.
authorskalberg
Thu Mar 03 12:43:01 2005 +0100 (2005-03-03 ago)
changeset 155708d8c70b41bab
parent 15569 1b3115d1a8df
child 15571 c166086feace
Move towards standard functions.
NEWS
TFL/casesplit.ML
TFL/post.ML
TFL/rules.ML
TFL/tfl.ML
TFL/thry.ML
src/CCL/CCL.ML
src/CCL/typecheck.ML
src/CTT/CTT.ML
src/FOL/IFOL_lemmas.ML
src/FOL/eqrule_FOL_data.ML
src/FOL/intprover.ML
src/FOL/simpdata.ML
src/FOLP/IFOLP.ML
src/FOLP/classical.ML
src/FOLP/intprover.ML
src/FOLP/simp.ML
src/FOLP/simpdata.ML
src/HOL/Algebra/ringsimp.ML
src/HOL/Bali/Basis.thy
src/HOL/HOL.thy
src/HOL/Import/hol4rews.ML
src/HOL/Import/import_syntax.ML
src/HOL/Import/proof_kernel.ML
src/HOL/Import/replay.ML
src/HOL/Import/shuffler.ML
src/HOL/Integ/cooper_dec.ML
src/HOL/Integ/presburger.ML
src/HOL/IsaMakefile
src/HOL/Lambda/WeakNorm.thy
src/HOL/Library/EfficientNat.thy
src/HOL/List.thy
src/HOL/Matrix/Cplex.ML
src/HOL/Matrix/CplexMatrixConverter.ML
src/HOL/Matrix/codegen_prep.ML
src/HOL/Matrix/eq_codegen.ML
src/HOL/Matrix/fspmlp.ML
src/HOL/MicroJava/BV/BVExample.thy
src/HOL/Modelcheck/EindhovenSyn.ML
src/HOL/Modelcheck/MuckeSyn.ML
src/HOL/Modelcheck/mucke_oracle.ML
src/HOL/Product_Type.thy
src/HOL/Prolog/HOHH.ML
src/HOL/Tools/Presburger/cooper_dec.ML
src/HOL/Tools/Presburger/presburger.ML
src/HOL/Tools/datatype_abs_proofs.ML
src/HOL/Tools/datatype_aux.ML
src/HOL/Tools/datatype_codegen.ML
src/HOL/Tools/datatype_package.ML
src/HOL/Tools/datatype_prop.ML
src/HOL/Tools/datatype_realizer.ML
src/HOL/Tools/datatype_rep_proofs.ML
src/HOL/Tools/inductive_codegen.ML
src/HOL/Tools/inductive_package.ML
src/HOL/Tools/inductive_realizer.ML
src/HOL/Tools/meson.ML
src/HOL/Tools/primrec_package.ML
src/HOL/Tools/prop_logic.ML
src/HOL/Tools/recdef_package.ML
src/HOL/Tools/recfun_codegen.ML
src/HOL/Tools/record_package.ML
src/HOL/Tools/refute.ML
src/HOL/Tools/refute_isar.ML
src/HOL/Tools/rewrite_hol_proof.ML
src/HOL/Tools/sat_solver.ML
src/HOL/Tools/specification_package.ML
src/HOL/Tools/split_rule.ML
src/HOL/Tools/typedef_package.ML
src/HOL/arith_data.ML
src/HOL/cladata.ML
src/HOL/eqrule_HOL_data.ML
src/HOL/ex/svc_funcs.ML
src/HOL/hologic.ML
src/HOL/simpdata.ML
src/HOL/thy_syntax.ML
src/HOLCF/IOA/Modelcheck/MuIOAOracle.ML
src/HOLCF/IOA/meta_theory/Sequence.ML
src/HOLCF/adm.ML
src/HOLCF/cont_consts.ML
src/HOLCF/domain/axioms.ML
src/HOLCF/domain/extender.ML
src/HOLCF/domain/interface.ML
src/HOLCF/domain/library.ML
src/HOLCF/domain/syntax.ML
src/HOLCF/domain/theorems.ML
src/Provers/Arith/abel_cancel.ML
src/Provers/Arith/cancel_numeral_factor.ML
src/Provers/Arith/cancel_numerals.ML
src/Provers/Arith/combine_numerals.ML
src/Provers/Arith/extract_common_term.ML
src/Provers/Arith/fast_lin_arith.ML
src/Provers/blast.ML
src/Provers/clasimp.ML
src/Provers/classical.ML
src/Provers/ind.ML
src/Provers/induct_method.ML
src/Provers/make_elim.ML
src/Provers/order.ML
src/Provers/quasi.ML
src/Provers/simp.ML
src/Provers/splitter.ML
src/Provers/trancl.ML
src/Provers/typedsimp.ML
src/Pure/General/file.ML
src/Pure/General/graph.ML
src/Pure/General/history.ML
src/Pure/General/lazy_seq.ML
src/Pure/General/name_space.ML
src/Pure/General/path.ML
src/Pure/General/pretty.ML
src/Pure/General/scan.ML
src/Pure/General/seq.ML
src/Pure/General/symbol.ML
src/Pure/General/table.ML
src/Pure/General/xml.ML
src/Pure/IsaPlanner/isand.ML
src/Pure/IsaPlanner/isaplib.ML
src/Pure/IsaPlanner/rw_inst.ML
src/Pure/IsaPlanner/rw_tools.ML
src/Pure/IsaPlanner/term_lib.ML
src/Pure/Isar/args.ML
src/Pure/Isar/attrib.ML
src/Pure/Isar/calculation.ML
src/Pure/Isar/constdefs.ML
src/Pure/Isar/context_rules.ML
src/Pure/Isar/induct_attrib.ML
src/Pure/Isar/isar_output.ML
src/Pure/Isar/isar_syn.ML
src/Pure/Isar/isar_thy.ML
src/Pure/Isar/locale.ML
src/Pure/Isar/method.ML
src/Pure/Isar/net_rules.ML
src/Pure/Isar/object_logic.ML
src/Pure/Isar/obtain.ML
src/Pure/Isar/outer_parse.ML
src/Pure/Isar/outer_syntax.ML
src/Pure/Isar/proof.ML
src/Pure/Isar/proof_context.ML
src/Pure/Isar/rule_cases.ML
src/Pure/Isar/session.ML
src/Pure/Isar/toplevel.ML
src/Pure/Proof/extraction.ML
src/Pure/Proof/proof_rewrite_rules.ML
src/Pure/Proof/proof_syntax.ML
src/Pure/Proof/proofchecker.ML
src/Pure/Proof/reconstruct.ML
src/Pure/Syntax/ast.ML
src/Pure/Syntax/lexicon.ML
src/Pure/Syntax/mixfix.ML
src/Pure/Syntax/parser.ML
src/Pure/Syntax/printer.ML
src/Pure/Syntax/syn_ext.ML
src/Pure/Syntax/syn_trans.ML
src/Pure/Syntax/syntax.ML
src/Pure/Thy/present.ML
src/Pure/Thy/thm_deps.ML
src/Pure/Thy/thy_info.ML
src/Pure/Thy/thy_load.ML
src/Pure/Thy/thy_parse.ML
src/Pure/Thy/thy_scan.ML
src/Pure/axclass.ML
src/Pure/codegen.ML
src/Pure/display.ML
src/Pure/drule.ML
src/Pure/envir.ML
src/Pure/fact_index.ML
src/Pure/goals.ML
src/Pure/library.ML
src/Pure/meta_simplifier.ML
src/Pure/net.ML
src/Pure/pattern.ML
src/Pure/proof_general.ML
src/Pure/proofterm.ML
src/Pure/pure_thy.ML
src/Pure/search.ML
src/Pure/sign.ML
src/Pure/sorts.ML
src/Pure/tactic.ML
src/Pure/tctical.ML
src/Pure/term.ML
src/Pure/theory.ML
src/Pure/thm.ML
src/Pure/type.ML
src/Pure/type_infer.ML
src/Pure/unify.ML
src/ZF/Datatype.ML
src/ZF/Tools/cartprod.ML
src/ZF/Tools/datatype_package.ML
src/ZF/Tools/induct_tacs.ML
src/ZF/Tools/inductive_package.ML
src/ZF/Tools/primrec_package.ML
src/ZF/Tools/typechk.ML
src/ZF/arith_data.ML
src/ZF/ind_syntax.ML
src/ZF/simpdata.ML
src/ZF/thy_syntax.ML
     1.1 --- a/NEWS	Thu Mar 03 09:22:35 2005 +0100
     1.2 +++ b/NEWS	Thu Mar 03 12:43:01 2005 +0100
     1.3 @@ -10,6 +10,37 @@
     1.4    Library.OPTION: Isabelle now uses the standard option type.  The
     1.5    functions the, is_some, is_none, etc. are still in Library, but
     1.6    the constructors are now SOME and NONE instead of Some and None.
     1.7 +  They throw the exception Option.
     1.8 +
     1.9 +* The exception LIST is no more, the standard exceptions Empty and
    1.10 +  Subscript, as well as Library.UnequalLengths are used instead.  This
    1.11 +  means that function like Library.hd and Library.tl are gone, as the
    1.12 +  standard hd and tl functions suffice.
    1.13 +
    1.14 +  A number of functions, specifically those in the LIBRARY_CLOSED
    1.15 +  signature, are now no longer exported to the top ML level, as they
    1.16 +  are variants of standard functions.  The following suggests how
    1.17 +  one can translate existing code:
    1.18 +
    1.19 +    the x = valOf x
    1.20 +    if_none x y = getOpt(x,y)
    1.21 +    is_some x = isSome x
    1.22 +    apsome f x = Option.map f x
    1.23 +    rev_append xs ys = List.revAppend(xs,ys)
    1.24 +    nth_elem(i,xs) = List.nth(xs,i)
    1.25 +    last_elem xs = List.last xs
    1.26 +    flat xss = List.concat xss
    1.27 +    seq fs = app fs
    1.28 +    partition P xs = List.partition P xs
    1.29 +    filter P xs = List.filter P xs
    1.30 +    mapfilter f xs = List.mapPartial f xs
    1.31 +
    1.32 +  The final four functions, take, drop, foldl, and foldr, are somewhat
    1.33 +  more complicated (especially the semantics of take and drop differ
    1.34 +  from the standard).
    1.35 +
    1.36 +  A simple solution to broken code is to include "open Library" at the
    1.37 +  beginning of a structure.  Everything after that will be as before.
    1.38  
    1.39  * Document preparation: new antiquotations @{lhs thm} and @{rhs thm}
    1.40    printing the lhs/rhs of definitions, equations, inequations etc. 
     2.1 --- a/TFL/casesplit.ML	Thu Mar 03 09:22:35 2005 +0100
     2.2 +++ b/TFL/casesplit.ML	Thu Mar 03 12:43:01 2005 +0100
     2.3 @@ -207,7 +207,7 @@
     2.4            let val (n,ty) = Term.dest_Free x in 
     2.5              (if vstr = n orelse vstr = Syntax.dest_skolem n 
     2.6               then SOME (n,ty) else NONE )
     2.7 -            handle LIST _ => NONE
     2.8 +            handle Fail _ => NONE (* dest_skolem *)
     2.9            end;
    2.10        val (n,ty) = case Library.get_first getter freets 
    2.11                  of SOME (n, ty) => (n, ty)
    2.12 @@ -311,7 +311,7 @@
    2.13                raise ERROR_MESSAGE "splitto: cannot find variable to split on")
    2.14              | SOME v => 
    2.15               let 
    2.16 -               val gt = Data.dest_Trueprop (nth_elem(0, Thm.prems_of th));
    2.17 +               val gt = Data.dest_Trueprop (List.nth(Thm.prems_of th, 0));
    2.18                 val split_thm = mk_casesplit_goal_thm sgn v gt;
    2.19                 val (subthms, expf) = IsaND.fixed_subgoal_thms split_thm;
    2.20               in 
    2.21 @@ -340,7 +340,7 @@
    2.22     the well-foundness conditions have been solved. *)
    2.23  local
    2.24    fun get_related_thms i = 
    2.25 -      mapfilter ((fn (r,x) => if x = i then SOME r else NONE));
    2.26 +      List.mapPartial ((fn (r,x) => if x = i then SOME r else NONE));
    2.27        
    2.28    fun solve_eq (th, [], i) = 
    2.29        raise ERROR_MESSAGE "derive_init_eqs: missing rules"
     3.1 --- a/TFL/post.ML	Thu Mar 03 09:22:35 2005 +0100
     3.2 +++ b/TFL/post.ML	Thu Mar 03 12:43:01 2005 +0100
     3.3 @@ -46,7 +46,7 @@
     3.4   *--------------------------------------------------------------------------*)
     3.5  fun termination_goals rules =
     3.6      map (#1 o Type.freeze_thaw o HOLogic.dest_Trueprop)
     3.7 -      (foldr (fn (th,A) => union_term (prems_of th, A)) (rules, []));
     3.8 +      (Library.foldr (fn (th,A) => union_term (prems_of th, A)) (rules, []));
     3.9  
    3.10  (*---------------------------------------------------------------------------
    3.11   * Finds the termination conditions in (highly massaged) definition and
    3.12 @@ -105,7 +105,7 @@
    3.13    |   _ => r RS P_imp_P_eq_True
    3.14  
    3.15  (*Is this the best way to invoke the simplifier??*)
    3.16 -fun rewrite L = rewrite_rule (map mk_meta_eq (filter(not o id_thm) L))
    3.17 +fun rewrite L = rewrite_rule (map mk_meta_eq (List.filter(not o id_thm) L))
    3.18  
    3.19  fun join_assums th =
    3.20    let val {sign,...} = rep_thm th
    3.21 @@ -207,7 +207,7 @@
    3.22  -- Lucas Dixon, Aug 2004 *)
    3.23  local
    3.24    fun get_related_thms i = 
    3.25 -      mapfilter ((fn (r,x) => if x = i then SOME r else NONE));
    3.26 +      List.mapPartial ((fn (r,x) => if x = i then SOME r else NONE));
    3.27  
    3.28    fun solve_eq (th, [], i) = 
    3.29        raise ERROR_MESSAGE "derive_init_eqs: missing rules"
    3.30 @@ -226,9 +226,9 @@
    3.31        val eqths = map (Thm.trivial o (Thm.cterm_of sgn) o HOLogic.mk_Trueprop) 
    3.32                        eqs
    3.33        fun countlist l = 
    3.34 -          (rev o snd o (foldl (fn ((i,L), e) => (i + 1,(e,i) :: L)))) ((0,[]), l)
    3.35 +          (rev o snd o (Library.foldl (fn ((i,L), e) => (i + 1,(e,i) :: L)))) ((0,[]), l)
    3.36      in
    3.37 -      flat (map (fn (e,i) => solve_eq (e, (get_related_thms i rules), i))
    3.38 +      List.concat (map (fn (e,i) => solve_eq (e, (get_related_thms i rules), i))
    3.39                  (countlist eqths))
    3.40      end;
    3.41  end;
     4.1 --- a/TFL/rules.ML	Thu Mar 03 09:22:35 2005 +0100
     4.2 +++ b/TFL/rules.ML	Thu Mar 03 12:43:01 2005 +0100
     4.3 @@ -133,7 +133,7 @@
     4.4  
     4.5  fun FILTER_DISCH_ALL P thm =
     4.6   let fun check tm = P (#t (Thm.rep_cterm tm))
     4.7 - in  foldr (fn (tm,th) => if check tm then DISCH tm th else th)
     4.8 + in  Library.foldr (fn (tm,th) => if check tm then DISCH tm th else th)
     4.9                (chyps thm, thm)
    4.10   end;
    4.11  
    4.12 @@ -658,7 +658,7 @@
    4.13    in (ants,get_lhs eq)
    4.14    end;
    4.15  
    4.16 -fun restricted t = is_some (S.find_term
    4.17 +fun restricted t = isSome (S.find_term
    4.18                              (fn (Const("Wellfounded_Recursion.cut",_)) =>true | _ => false)
    4.19                              t)
    4.20  
    4.21 @@ -785,7 +785,7 @@
    4.22                val dummy = print_cterms "TC:"
    4.23                                [cterm_of sign (HOLogic.mk_Trueprop TC)]
    4.24                val dummy = tc_list := (TC :: !tc_list)
    4.25 -              val nestedp = is_some (S.find_term is_func TC)
    4.26 +              val nestedp = isSome (S.find_term is_func TC)
    4.27                val dummy = if nestedp then say "nested" else say "not_nested"
    4.28                val dummy = term_ref := ([func,TC]@(!term_ref))
    4.29                val th' = if nestedp then raise RULES_ERR "solver" "nested function"
    4.30 @@ -808,7 +808,7 @@
    4.31        (prover names) (empty_ss addsimps [cut_lemma'] addeqcongs congs) ctm
    4.32      val th2 = equal_elim th1 th
    4.33   in
    4.34 - (th2, filter (not o restricted) (!tc_list))
    4.35 + (th2, List.filter (not o restricted) (!tc_list))
    4.36   end;
    4.37  
    4.38  
     5.1 --- a/TFL/tfl.ML	Thu Mar 03 09:22:35 2005 +0100
     5.2 +++ b/TFL/tfl.ML	Thu Mar 03 12:43:01 2005 +0100
     5.3 @@ -201,8 +201,8 @@
     5.4  fun mk_pat (c,l) =
     5.5    let val L = length (binder_types (type_of c))
     5.6        fun build (prfx,tag,plist) =
     5.7 -          let val args   = take (L,plist)
     5.8 -              and plist' = drop(L,plist)
     5.9 +          let val args   = Library.take (L,plist)
    5.10 +              and plist' = Library.drop(L,plist)
    5.11            in (prfx,tag,list_comb(c,args)::plist') end
    5.12    in map build l end;
    5.13  
    5.14 @@ -336,7 +336,7 @@
    5.15       val dummy = map (no_repeat_vars thy) pats
    5.16       val rows = ListPair.zip (map (fn x => ([]:term list,[x])) pats,
    5.17                                map (fn (t,i) => (t,(i,true))) (enumerate R))
    5.18 -     val names = foldr add_term_names (R,[])
    5.19 +     val names = Library.foldr add_term_names (R,[])
    5.20       val atype = type_of(hd pats)
    5.21       and aname = variant names "a"
    5.22       val a = Free(aname,atype)
    5.23 @@ -433,13 +433,13 @@
    5.24  end;
    5.25  
    5.26  
    5.27 -fun givens pats = map pat_of (filter given pats);
    5.28 +fun givens pats = map pat_of (List.filter given pats);
    5.29  
    5.30  fun post_definition meta_tflCongs (theory, (def, pats)) =
    5.31   let val tych = Thry.typecheck theory
    5.32       val f = #lhs(S.dest_eq(concl def))
    5.33       val corollary = R.MATCH_MP Thms.WFREC_COROLLARY def
    5.34 -     val pats' = filter given pats
    5.35 +     val pats' = List.filter given pats
    5.36       val given_pats = map pat_of pats'
    5.37       val rows = map row_of_pat pats'
    5.38       val WFR = #ant(S.dest_imp(concl corollary))
    5.39 @@ -499,7 +499,7 @@
    5.40       val tych = Thry.typecheck thy
    5.41       val WFREC_THM0 = R.ISPEC (tych functional) Thms.WFREC_COROLLARY
    5.42       val Const("All",_) $ Abs(Rname,Rtype,_) = concl WFREC_THM0
    5.43 -     val R = Free (variant (foldr add_term_names (eqns,[])) Rname,
    5.44 +     val R = Free (variant (Library.foldr add_term_names (eqns,[])) Rname,
    5.45                     Rtype)
    5.46       val WFREC_THM = R.ISPECL [tych R, tych g] WFREC_THM0
    5.47       val ([proto_def, WFR],_) = S.strip_imp(concl WFREC_THM)
    5.48 @@ -540,7 +540,7 @@
    5.49                         prths extractants;
    5.50                         ())
    5.51                   else ()
    5.52 -     val TCs = foldr (gen_union (op aconv)) (TCl, [])
    5.53 +     val TCs = Library.foldr (gen_union (op aconv)) (TCl, [])
    5.54       val full_rqt = WFR::TCs
    5.55       val R' = S.mk_select{Bvar=R1, Body=S.list_mk_conj full_rqt}
    5.56       val R'abs = S.rand R'
    5.57 @@ -622,7 +622,7 @@
    5.58    let val (qvars,body) = S.strip_exists tm
    5.59        val vlist = #2(S.strip_comb (S.rhs body))
    5.60        val plist = ListPair.zip (vlist, xlist)
    5.61 -      val args = map (fn qv => the (gen_assoc (op aconv) (plist, qv))) qvars
    5.62 +      val args = map (fn qv => valOf (gen_assoc (op aconv) (plist, qv))) qvars
    5.63                     handle Option => sys_error
    5.64                         "TFL fault [alpha_ex_unroll]: no correspondence"
    5.65        fun build ex      []   = []
    5.66 @@ -682,7 +682,7 @@
    5.67                                                 rows = map (expnd c) rows})
    5.68                             (U.zip3 new_formals groups constraints)
    5.69              val recursive_thms = map mk news
    5.70 -            val build_exists = foldr
    5.71 +            val build_exists = Library.foldr
    5.72                                  (fn((x,t), th) =>
    5.73                                   R.CHOOSE (tych x, R.ASSUME (tych t)) th)
    5.74              val thms' = ListPair.map build_exists (vexl, recursive_thms)
    5.75 @@ -698,7 +698,7 @@
    5.76   let val tych = Thry.typecheck thy
    5.77       val ty_info = Thry.induct_info thy
    5.78   in fn pats =>
    5.79 - let val names = foldr add_term_names (pats,[])
    5.80 + let val names = Library.foldr add_term_names (pats,[])
    5.81       val T = type_of (hd pats)
    5.82       val aname = Term.variant names "a"
    5.83       val vname = Term.variant (aname::names) "v"
    5.84 @@ -733,7 +733,7 @@
    5.85  in
    5.86  fun build_ih f P (pat,TCs) =
    5.87   let val globals = S.free_vars_lr pat
    5.88 -     fun nested tm = is_some (S.find_term (curry (op aconv) f) tm)
    5.89 +     fun nested tm = isSome (S.find_term (curry (op aconv) f) tm)
    5.90       fun dest_TC tm =
    5.91           let val (cntxt,R_y_pat) = S.strip_imp(#2(S.strip_forall tm))
    5.92               val (R,y,_) = S.dest_relation R_y_pat
    5.93 @@ -762,7 +762,7 @@
    5.94  fun build_ih f (P,SV) (pat,TCs) =
    5.95   let val pat_vars = S.free_vars_lr pat
    5.96       val globals = pat_vars@SV
    5.97 -     fun nested tm = is_some (S.find_term (curry (op aconv) f) tm)
    5.98 +     fun nested tm = isSome (S.find_term (curry (op aconv) f) tm)
    5.99       fun dest_TC tm =
   5.100           let val (cntxt,R_y_pat) = S.strip_imp(#2(S.strip_forall tm))
   5.101               val (R,y,_) = S.dest_relation R_y_pat
   5.102 @@ -795,7 +795,7 @@
   5.103   let val tych = Thry.typecheck thy
   5.104       val antc = tych(#ant(S.dest_imp tm))
   5.105       val thm' = R.SPEC_ALL thm
   5.106 -     fun nested tm = is_some (S.find_term (curry (op aconv) f) tm)
   5.107 +     fun nested tm = isSome (S.find_term (curry (op aconv) f) tm)
   5.108       fun get_cntxt TC = tych(#ant(S.dest_imp(#2(S.strip_forall(concl TC)))))
   5.109       fun mk_ih ((TC,locals),th2,nested) =
   5.110           R.GENL (map tych locals)
   5.111 @@ -832,7 +832,7 @@
   5.112          let val ex_tm = S.mk_exists{Bvar=v,Body=tm}
   5.113          in (ex_tm, R.CHOOSE(tych v, R.ASSUME (tych ex_tm)) thm)
   5.114          end
   5.115 -      val [veq] = filter (can S.dest_eq) (#1 (R.dest_thm thm))
   5.116 +      val [veq] = List.filter (can S.dest_eq) (#1 (R.dest_thm thm))
   5.117        val {lhs,rhs} = S.dest_eq veq
   5.118        val L = S.free_vars_lr rhs
   5.119    in  #2 (U.itlist CHOOSER L (veq,thm))  end;
   5.120 @@ -851,7 +851,7 @@
   5.121      val (pats,TCsl) = ListPair.unzip pat_TCs_list
   5.122      val case_thm = complete_cases thy pats
   5.123      val domain = (type_of o hd) pats
   5.124 -    val Pname = Term.variant (foldr (foldr add_term_names)
   5.125 +    val Pname = Term.variant (Library.foldr (Library.foldr add_term_names)
   5.126                                (pats::TCsl, [])) "P"
   5.127      val P = Free(Pname, domain --> HOLogic.boolT)
   5.128      val Sinduct = R.SPEC (tych P) Sinduction
   5.129 @@ -862,7 +862,7 @@
   5.130      val cases = map (fn pat => betapply (Sinduct_assumf, pat)) pats
   5.131      val tasks = U.zip3 cases TCl' (R.CONJUNCTS Rinduct_assum)
   5.132      val proved_cases = map (prove_case fconst thy) tasks
   5.133 -    val v = Free (variant (foldr add_term_names (map concl proved_cases, []))
   5.134 +    val v = Free (variant (Library.foldr add_term_names (map concl proved_cases, []))
   5.135                      "v",
   5.136                    domain)
   5.137      val vtyped = tych v
     6.1 --- a/TFL/thry.ML	Thu Mar 03 09:22:35 2005 +0100
     6.2 +++ b/TFL/thry.ML	Thu Mar 03 12:43:01 2005 +0100
     6.3 @@ -66,12 +66,12 @@
     6.4          NONE => NONE
     6.5        | SOME {nchotomy, ...} =>
     6.6            SOME {nchotomy = nchotomy,
     6.7 -                constructors = the (DatatypePackage.constrs_of thy tname)};
     6.8 +                constructors = valOf (DatatypePackage.constrs_of thy tname)};
     6.9  
    6.10  fun extract_info thy =
    6.11   let val infos = map snd (Symtab.dest (DatatypePackage.get_datatypes thy))
    6.12   in {case_congs = map (mk_meta_eq o #case_cong) infos,
    6.13 -     case_rewrites = flat (map (map mk_meta_eq o #case_rewrites) infos)}
    6.14 +     case_rewrites = List.concat (map (map mk_meta_eq o #case_rewrites) infos)}
    6.15   end;
    6.16  
    6.17  
     7.1 --- a/src/CCL/CCL.ML	Thu Mar 03 09:22:35 2005 +0100
     7.2 +++ b/src/CCL/CCL.ML	Thu Mar 03 12:43:01 2005 +0100
     7.3 @@ -59,7 +59,7 @@
     7.4  
     7.5  fun mk_inj_rl thy rews s = 
     7.6        let fun mk_inj_lemmas r = ([arg_cong] RL [(r RS (r RS eq_lemma))]);
     7.7 -          val inj_lemmas = flat (map mk_inj_lemmas rews);
     7.8 +          val inj_lemmas = List.concat (map mk_inj_lemmas rews);
     7.9            val tac = REPEAT (ares_tac [iffI,allI,conjI] 1 ORELSE
    7.10                              eresolve_tac inj_lemmas 1 ORELSE
    7.11                              asm_simp_tac (CCL_ss addsimps rews) 1)
    7.12 @@ -99,7 +99,7 @@
    7.13    fun mk_lemma (ra,rb) = [lemma] RL [ra RS (rb RS eq_lemma)] RL 
    7.14                             [distinctness RS notE,sym RS (distinctness RS notE)];
    7.15  in
    7.16 -  fun mk_lemmas rls = flat (map mk_lemma (mk_combs pair rls));
    7.17 +  fun mk_lemmas rls = List.concat (map mk_lemma (mk_combs pair rls));
    7.18    fun mk_dstnct_rls thy xs = mk_combs (mk_thm_str thy) xs;
    7.19  end;
    7.20  
    7.21 @@ -117,7 +117,7 @@
    7.22                                 (fn _ => [simp_tac (CCL_ss addsimps (rls@inj_rls)) 1])
    7.23            in map (mk_dstnct_thm ccl_dstncts) (mk_dstnct_rls thy xs) end;
    7.24  
    7.25 -fun mkall_dstnct_thms thy defs i_rls xss = flat (map (mk_dstnct_thms thy defs i_rls) xss);
    7.26 +fun mkall_dstnct_thms thy defs i_rls xss = List.concat (map (mk_dstnct_thms thy defs i_rls) xss);
    7.27  
    7.28  (*** Rewriting and Proving ***)
    7.29  
     8.1 --- a/src/CCL/typecheck.ML	Thu Mar 03 09:22:35 2005 +0100
     8.2 +++ b/src/CCL/typecheck.ML	Thu Mar 03 12:43:01 2005 +0100
     8.3 @@ -85,12 +85,12 @@
     8.4  
     8.5  fun IHinst tac rls = SUBGOAL (fn (Bi,i) =>
     8.6    let val bvs = bvars Bi [];
     8.7 -      val ihs = filter could_IH (Logic.strip_assums_hyp Bi);
     8.8 +      val ihs = List.filter could_IH (Logic.strip_assums_hyp Bi);
     8.9        val rnames = map (fn x=>
    8.10                      let val (a,b) = get_bno [] 0 x
    8.11 -                    in (nth_elem(a,bvs),b) end) ihs;
    8.12 +                    in (List.nth(bvs,a),b) end) ihs;
    8.13        fun try_IHs [] = no_tac
    8.14 -        | try_IHs ((x,y)::xs) = tac [("g",x)] (nth_elem(y-1,rls)) i ORELSE (try_IHs xs);
    8.15 +        | try_IHs ((x,y)::xs) = tac [("g",x)] (List.nth(rls,y-1)) i ORELSE (try_IHs xs);
    8.16    in try_IHs rnames end);
    8.17  
    8.18  (*****)
     9.1 --- a/src/CTT/CTT.ML	Thu Mar 03 09:22:35 2005 +0100
     9.2 +++ b/src/CTT/CTT.ML	Thu Mar 03 12:43:01 2005 +0100
     9.3 @@ -157,7 +157,7 @@
     9.4  
     9.5  (*0 subgoals vs 1 or more*)
     9.6  val (safe0_brls, safep_brls) =
     9.7 -    partition (apl(0,op=) o subgoals_of_brl) safe_brls;
     9.8 +    List.partition (apl(0,op=) o subgoals_of_brl) safe_brls;
     9.9  
    9.10  fun safestep_tac thms i =
    9.11      form_tac  ORELSE  
    10.1 --- a/src/FOL/IFOL_lemmas.ML	Thu Mar 03 09:22:35 2005 +0100
    10.2 +++ b/src/FOL/IFOL_lemmas.ML	Thu Mar 03 12:43:01 2005 +0100
    10.3 @@ -384,7 +384,7 @@
    10.4  (*special cases for free variables P, Q, R, S -- up to 3 arguments*)
    10.5  
    10.6  val pred_congs = 
    10.7 -    flat (map (fn c => 
    10.8 +    List.concat (map (fn c => 
    10.9                 map (fn th => read_instantiate [("P",c)] th)
   10.10                     [pred1_cong,pred2_cong,pred3_cong])
   10.11                 (explode"PQRS"));
    11.1 --- a/src/FOL/eqrule_FOL_data.ML	Thu Mar 03 09:22:35 2005 +0100
    11.2 +++ b/src/FOL/eqrule_FOL_data.ML	Thu Mar 03 12:43:01 2005 +0100
    11.3 @@ -37,14 +37,14 @@
    11.4               (case Term.head_of p of
    11.5                  Const(a,_) =>
    11.6                    (case Library.assoc(pairs,a) of
    11.7 -                     SOME(rls) => flat (map atoms ([th] RL rls))
    11.8 +                     SOME(rls) => List.concat (map atoms ([th] RL rls))
    11.9                     | NONE => [th])
   11.10                | _ => [th])
   11.11           | _ => [th])
   11.12    in atoms end;
   11.13  
   11.14  val prep_meta_eq = 
   11.15 -    (mapfilter  
   11.16 +    (List.mapPartial  
   11.17         mk_eq
   11.18         o (mk_atomize tranformation_pairs)
   11.19         o Drule.gen_all 
    12.1 --- a/src/FOL/intprover.ML	Thu Mar 03 09:22:35 2005 +0100
    12.2 +++ b/src/FOL/intprover.ML	Thu Mar 03 12:43:01 2005 +0100
    12.3 @@ -60,7 +60,7 @@
    12.4  
    12.5  (*0 subgoals vs 1 or more: the p in safep is for positive*)
    12.6  val (safe0_brls, safep_brls) =
    12.7 -    partition (apl(0,op=) o subgoals_of_brl) safe_brls;
    12.8 +    List.partition (apl(0,op=) o subgoals_of_brl) safe_brls;
    12.9  
   12.10  (*Attack subgoals using safe inferences -- matching, not resolution*)
   12.11  val safe_step_tac = FIRST' [eq_assume_tac,
    13.1 --- a/src/FOL/simpdata.ML	Thu Mar 03 09:22:35 2005 +0100
    13.2 +++ b/src/FOL/simpdata.ML	Thu Mar 03 12:43:01 2005 +0100
    13.3 @@ -116,7 +116,7 @@
    13.4               (case head_of p of
    13.5                  Const(a,_) =>
    13.6                    (case assoc(pairs,a) of
    13.7 -                     SOME(rls) => flat (map atoms ([th] RL rls))
    13.8 +                     SOME(rls) => List.concat (map atoms ([th] RL rls))
    13.9                     | NONE => [th])
   13.10                | _ => [th])
   13.11           | _ => [th])
    14.1 --- a/src/FOLP/IFOLP.ML	Thu Mar 03 09:22:35 2005 +0100
    14.2 +++ b/src/FOLP/IFOLP.ML	Thu Mar 03 12:43:01 2005 +0100
    14.3 @@ -78,7 +78,7 @@
    14.4            and concl = discard_proof (Logic.strip_assums_concl prem)
    14.5        in  
    14.6            if exists (fn hyp => hyp aconv concl) hyps
    14.7 -          then case distinct (filter (fn hyp=> could_unify(hyp,concl)) hyps) of
    14.8 +          then case distinct (List.filter (fn hyp=> could_unify(hyp,concl)) hyps) of
    14.9                     [_] => assume_tac i
   14.10                   |  _  => no_tac
   14.11            else no_tac
   14.12 @@ -310,7 +310,7 @@
   14.13  (*special cases for free variables P, Q, R, S -- up to 3 arguments*)
   14.14  
   14.15  val pred_congs = 
   14.16 -    flat (map (fn c => 
   14.17 +    List.concat (map (fn c => 
   14.18                 map (fn th => read_instantiate [("P",c)] th)
   14.19                     [pred1_cong,pred2_cong,pred3_cong])
   14.20                 (explode"PQRS"));
    15.1 --- a/src/FOLP/classical.ML	Thu Mar 03 09:22:35 2005 +0100
    15.2 +++ b/src/FOLP/classical.ML	Thu Mar 03 12:43:01 2005 +0100
    15.3 @@ -112,7 +112,7 @@
    15.4  (*Note that allE precedes exI in haz_brls*)
    15.5  fun make_cs {safeIs,safeEs,hazIs,hazEs} =
    15.6    let val (safe0_brls, safep_brls) = (*0 subgoals vs 1 or more*)
    15.7 -          partition (apl(0,op=) o subgoals_of_brl) 
    15.8 +          List.partition (apl(0,op=) o subgoals_of_brl) 
    15.9               (sort (make_ord lessb) (joinrules(safeIs, safeEs)))
   15.10    in CS{safeIs=safeIs, safeEs=safeEs, hazIs=hazIs, hazEs=hazEs,
   15.11          safe0_brls=safe0_brls, safep_brls=safep_brls,
    16.1 --- a/src/FOLP/intprover.ML	Thu Mar 03 09:22:35 2005 +0100
    16.2 +++ b/src/FOLP/intprover.ML	Thu Mar 03 12:43:01 2005 +0100
    16.3 @@ -50,7 +50,7 @@
    16.4  
    16.5  (*0 subgoals vs 1 or more: the p in safep is for positive*)
    16.6  val (safe0_brls, safep_brls) =
    16.7 -    partition (apl(0,op=) o subgoals_of_brl) safe_brls;
    16.8 +    List.partition (apl(0,op=) o subgoals_of_brl) safe_brls;
    16.9  
   16.10  (*Attack subgoals using safe inferences*)
   16.11  val safe_step_tac = FIRST' [uniq_assume_tac,
    17.1 --- a/src/FOLP/simp.ML	Thu Mar 03 09:22:35 2005 +0100
    17.2 +++ b/src/FOLP/simp.ML	Thu Mar 03 12:43:01 2005 +0100
    17.3 @@ -84,7 +84,7 @@
    17.4            biresolve_tac (Net.unify_term net
    17.5                         (lhs_of (strip_assums_concl prem))) i);
    17.6  
    17.7 -fun nth_subgoal i thm = nth_elem(i-1,prems_of thm);
    17.8 +fun nth_subgoal i thm = List.nth(prems_of thm,i-1);
    17.9  
   17.10  fun goal_concl i thm = strip_assums_concl(nth_subgoal i thm);
   17.11  
   17.12 @@ -161,7 +161,7 @@
   17.13                       in case f of
   17.14                              Const(c,T) => 
   17.15                                  if c mem ccs
   17.16 -                                then foldr add_hvars (args,hvars)
   17.17 +                                then Library.foldr add_hvars (args,hvars)
   17.18                                  else add_term_vars(tm,hvars)
   17.19                            | _ => add_term_vars(tm,hvars)
   17.20                       end
   17.21 @@ -173,7 +173,7 @@
   17.22                  if at then vars else add_term_vars(tm,vars)
   17.23          fun add_list(tm,al,vars) = let val (_,tml) = strip_comb tm
   17.24                  in if length(tml)=length(al)
   17.25 -                   then foldr itf (tml~~al,vars)
   17.26 +                   then Library.foldr itf (tml~~al,vars)
   17.27                     else vars
   17.28                  end
   17.29          fun add_vars (tm,vars) = case tm of
   17.30 @@ -194,12 +194,12 @@
   17.31      val lhs = rhs_of_eq 1 thm'
   17.32      val rhs = lhs_of_eq nops thm'
   17.33      val asms = tl(rev(tl(prems_of thm')))
   17.34 -    val hvars = foldr (add_hidden_vars ccs) (lhs::rhs::asms,[])
   17.35 +    val hvars = Library.foldr (add_hidden_vars ccs) (lhs::rhs::asms,[])
   17.36      val hvars = add_new_asm_vars new_asms (rhs,hvars)
   17.37      fun it_asms (asm,hvars) =
   17.38          if atomic asm then add_new_asm_vars new_asms (asm,hvars)
   17.39          else add_term_frees(asm,hvars)
   17.40 -    val hvars = foldr it_asms (asms,hvars)
   17.41 +    val hvars = Library.foldr it_asms (asms,hvars)
   17.42      val hvs = map (#1 o dest_Var) hvars
   17.43      val refl1_tac = refl_tac 1
   17.44      fun norm_step_tac st = st |>
   17.45 @@ -216,7 +216,7 @@
   17.46  
   17.47  fun add_norm_tags congs =
   17.48      let val ccs = map cong_const congs
   17.49 -        val new_asms = filter (exists not o #2)
   17.50 +        val new_asms = List.filter (exists not o #2)
   17.51                  (ccs ~~ (map (map atomic o prems_of) congs));
   17.52      in add_norms(congs,ccs,new_asms) end;
   17.53  
   17.54 @@ -252,7 +252,7 @@
   17.55      (writeln"\nDuplicate rewrite or congruence rule:"; print_thm th;
   17.56       net);
   17.57  
   17.58 -val insert_thms = foldr insert_thm_warn;
   17.59 +val insert_thms = Library.foldr insert_thm_warn;
   17.60  
   17.61  fun addrew(SS{auto_tac,congs,cong_net,mk_simps,simps,simp_net}, thm) =
   17.62  let val thms = mk_simps thm
   17.63 @@ -260,7 +260,7 @@
   17.64        simps = (thm,thms)::simps, simp_net = insert_thms(thms,simp_net)}
   17.65  end;
   17.66  
   17.67 -val op addrews = foldl addrew;
   17.68 +val op addrews = Library.foldl addrew;
   17.69  
   17.70  fun op addcongs(SS{auto_tac,congs,cong_net,mk_simps,simps,simp_net}, thms) =
   17.71  let val congs' = thms @ congs;
   17.72 @@ -278,10 +278,10 @@
   17.73      (writeln"\nNo such rewrite or congruence rule:";  print_thm th;
   17.74       net);
   17.75  
   17.76 -val delete_thms = foldr delete_thm_warn;
   17.77 +val delete_thms = Library.foldr delete_thm_warn;
   17.78  
   17.79  fun op delcongs(SS{auto_tac,congs,cong_net,mk_simps,simps,simp_net}, thms) =
   17.80 -let val congs' = foldl (gen_rem Drule.eq_thm_prop) (congs,thms)
   17.81 +let val congs' = Library.foldl (gen_rem Drule.eq_thm_prop) (congs,thms)
   17.82  in SS{auto_tac=auto_tac, congs= congs',
   17.83        cong_net= delete_thms(map mk_trans thms,cong_net),
   17.84        mk_simps= normed_rews congs', simps=simps, simp_net=simp_net}
   17.85 @@ -298,7 +298,7 @@
   17.86        simps = simps', simp_net = delete_thms(thms,simp_net)}
   17.87  end;
   17.88  
   17.89 -val op delrews = foldl delrew;
   17.90 +val op delrews = Library.foldl delrew;
   17.91  
   17.92  
   17.93  fun op setauto(SS{congs,cong_net,mk_simps,simps,simp_net,...}, auto_tac) =
   17.94 @@ -426,9 +426,9 @@
   17.95              SOME(thm',_) =>
   17.96                      let val ps = prems_of thm and ps' = prems_of thm';
   17.97                          val n = length(ps')-length(ps);
   17.98 -                        val a = length(strip_assums_hyp(nth_elem(i-1,ps)))
   17.99 +                        val a = length(strip_assums_hyp(List.nth(ps,i-1)))
  17.100                          val l = map (fn p => length(strip_assums_hyp(p)))
  17.101 -                                    (take(n,drop(i-1,ps')));
  17.102 +                                    (Library.take(n,Library.drop(i-1,ps')));
  17.103                      in (simp_refl(rev(l),a,REW::ss),thm',anet,ats,cs) end
  17.104            | NONE => (REW::ss,thm,anet,ats,cs);
  17.105  
  17.106 @@ -437,9 +437,9 @@
  17.107  fun add_asms(ss,thm,a,anet,ats,cs) =
  17.108      let val As = strip_varify(nth_subgoal i thm, a, []);
  17.109          val thms = map (trivial o cterm_of(#sign(rep_thm(thm))))As;
  17.110 -        val new_rws = flat(map mk_rew_rules thms);
  17.111 -        val rwrls = map mk_trans (flat(map mk_rew_rules thms));
  17.112 -        val anet' = foldr lhs_insert_thm (rwrls,anet)
  17.113 +        val new_rws = List.concat(map mk_rew_rules thms);
  17.114 +        val rwrls = map mk_trans (List.concat(map mk_rew_rules thms));
  17.115 +        val anet' = Library.foldr lhs_insert_thm (rwrls,anet)
  17.116      in  if !tracing andalso not(null new_rws)
  17.117          then (writeln"Adding rewrites:";  prths new_rws;  ())
  17.118          else ();
  17.119 @@ -539,7 +539,7 @@
  17.120  fun Pinst(f,fT,(eq,eqT),k,i,T,yik,Ts) =
  17.121  let fun xn_list(x,n) =
  17.122          let val ixs = map (fn i => (x^(radixstring(26,"a",i)),0)) (0 upto n);
  17.123 -        in ListPair.map eta_Var (ixs, take(n+1,Ts)) end
  17.124 +        in ListPair.map eta_Var (ixs, Library.take(n+1,Ts)) end
  17.125      val lhs = list_comb(f,xn_list("X",k-1))
  17.126      val rhs = list_comb(f,xn_list("X",i-1) @ [Bound 0] @ yik)
  17.127  in Abs("", T, Const(eq,[fT,fT]--->eqT) $ lhs $ rhs) end;
  17.128 @@ -596,7 +596,7 @@
  17.129      val T' = incr_tvar 9 T;
  17.130  in mk_cong_type sg (Const(f,T'),T') end;
  17.131  
  17.132 -fun mk_congs thy = flat o map (mk_cong_thy thy);
  17.133 +fun mk_congs thy = List.concat o map (mk_cong_thy thy);
  17.134  
  17.135  fun mk_typed_congs thy =
  17.136  let val sg = sign_of thy;
  17.137 @@ -606,7 +606,7 @@
  17.138              val t = case Sign.const_type sg f of
  17.139                        SOME(_) => Const(f,T) | NONE => Free(f,T)
  17.140          in (t,T) end
  17.141 -in flat o map (mk_cong_type sg o readfT) end;
  17.142 +in List.concat o map (mk_cong_type sg o readfT) end;
  17.143  
  17.144  end (* local *)
  17.145  end (* SIMP *);
    18.1 --- a/src/FOLP/simpdata.ML	Thu Mar 03 09:22:35 2005 +0100
    18.2 +++ b/src/FOLP/simpdata.ML	Thu Mar 03 12:43:01 2005 +0100
    18.3 @@ -85,7 +85,7 @@
    18.4               (case head_of p of
    18.5                  Const(a,_) =>
    18.6                    (case assoc(pairs,a) of
    18.7 -                     SOME(rls) => flat (map atoms ([th] RL rls))
    18.8 +                     SOME(rls) => List.concat (map atoms ([th] RL rls))
    18.9                     | NONE => [th])
   18.10                | _ => [th])
   18.11           | _ => [th])
    19.1 --- a/src/HOL/Algebra/ringsimp.ML	Thu Mar 03 09:22:35 2005 +0100
    19.2 +++ b/src/HOL/Algebra/ringsimp.ML	Thu Mar 03 12:43:01 2005 +0100
    19.3 @@ -74,17 +74,17 @@
    19.4        handle TERM _ => [];
    19.5  
    19.6      val prems = ProofContext.prems_of ctxt;
    19.7 -    val rings = flat (map (ring_filter o #prop o rep_thm) prems);
    19.8 -    val comms = flat (map (comm_filter o #prop o rep_thm) prems);
    19.9 +    val rings = List.concat (map (ring_filter o #prop o rep_thm) prems);
   19.10 +    val comms = List.concat (map (comm_filter o #prop o rep_thm) prems);
   19.11      val non_comm_rings = rings \\ comms;
   19.12      val comm_rings = rings inter_string comms;
   19.13      val _ = tracing
   19.14        ("Non-commutative rings in proof context: " ^ commas non_comm_rings ^
   19.15         "\nCommutative rings in proof context: " ^ commas comm_rings);
   19.16      val simps =
   19.17 -      flat (map (fn s => ProofContext.get_thms ctxt (s ^ ".ring_simprules", NONE))
   19.18 +      List.concat (map (fn s => ProofContext.get_thms ctxt (s ^ ".ring_simprules", NONE))
   19.19          non_comm_rings) @
   19.20 -      flat (map (fn s => ProofContext.get_thms ctxt (s ^ ".cring_simprules", NONE))
   19.21 +      List.concat (map (fn s => ProofContext.get_thms ctxt (s ^ ".cring_simprules", NONE))
   19.22          comm_rings);
   19.23    in Method.SIMPLE_METHOD' HEADGOAL (asm_full_simp_tac (cring_ss addsimps simps))
   19.24    end;
    20.1 --- a/src/HOL/Bali/Basis.thy	Thu Mar 03 09:22:35 2005 +0100
    20.2 +++ b/src/HOL/Bali/Basis.thy	Thu Mar 03 12:43:01 2005 +0100
    20.3 @@ -188,7 +188,7 @@
    20.4  (*###to be phased out *)
    20.5  ML {* 
    20.6  fun noAll_simpset () = simpset() setmksimps 
    20.7 -	mksimps (filter (fn (x,_) => x<>"All") mksimps_pairs)
    20.8 +	mksimps (List.filter (fn (x,_) => x<>"All") mksimps_pairs)
    20.9  *}
   20.10  
   20.11  lemma All_Ex_refl_eq2 [simp]: 
    21.1 --- a/src/HOL/HOL.thy	Thu Mar 03 09:22:35 2005 +0100
    21.2 +++ b/src/HOL/HOL.thy	Thu Mar 03 12:43:01 2005 +0100
    21.3 @@ -771,7 +771,7 @@
    21.4    fun wrong_prem (Const ("All", _) $ (Abs (_, _, t))) = wrong_prem t
    21.5    |   wrong_prem (Bound _) = true
    21.6    |   wrong_prem _ = false
    21.7 -  val filter_right = filter (fn t => not (wrong_prem (HOLogic.dest_Trueprop (hd (Thm.prems_of t)))))
    21.8 +  val filter_right = List.filter (fn t => not (wrong_prem (HOLogic.dest_Trueprop (hd (Thm.prems_of t)))))
    21.9  in
   21.10    fun smp i = funpow i (fn m => filter_right ([spec] RL m)) ([mp])
   21.11    fun smp_tac j = EVERY'[dresolve_tac (smp j), atac]
    22.1 --- a/src/HOL/Import/hol4rews.ML	Thu Mar 03 09:22:35 2005 +0100
    22.2 +++ b/src/HOL/Import/hol4rews.ML	Thu Mar 03 12:43:01 2005 +0100
    22.3 @@ -614,7 +614,7 @@
    22.4  	    then
    22.5  		let
    22.6  		    val paths = NameSpace.unpack isa
    22.7 -		    val i = drop(length paths - 2,paths)
    22.8 +		    val i = Library.drop(length paths - 2,paths)
    22.9  		in
   22.10  		    case i of
   22.11  			[seg,con] => output_thy ^ "." ^ seg ^ "." ^ con
    23.1 --- a/src/HOL/Import/import_syntax.ML	Thu Mar 03 09:22:35 2005 +0100
    23.2 +++ b/src/HOL/Import/import_syntax.ML	Thu Mar 03 12:43:01 2005 +0100
    23.3 @@ -49,7 +49,7 @@
    23.4  		val thyname = get_generating_thy thy
    23.5  		val segname = get_import_segment thy
    23.6  		val (int_thms,facts) = Replay.setup_int_thms thyname thy
    23.7 -		val thmnames = filter (not o should_ignore thyname thy) facts
    23.8 +		val thmnames = List.filter (not o should_ignore thyname thy) facts
    23.9  	    in
   23.10  		thy |> clear_import_thy
   23.11  		    |> set_segment thyname segname
   23.12 @@ -68,7 +68,7 @@
   23.13  				      let
   23.14  					  val thyname = get_import_thy thy
   23.15  				      in
   23.16 -					  foldl (fn (thy,thmname) => ignore_hol4 thyname thmname thy) (thy,ignored)
   23.17 +					  Library.foldl (fn (thy,thmname) => ignore_hol4 thyname thmname thy) (thy,ignored)
   23.18  				      end)
   23.19  
   23.20  val thm_maps = Scan.repeat1 (P.name --| P.$$$ ">" -- P.xname)
   23.21 @@ -77,7 +77,7 @@
   23.22  				   let
   23.23  				       val thyname = get_import_thy thy
   23.24  				   in
   23.25 -				       foldl (fn (thy,(hol,isa)) => add_hol4_mapping thyname hol isa thy) (thy,thmmaps)
   23.26 +				       Library.foldl (fn (thy,(hol,isa)) => add_hol4_mapping thyname hol isa thy) (thy,thmmaps)
   23.27  				   end)
   23.28  
   23.29  val type_maps = Scan.repeat1 (P.name --| P.$$$ ">" -- P.xname)
   23.30 @@ -86,7 +86,7 @@
   23.31  				    let
   23.32  					val thyname = get_import_thy thy
   23.33  				    in
   23.34 -					foldl (fn (thy,(hol,isa)) => add_hol4_type_mapping thyname hol false isa thy) (thy,typmaps)
   23.35 +					Library.foldl (fn (thy,(hol,isa)) => add_hol4_type_mapping thyname hol false isa thy) (thy,typmaps)
   23.36  				    end)
   23.37  
   23.38  val def_maps = Scan.repeat1 (P.name --| P.$$$ ">" -- P.xname)
   23.39 @@ -95,7 +95,7 @@
   23.40  				   let
   23.41  				       val thyname = get_import_thy thy
   23.42  				   in
   23.43 -				       foldl (fn (thy,(hol,isa)) => add_defmap thyname hol isa thy) (thy,defmaps)
   23.44 +				       Library.foldl (fn (thy,(hol,isa)) => add_defmap thyname hol isa thy) (thy,defmaps)
   23.45  				   end)
   23.46  
   23.47  val const_renames = Scan.repeat1 (P.name --| P.$$$ ">" -- P.name)
   23.48 @@ -104,7 +104,7 @@
   23.49  					let
   23.50  					    val thyname = get_import_thy thy
   23.51  					in
   23.52 -					    foldl (fn (thy,(hol,isa)) => add_hol4_const_renaming thyname hol isa thy) (thy,renames)
   23.53 +					    Library.foldl (fn (thy,(hol,isa)) => add_hol4_const_renaming thyname hol isa thy) (thy,renames)
   23.54  					end)
   23.55  																      
   23.56  val const_maps = Scan.repeat1 (P.name --| P.$$$ ">" -- P.xname -- Scan.option (P.$$$ "::" |-- P.typ))
   23.57 @@ -113,7 +113,7 @@
   23.58  				     let
   23.59  					 val thyname = get_import_thy thy
   23.60  				     in
   23.61 -					 foldl (fn (thy,((hol,isa),NONE)) => add_hol4_const_mapping thyname hol false isa thy
   23.62 +					 Library.foldl (fn (thy,((hol,isa),NONE)) => add_hol4_const_mapping thyname hol false isa thy
   23.63  						 | (thy,((hol,isa),SOME ty)) => add_hol4_const_wt_mapping thyname hol false isa (typ_of (read_ctyp (sign_of thy) ty)) thy) (thy,constmaps)
   23.64  				     end)
   23.65  
   23.66 @@ -123,7 +123,7 @@
   23.67  				      let
   23.68  					  val thyname = get_import_thy thy
   23.69  				      in
   23.70 -					  foldl (fn (thy,((hol,isa),NONE)) => add_hol4_const_mapping thyname hol true isa thy
   23.71 +					  Library.foldl (fn (thy,((hol,isa),NONE)) => add_hol4_const_mapping thyname hol true isa thy
   23.72  						  | (thy,((hol,isa),SOME ty)) => add_hol4_const_wt_mapping thyname hol true isa (typ_of (read_ctyp (sign_of thy) ty)) thy) (thy,constmaps)
   23.73  				      end)
   23.74  
   23.75 @@ -138,7 +138,7 @@
   23.76  			 Scan.empty_lexicon)
   23.77  	val get_lexes = fn () => !lexes
   23.78  	val token_source = OuterLex.source false get_lexes (Position.line 1) symb_source
   23.79 -	val token_list = filter (not o (OuterLex.is_kind OuterLex.Space)) (Source.exhaust token_source)
   23.80 +	val token_list = filter_out (OuterLex.is_kind OuterLex.Space) (Source.exhaust token_source)
   23.81  	val import_segmentP = OuterParse.$$$ "import_segment" |-- import_segment
   23.82  	val type_mapsP = OuterParse.$$$ "type_maps" |-- type_maps
   23.83  	val def_mapsP = OuterParse.$$$ "def_maps" |-- def_maps
    24.1 --- a/src/HOL/Import/proof_kernel.ML	Thu Mar 03 09:22:35 2005 +0100
    24.2 +++ b/src/HOL/Import/proof_kernel.ML	Thu Mar 03 12:43:01 2005 +0100
    24.3 @@ -580,7 +580,7 @@
    24.4  		 else find ps
    24.5  	     end) handle OS.SysErr _ => find ps
    24.6      in
    24.7 -	apsome (fn p => OS.Path.joinDirFile {dir = p, file = thyname}) (find path)
    24.8 +	Option.map (fn p => OS.Path.joinDirFile {dir = p, file = thyname}) (find path)
    24.9      end
   24.10  			   
   24.11  fun proof_file_name thyname thmname thy =
   24.12 @@ -675,7 +675,7 @@
   24.13  		val (c,asl) = case terms of
   24.14  				  [] => raise ERR "x2p" "Bad oracle description"
   24.15  				| (hd::tl) => (hd,tl)
   24.16 -		val tg = foldr (fn (oracle,tg) => Tag.merge (Tag.read oracle) tg) (ors,Tag.empty_tag)
   24.17 +		val tg = Library.foldr (fn (oracle,tg) => Tag.merge (Tag.read oracle) tg) (ors,Tag.empty_tag)
   24.18  	    in
   24.19  		mk_proof (POracle(tg,map xml_to_term asl,xml_to_term c))
   24.20  	    end
   24.21 @@ -916,7 +916,7 @@
   24.22      end
   24.23  
   24.24  fun implies_elim_all th =
   24.25 -    foldl (fn (th,p) => implies_elim th (assume p)) (th,cprems_of th)
   24.26 +    Library.foldl (fn (th,p) => implies_elim th (assume p)) (th,cprems_of th)
   24.27  
   24.28  fun norm_hyps th =
   24.29      th |> beta_eta_thm
   24.30 @@ -1064,7 +1064,7 @@
   24.31  	  | process _ = raise ERR "disamb_helper" "Internal error"
   24.32  
   24.33  	val (vars',rens',inst) =
   24.34 -	    foldr process (varstm,(vars,rens,[]))
   24.35 +	    Library.foldr process (varstm,(vars,rens,[]))
   24.36      in
   24.37  	({vars=vars',rens=rens'},inst)
   24.38      end
   24.39 @@ -1100,7 +1100,7 @@
   24.40      end
   24.41  
   24.42  fun disamb_terms_from info tms =
   24.43 -    foldr (fn (tm,(info,tms)) =>
   24.44 +    Library.foldr (fn (tm,(info,tms)) =>
   24.45  	      let
   24.46  		  val (info',tm') = disamb_term_from info tm
   24.47  	      in
   24.48 @@ -1109,7 +1109,7 @@
   24.49  	  (tms,(info,[]))
   24.50  
   24.51  fun disamb_thms_from info hthms =
   24.52 -    foldr (fn (hthm,(info,thms)) =>
   24.53 +    Library.foldr (fn (hthm,(info,thms)) =>
   24.54  	      let
   24.55  		  val (info',tm') = disamb_thm_from info hthm
   24.56  	      in
   24.57 @@ -1127,7 +1127,7 @@
   24.58      let
   24.59  	val vars = collect_vars (prop_of th)
   24.60  	val (rens',inst,_) =
   24.61 -	    foldr (fn((ren as (vold as Free(vname,_),vnew)),
   24.62 +	    Library.foldr (fn((ren as (vold as Free(vname,_),vnew)),
   24.63  		      (rens,inst,vars)) =>
   24.64  		     (case Library.find_first (fn Free(v,_) => v = vname | _ => false) vars of
   24.65  			  SOME v' => if v' = vold
   24.66 @@ -1139,7 +1139,7 @@
   24.67  	val (dom,rng) = ListPair.unzip inst
   24.68  	val th' = mk_INST (map (cterm_of sg) dom) (map (cterm_of sg) rng) th
   24.69  	val nvars = collect_vars (prop_of th')
   24.70 -	val rens' = filter (fn(_,v) => v mem nvars) rens
   24.71 +	val rens' = List.filter (fn(_,v) => v mem nvars) rens
   24.72  	val res = HOLThm(rens',th')
   24.73      in
   24.74  	res
   24.75 @@ -1167,7 +1167,7 @@
   24.76  	end
   24.77  
   24.78  fun non_trivial_term_consts tm =
   24.79 -    filter (fn c => not (c = "Trueprop" orelse
   24.80 +    List.filter (fn c => not (c = "Trueprop" orelse
   24.81  			 c = "All" orelse
   24.82  			 c = "op -->" orelse
   24.83  			 c = "op &" orelse
   24.84 @@ -1239,7 +1239,7 @@
   24.85  		val th1 = (SOME (transform_error (PureThy.get_thm thy) (thmname, NONE))
   24.86  			   handle ERROR_MESSAGE _ =>
   24.87  				  (case split_name thmname of
   24.88 -				       SOME (listname,idx) => (SOME (nth_elem(idx-1,PureThy.get_thms thy (listname, NONE)))
   24.89 +				       SOME (listname,idx) => (SOME (List.nth(PureThy.get_thms thy (listname, NONE),idx-1))
   24.90  							       handle _ => NONE)
   24.91  				     | NONE => NONE))
   24.92  	    in
   24.93 @@ -1794,7 +1794,7 @@
   24.94  		      | inst_type ty1 ty2 (ty as Type(name,tys)) =
   24.95  			Type(name,map (inst_type ty1 ty2) tys)
   24.96  		in
   24.97 -		    foldr (fn (v,th) =>
   24.98 +		    Library.foldr (fn (v,th) =>
   24.99  			      let
  24.100  				  val cdom = fst (dom_rng (fst (dom_rng cty)))
  24.101  				  val vty  = type_of v
  24.102 @@ -1806,7 +1806,7 @@
  24.103  		end
  24.104  	      | SOME _ => raise ERR "GEN_ABS" "Bad constant"
  24.105  	      | NONE => 
  24.106 -		foldr (fn (v,th) => mk_ABS v th sg) (vlist',th)
  24.107 +		Library.foldr (fn (v,th) => mk_ABS v th sg) (vlist',th)
  24.108  	val res = HOLThm(rens_of info',th1)
  24.109  	val _ = message "RESULT:"
  24.110  	val _ = if_debug pth res
  24.111 @@ -1876,7 +1876,7 @@
  24.112      let
  24.113  	val constname = rename_const thyname thy constname
  24.114          val sg = sign_of thy
  24.115 -        val redeclared = is_some (Sign.const_type sg (Sign.intern_const sg constname));
  24.116 +        val redeclared = isSome (Sign.const_type sg (Sign.intern_const sg constname));
  24.117  	val _ = warning ("Introducing constant " ^ constname)
  24.118  	val (thmname,thy) = get_defname thyname constname thy
  24.119  	val (info,rhs') = disamb_term rhs
  24.120 @@ -1956,21 +1956,21 @@
  24.121  				 | dest_exists tm =
  24.122  				   raise ERR "new_specification" "Bad existential formula"
  24.123  					 
  24.124 -			       val (consts,_) = foldl (fn ((cs,ex),cname) =>
  24.125 +			       val (consts,_) = Library.foldl (fn ((cs,ex),cname) =>
  24.126  							  let
  24.127  							      val (_,cT,p) = dest_exists ex
  24.128  							  in
  24.129  							      ((cname,cT,mk_syn thy cname)::cs,p)
  24.130  							  end) (([],HOLogic.dest_Trueprop (concl_of th)),names)
  24.131  			       val sg = sign_of thy
  24.132 -			       val str = foldl (fn (acc,(c,T,csyn)) =>
  24.133 +			       val str = Library.foldl (fn (acc,(c,T,csyn)) =>
  24.134  						   acc ^ "\n  " ^ (quotename c) ^ " :: \"" ^ string_of_ctyp (ctyp_of sg T) ^ "\" " ^ (Syntax.string_of_mixfix csyn)) ("consts",consts)
  24.135  			       val thy' = add_dump str thy
  24.136  			   in
  24.137  			       Theory.add_consts_i consts thy'
  24.138  			   end
  24.139  
  24.140 -	    val thy1 = foldr (fn(name,thy)=>
  24.141 +	    val thy1 = Library.foldr (fn(name,thy)=>
  24.142  				snd (get_defname thyname name thy)) (names,thy1)
  24.143  	    fun new_name name = fst (get_defname thyname name thy1)
  24.144  	    val (thy',res) = SpecificationPackage.add_specification_i NONE
  24.145 @@ -1989,7 +1989,7 @@
  24.146  		     then quotename name
  24.147  		     else (quotename newname) ^ ": " ^ (quotename name),thy')
  24.148  		end
  24.149 -	    val (new_names,thy') = foldr (fn(name,(names,thy)) =>
  24.150 +	    val (new_names,thy') = Library.foldr (fn(name,(names,thy)) =>
  24.151  					    let
  24.152  						val (name',thy') = handle_const (name,thy)
  24.153  					    in
    25.1 --- a/src/HOL/Import/replay.ML	Thu Mar 03 09:22:35 2005 +0100
    25.2 +++ b/src/HOL/Import/replay.ML	Thu Mar 03 12:43:01 2005 +0100
    25.3 @@ -25,7 +25,7 @@
    25.4  	    end
    25.5  	  | rp (PSubst(prfs,ctxt,prf)) thy =
    25.6  	    let
    25.7 -		val (thy',ths) = foldr (fn (p,(thy,ths)) =>
    25.8 +		val (thy',ths) = Library.foldr (fn (p,(thy,ths)) =>
    25.9  					   let
   25.10  					       val (thy',th) = rp' p thy
   25.11  					   in
   25.12 @@ -319,7 +319,7 @@
   25.13  	    in
   25.14  		fst (replay_proof int_thms thyname thmname prf thy)
   25.15  	    end
   25.16 -	val res_thy = foldl replay_fact (thy,thmnames)
   25.17 +	val res_thy = Library.foldl replay_fact (thy,thmnames)
   25.18      in
   25.19  	res_thy
   25.20      end
    26.1 --- a/src/HOL/Import/shuffler.ML	Thu Mar 03 09:22:35 2005 +0100
    26.2 +++ b/src/HOL/Import/shuffler.ML	Thu Mar 03 12:43:01 2005 +0100
    26.3 @@ -42,17 +42,17 @@
    26.4    case e of
    26.5       THM (msg,i,thms) =>
    26.6  	 (writeln ("Exception THM " ^ string_of_int i ^ " raised:\n" ^ msg);
    26.7 -	  seq print_thm thms)
    26.8 +	  List.app print_thm thms)
    26.9     | THEORY (msg,thys) =>
   26.10  	 (writeln ("Exception THEORY raised:\n" ^ msg);
   26.11 -	  seq (Pretty.writeln o Display.pretty_theory) thys)
   26.12 +	  List.app (Pretty.writeln o Display.pretty_theory) thys)
   26.13     | TERM (msg,ts) =>
   26.14  	 (writeln ("Exception TERM raised:\n" ^ msg);
   26.15 -	  seq (writeln o Sign.string_of_term sign) ts)
   26.16 +	  List.app (writeln o Sign.string_of_term sign) ts)
   26.17     | TYPE (msg,Ts,ts) =>
   26.18  	 (writeln ("Exception TYPE raised:\n" ^ msg);
   26.19 -	  seq (writeln o Sign.string_of_typ sign) Ts;
   26.20 -	  seq (writeln o Sign.string_of_term sign) ts)
   26.21 +	  List.app (writeln o Sign.string_of_typ sign) Ts;
   26.22 +	  List.app (writeln o Sign.string_of_term sign) ts)
   26.23     | e => raise e
   26.24  
   26.25  (*Prints an exception, then fails*)
   26.26 @@ -251,7 +251,7 @@
   26.27  	val tvars = term_tvars t
   26.28  	val tfree_names = add_term_tfree_names(t,[])
   26.29  	val (type_inst,_) =
   26.30 -	    foldl (fn ((inst,used),(w as (v,_),S)) =>
   26.31 +	    Library.foldl (fn ((inst,used),(w as (v,_),S)) =>
   26.32  		      let
   26.33  			  val v' = variant used v
   26.34  		      in
   26.35 @@ -553,13 +553,13 @@
   26.36      end
   26.37      
   26.38  val collect_ignored =
   26.39 -    foldr (fn (thm,cs) =>
   26.40 +    Library.foldr (fn (thm,cs) =>
   26.41  	      let
   26.42  		  val (lhs,rhs) = Logic.dest_equals (prop_of thm)
   26.43  		  val ignore_lhs = term_consts lhs \\ term_consts rhs
   26.44  		  val ignore_rhs = term_consts rhs \\ term_consts lhs
   26.45  	      in
   26.46 -		  foldr (op ins_string) (ignore_lhs @ ignore_rhs,cs)
   26.47 +		  Library.foldr (op ins_string) (ignore_lhs @ ignore_rhs,cs)
   26.48  	      end)
   26.49  
   26.50  (* set_prop t thms tries to make a theorem with the proposition t from
   26.51 @@ -570,7 +570,7 @@
   26.52      let
   26.53  	val sg = sign_of thy
   26.54  	val vars = add_term_frees (t,add_term_vars (t,[]))
   26.55 -	val closed_t = foldr (fn (v,body) => let val vT = type_of v
   26.56 +	val closed_t = Library.foldr (fn (v,body) => let val vT = type_of v
   26.57  					     in all vT $ (Abs("x",vT,abstract_over(v,body))) end) (vars,t)
   26.58  	val rew_th = norm_term thy closed_t
   26.59  	val rhs = snd (dest_equals (cprop_of rew_th))
   26.60 @@ -614,13 +614,13 @@
   26.61  	val rel_consts = term_consts t \\ ignored
   26.62  	val pot_thms = PureThy.thms_containing_consts thy rel_consts
   26.63      in
   26.64 -	filter (match_consts ignored t) pot_thms
   26.65 +	List.filter (match_consts ignored t) pot_thms
   26.66      end
   26.67  
   26.68  fun gen_shuffle_tac thy search thms i st =
   26.69      let
   26.70  	val _ = message ("Shuffling " ^ (string_of_thm st))
   26.71 -	val t = nth_elem(i-1,prems_of st)
   26.72 +	val t = List.nth(prems_of st,i-1)
   26.73  	val set = set_prop thy t
   26.74  	fun process_tac thms st =
   26.75  	    case set thms of
    27.1 --- a/src/HOL/Integ/cooper_dec.ML	Thu Mar 03 09:22:35 2005 +0100
    27.2 +++ b/src/HOL/Integ/cooper_dec.ML	Thu Mar 03 12:43:01 2005 +0100
    27.3 @@ -442,7 +442,7 @@
    27.4     val ts = coeffs_of t
    27.5     in case ts of
    27.6       [] => raise DVD_UNKNOWN
    27.7 -    |_  => foldr (fn(k,r) => r andalso (k mod dn = 0)) (ts,true)
    27.8 +    |_  => Library.foldr (fn(k,r) => r andalso (k mod dn = 0)) (ts,true)
    27.9     end;
   27.10  
   27.11  
   27.12 @@ -736,7 +736,7 @@
   27.13               in (rw,HOLogic.mk_disj(F',rf)) 
   27.14  	     end)
   27.15      val f = if b then linear_add else linear_sub
   27.16 -    val p_elements = foldr (fn (i,l) => l union (map (fn e => f [] e (mk_numeral i)) st)) (1 upto d,[])
   27.17 +    val p_elements = Library.foldr (fn (i,l) => l union (map (fn e => f [] e (mk_numeral i)) st)) (1 upto d,[])
   27.18      in h p_elements
   27.19      end;
   27.20  
   27.21 @@ -873,7 +873,7 @@
   27.22  fun lift_qelim afn nfn qfn isat = 
   27.23   let   fun qelim x vars p = 
   27.24    let val cjs = conjuncts p 
   27.25 -      val (ycjs,ncjs) = partition (has_bound) cjs in 
   27.26 +      val (ycjs,ncjs) = List.partition (has_bound) cjs in 
   27.27        (if ycjs = [] then p else 
   27.28                            let val q = (qfn vars ((HOLogic.exists_const HOLogic.intT 
   27.29  			  ) $ Abs(x,HOLogic.intT,(list_conj ycjs)))) in 
    28.1 --- a/src/HOL/Integ/presburger.ML	Thu Mar 03 09:22:35 2005 +0100
    28.2 +++ b/src/HOL/Integ/presburger.ML	Thu Mar 03 12:43:01 2005 +0100
    28.3 @@ -148,21 +148,21 @@
    28.4        if body_type T mem [iT, nT] 
    28.5           andalso not (ts = []) andalso forall (null o loose_bnos) ts 
    28.6        then [fm]
    28.7 -      else foldl op union ([], map getfuncs ts)
    28.8 +      else Library.foldl op union ([], map getfuncs ts)
    28.9    | (Var (_, T), ts as _ :: _) =>
   28.10        if body_type T mem [iT, nT] 
   28.11           andalso not (ts = []) andalso forall (null o loose_bnos) ts then [fm]
   28.12 -      else foldl op union ([], map getfuncs ts)
   28.13 +      else Library.foldl op union ([], map getfuncs ts)
   28.14    | (Const (s, T), ts) =>
   28.15        if (s, T) mem allowed_consts orelse not (body_type T mem [iT, nT])
   28.16 -      then foldl op union ([], map getfuncs ts)
   28.17 +      then Library.foldl op union ([], map getfuncs ts)
   28.18        else [fm]
   28.19    | (Abs (s, T, t), _) => getfuncs t
   28.20    | _ => [];
   28.21  
   28.22  
   28.23  fun abstract_pres sg fm = 
   28.24 -  foldr (fn (t, u) =>
   28.25 +  Library.foldr (fn (t, u) =>
   28.26        let val T = fastype_of t
   28.27        in all T $ Abs ("x", T, abstract_over (t, u)) end)
   28.28           (getfuncs fm, fm);
   28.29 @@ -198,7 +198,7 @@
   28.30   abstracted over.*)
   28.31   
   28.32  fun relevant ps t = (term_typed_consts t) subset allowed_consts andalso 
   28.33 -  map (fn i => snd (nth_elem (i, ps))) (loose_bnos t) @
   28.34 +  map (fn i => snd (List.nth (ps, i))) (loose_bnos t) @
   28.35    map (snd o dest_Free) (term_frees t) @ map (snd o dest_Var) (term_vars t)
   28.36    subset [iT, nT]
   28.37    andalso not (has_free_funcs t);
   28.38 @@ -217,13 +217,13 @@
   28.39          (HOLogic.all_const T $ Abs (s, T, P), n)
   28.40        else (incr_boundvars ~1 P, n-1)
   28.41      fun mk_all2 (v, t) = HOLogic.all_const (fastype_of v) $ lambda v t;
   28.42 -    val (rhs,irhs) = partition (relevant (rev ps)) hs
   28.43 +    val (rhs,irhs) = List.partition (relevant (rev ps)) hs
   28.44      val np = length ps
   28.45 -    val (fm',np) =  foldr (fn ((x, T), (fm,n)) => mk_all ((x, T), (fm,n)))
   28.46 -      (ps,(foldr HOLogic.mk_imp (rhs, c), np))
   28.47 -    val (vs, _) = partition (fn t => q orelse (type_of t) = nT)
   28.48 +    val (fm',np) =  Library.foldr (fn ((x, T), (fm,n)) => mk_all ((x, T), (fm,n)))
   28.49 +      (ps,(Library.foldr HOLogic.mk_imp (rhs, c), np))
   28.50 +    val (vs, _) = List.partition (fn t => q orelse (type_of t) = nT)
   28.51        (term_frees fm' @ term_vars fm');
   28.52 -    val fm2 = foldr mk_all2 (vs, fm')
   28.53 +    val fm2 = Library.foldr mk_all2 (vs, fm')
   28.54    in (fm2, np + length vs, length rhs) end;
   28.55  
   28.56  (*Object quantifier to meta --*)
   28.57 @@ -300,7 +300,7 @@
   28.58   in
   28.59     Method.simple_args 
   28.60    (Scan.optional (Args.$$$ "(" |-- Scan.repeat1 parse_flag --| Args.$$$ ")") [] >>
   28.61 -    curry (foldl op |>) (true, false))
   28.62 +    curry (Library.foldl op |>) (true, false))
   28.63      (fn (q,a) => fn _ => meth q a 1)
   28.64    end;
   28.65  
    29.1 --- a/src/HOL/IsaMakefile	Thu Mar 03 09:22:35 2005 +0100
    29.2 +++ b/src/HOL/IsaMakefile	Thu Mar 03 12:43:01 2005 +0100
    29.3 @@ -77,6 +77,7 @@
    29.4    $(SRC)/Provers/make_elim.ML $(SRC)/Provers/order.ML $(SRC)/Provers/quasi.ML\
    29.5    $(SRC)/Provers/simplifier.ML $(SRC)/Provers/splitter.ML \
    29.6    $(SRC)/Provers/trancl.ML \
    29.7 +  $(SRC)/TFL/casesplit.ML \
    29.8    $(SRC)/TFL/dcterm.ML $(SRC)/TFL/post.ML $(SRC)/TFL/rules.ML \
    29.9    $(SRC)/TFL/tfl.ML $(SRC)/TFL/thms.ML $(SRC)/TFL/thry.ML \
   29.10    $(SRC)/TFL/usyntax.ML $(SRC)/TFL/utils.ML \
    30.1 --- a/src/HOL/Lambda/WeakNorm.thy	Thu Mar 03 09:22:35 2005 +0100
    30.2 +++ b/src/HOL/Lambda/WeakNorm.thy	Thu Mar 03 12:43:01 2005 +0100
    30.3 @@ -566,7 +566,7 @@
    30.4    | term_of_dB' _ _ = error "term_of_dB: term not in normal form";
    30.5  
    30.6  fun typing_of_term Ts e (Bound i) =
    30.7 -      rtypingT_Var (e, nat_of_int i, dBtype_of_typ (nth_elem (i, Ts)))
    30.8 +      rtypingT_Var (e, nat_of_int i, dBtype_of_typ (List.nth (Ts, i)))
    30.9    | typing_of_term Ts e (t $ u) = (case fastype_of1 (Ts, t) of
   30.10          Type ("fun", [T, U]) => rtypingT_App (e, dB_of_term t,
   30.11            dBtype_of_typ T, dBtype_of_typ U, dB_of_term u,
    31.1 --- a/src/HOL/Library/EfficientNat.thy	Thu Mar 03 09:22:35 2005 +0100
    31.2 +++ b/src/HOL/Library/EfficientNat.thy	Thu Mar 03 12:43:01 2005 +0100
    31.3 @@ -100,7 +100,7 @@
    31.4      val Suc_if_eq' = Thm.transfer thy Suc_if_eq;
    31.5      val ctzero = cterm_of (sign_of Main.thy) HOLogic.zero;
    31.6      val vname = variant (map fst
    31.7 -      (foldl add_term_varnames ([], map prop_of thms))) "x";
    31.8 +      (Library.foldl add_term_varnames ([], map prop_of thms))) "x";
    31.9      val cv = cterm_of (sign_of Main.thy) (Var ((vname, 0), HOLogic.natT));
   31.10      fun lhs_of th = snd (Thm.dest_comb
   31.11        (fst (Thm.dest_comb (snd (Thm.dest_comb (cprop_of th))))));
   31.12 @@ -114,13 +114,13 @@
   31.13            map (apfst (pairself (Thm.capply ct1))) (find_vars ct2)
   31.14          end
   31.15        | _ => []);
   31.16 -    val eqs1 = flat (map
   31.17 +    val eqs1 = List.concat (map
   31.18        (fn th => map (pair th) (find_vars (lhs_of th))) thms);
   31.19 -    val eqs2 = map (fn x as (_, ((_, ctzero), _)) => (x, mapfilter (fn th =>
   31.20 +    val eqs2 = map (fn x as (_, ((_, ctzero), _)) => (x, List.mapPartial (fn th =>
   31.21        SOME (th, Thm.cterm_match (lhs_of th, ctzero))
   31.22          handle Pattern.MATCH => NONE) thms)) eqs1;
   31.23      fun distinct_vars vs = forall is_Var vs andalso null (duplicates vs);
   31.24 -    val eqs2' = map (apsnd (filter (fn (_, (_, s)) =>
   31.25 +    val eqs2' = map (apsnd (List.filter (fn (_, (_, s)) =>
   31.26        distinct_vars (map (term_of o snd) s)))) eqs2;
   31.27      fun mk_thms b ((th, ((ct, _), cv')), (th', s) :: _) =
   31.28        let
   31.29 @@ -133,7 +133,7 @@
   31.30                   SOME (rhs_of th''), SOME (Thm.cabs cv' (rhs_of th)), SOME cv']
   31.31                 Suc_if_eq')) th'') (Thm.forall_intr cv' th)
   31.32        in
   31.33 -        mapfilter (fn thm =>
   31.34 +        List.mapPartial (fn thm =>
   31.35            if thm = th then SOME th'''
   31.36            else if b andalso thm = th' then NONE
   31.37            else SOME thm) thms
   31.38 @@ -160,13 +160,13 @@
   31.39    let
   31.40      val Suc_clause' = Thm.transfer thy Suc_clause;
   31.41      val vname = variant (map fst
   31.42 -      (foldl add_term_varnames ([], map prop_of thms))) "x";
   31.43 +      (Library.foldl add_term_varnames ([], map prop_of thms))) "x";
   31.44      fun find_var (t as Const ("Suc", _) $ (v as Var _)) = SOME (t, v)
   31.45        | find_var (t $ u) = (case find_var t of NONE => find_var u | x => x)
   31.46        | find_var _ = NONE;
   31.47      fun find_thm th =
   31.48        let val th' = ObjectLogic.atomize_thm th
   31.49 -      in apsome (pair (th, th')) (find_var (prop_of th')) end
   31.50 +      in Option.map (pair (th, th')) (find_var (prop_of th')) end
   31.51    in
   31.52      case get_first find_thm thms of
   31.53        NONE => thms
   31.54 @@ -191,8 +191,8 @@
   31.55    let val dest = fst o HOLogic.dest_mem o HOLogic.dest_Trueprop
   31.56    in
   31.57      if forall (can (dest o concl_of)) ths andalso
   31.58 -      exists (fn th => "Suc" mem foldr add_term_consts
   31.59 -        (mapfilter (try dest) (concl_of th :: prems_of th), [])) ths
   31.60 +      exists (fn th => "Suc" mem Library.foldr add_term_consts
   31.61 +        (List.mapPartial (try dest) (concl_of th :: prems_of th), [])) ths
   31.62      then remove_suc_clause thy ths else ths
   31.63    end;
   31.64  
    32.1 --- a/src/HOL/List.thy	Thu Mar 03 09:22:35 2005 +0100
    32.2 +++ b/src/HOL/List.thy	Thu Mar 03 12:43:01 2005 +0100
    32.3 @@ -2127,7 +2127,7 @@
    32.4      (let val c = chr (dest_nibble c1 * 16 + dest_nibble c2)
    32.5       in if Symbol.is_printable c then SOME (gr, Pretty.quote (Pretty.str c))
    32.6         else NONE
    32.7 -     end handle LIST _ => NONE | Match => NONE)
    32.8 +     end handle Fail _ => NONE | Match => NONE)
    32.9    | char_codegen thy gr dep b _ = NONE;
   32.10  
   32.11  in
    33.1 --- a/src/HOL/Matrix/Cplex.ML	Thu Mar 03 09:22:35 2005 +0100
    33.2 +++ b/src/HOL/Matrix/Cplex.ML	Thu Mar 03 12:43:01 2005 +0100
    33.3 @@ -716,7 +716,7 @@
    33.4  
    33.5  fun merge a b = Symtab.merge (op =) (a, b)
    33.6  
    33.7 -fun mergemap f ts = foldl
    33.8 +fun mergemap f ts = Library.foldl
    33.9  			(fn (table, x) => merge table (f x))
   33.10  			(Symtab.empty, ts)
   33.11  
   33.12 @@ -778,7 +778,7 @@
   33.13  			      (fn (l, (k,v)) => (make_pos_constr k) :: l)
   33.14  			      ([], positive_vars))
   33.15          val bound_constrs = map (fn x => (NONE, x)) 
   33.16 -				(flat (map bound2constr bounds))
   33.17 +				(List.concat (map bound2constr bounds))
   33.18  	val constraints' = constraints @ pos_constrs @ bound_constrs	   
   33.19  	val bounds' = rev(Symtab.foldl (fn (l, (v,_)) => 
   33.20  					   (make_free_bound v)::l)
    34.1 --- a/src/HOL/Matrix/CplexMatrixConverter.ML	Thu Mar 03 09:22:35 2005 +0100
    34.2 +++ b/src/HOL/Matrix/CplexMatrixConverter.ML	Thu Mar 03 12:43:01 2005 +0100
    34.3 @@ -73,7 +73,7 @@
    34.4  	    set_elem vec (s2i v) (if positive then num else "-"^num)
    34.5  	  | setprod _ _ _ = raise (Converter "term is not a normed product")	
    34.6  
    34.7 -	fun sum2vec (cplexSum ts) = foldl (fn (vec, t) => setprod vec true t) (empty_vector, ts)
    34.8 +	fun sum2vec (cplexSum ts) = Library.foldl (fn (vec, t) => setprod vec true t) (empty_vector, ts)
    34.9  	  | sum2vec t = setprod empty_vector true t						
   34.10  
   34.11  	fun constrs2Ab j A b [] = (A, b)
   34.12 @@ -100,7 +100,7 @@
   34.13      let
   34.14  	fun setv (v, (name, value)) = (matrix_builder.set_elem v (name2index name) value) 
   34.15      in
   34.16 -	(opt, foldl setv (matrix_builder.empty_vector, entries))
   34.17 +	(opt, Library.foldl setv (matrix_builder.empty_vector, entries))
   34.18      end
   34.19    | convert_results _ _ = raise (Converter "No optimal result")
   34.20      
    35.1 --- a/src/HOL/Matrix/codegen_prep.ML	Thu Mar 03 09:22:35 2005 +0100
    35.2 +++ b/src/HOL/Matrix/codegen_prep.ML	Thu Mar 03 12:43:01 2005 +0100
    35.3 @@ -80,7 +80,7 @@
    35.4      
    35.5  fun prepare_thms ths = 
    35.6      let
    35.7 -	val ths = (filter is_meta_eq ths) @ (map (standard o mk_meta_eq) (filter (not o is_meta_eq) ths))		      
    35.8 +	val ths = (List.filter is_meta_eq ths) @ (map (standard o mk_meta_eq) (filter_out is_meta_eq ths))		      
    35.9  	val _ = if forall Thm.no_prems ths then () else raise (Prepare_thms "premisse found")
   35.10  	val thmgroups = group head_name ths
   35.11  	val test_clashgroups = group (fn (a,b) => mangle_id a) thmgroups
    36.1 --- a/src/HOL/Matrix/eq_codegen.ML	Thu Mar 03 09:22:35 2005 +0100
    36.2 +++ b/src/HOL/Matrix/eq_codegen.ML	Thu Mar 03 12:43:01 2005 +0100
    36.3 @@ -24,7 +24,7 @@
    36.4  fun parens b = if b then Pretty.enclose "(" ")" else Pretty.block;
    36.5  
    36.6  fun gen_mk_val f xs ps = Pretty.block ([Pretty.str "val ",
    36.7 -  f (length xs > 1) (flat
    36.8 +  f (length xs > 1) (List.concat
    36.9      (separate [Pretty.str ",", Pretty.brk 1] (map (single o Pretty.str) xs))),
   36.10    Pretty.str " =", Pretty.brk 1] @ ps @ [Pretty.str ";"]);
   36.11  
   36.12 @@ -79,7 +79,7 @@
   36.13        let
   36.14          val vs' = variantlist (map mk_decomp_tname Ts, vs);
   36.15          val (vs'', bs', ps') =
   36.16 -          foldl decomp_type_code ((vs @ vs', bs, ps @
   36.17 +          Library.foldl decomp_type_code ((vs @ vs', bs, ps @
   36.18              [mk_vall vs' [Pretty.str "Thm.dest_ctyp", Pretty.brk 1,
   36.19                Pretty.str v]]), vs' ~~ Ts)
   36.20        in
   36.21 @@ -106,7 +106,7 @@
   36.22  fun pretty_pattern b (Const (s, _)) = Pretty.block [Pretty.str "Const",
   36.23        Pretty.brk 1, Pretty.str ("(\"" ^ s ^ "\", _)")]
   36.24    | pretty_pattern b (t as _ $ _) = parens b
   36.25 -      (flat (separate [Pretty.str " $", Pretty.brk 1]
   36.26 +      (List.concat (separate [Pretty.str " $", Pretty.brk 1]
   36.27          (map (single o pretty_pattern true) (op :: (strip_comb t)))))
   36.28    | pretty_pattern b _ = Pretty.str "_";
   36.29  
   36.30 @@ -129,7 +129,7 @@
   36.31      [] => Pretty.str s
   36.32    | Ts => parens b [Pretty.str "tyinst_cterm", Pretty.brk 1,
   36.33        Pretty.list "[" "]" (map (fn (ixn, _) => mk_tyinst
   36.34 -        (ixn, the (assoc (ty_bs, ixn)))) Ts),
   36.35 +        (ixn, valOf (assoc (ty_bs, ixn)))) Ts),
   36.36        Pretty.brk 1, Pretty.str s]);
   36.37  
   36.38  fun mk_cterm_code b ty_bs ts xs (vals, t $ u) =
   36.39 @@ -151,7 +151,7 @@
   36.40        in (vals',
   36.41          parens b [Pretty.str "Thm.cabs", Pretty.brk 1, p, Pretty.brk 1, p'])
   36.42        end
   36.43 -  | mk_cterm_code b ty_bs ts xs (vals, Bound i) = (vals, nth_elem (i, xs))
   36.44 +  | mk_cterm_code b ty_bs ts xs (vals, Bound i) = (vals, List.nth (xs, i))
   36.45    | mk_cterm_code b ty_bs ts xs (vals, t) = (case assoc (vals, t) of
   36.46          NONE =>
   36.47            let val SOME s = assoc (ts, t)
   36.48 @@ -182,7 +182,7 @@
   36.49        in if s = s' then (vs, subs)
   36.50          else (s' :: vs, ((s, i), Var ((s', i), T)) :: subs)
   36.51        end;
   36.52 -    val (vs', subs) = foldl mk_subst ((vs, []), term_vars t)
   36.53 +    val (vs', subs) = Library.foldl mk_subst ((vs, []), term_vars t)
   36.54    in (vs', subst_Vars subs t) end;
   36.55  
   36.56  fun is_instance sg t u = t = subst_TVars_Vartab
   36.57 @@ -190,7 +190,7 @@
   36.58      (fastype_of u, fastype_of t))) u handle Type.TYPE_MATCH => false;
   36.59  
   36.60  (*
   36.61 -fun lookup sg fs t = apsome snd (Library.find_first
   36.62 +fun lookup sg fs t = Option.map snd (Library.find_first
   36.63    (is_instance sg t o fst) fs);
   36.64  *)
   36.65  
   36.66 @@ -269,18 +269,18 @@
   36.67                      val cvs' = map Var (map (rpair 0) ys ~~ Ts);
   36.68                      val rs = cvs' ~~ cvs;
   36.69                      val lhs = list_comb (Const (cname, Ts ---> uT), cvs');
   36.70 -                    val rhs = foldl betapply (f, cvs');
   36.71 +                    val rhs = Library.foldl betapply (f, cvs');
   36.72                      val (vs', tm_bs, tm_vals) = decomp_term_code false
   36.73                        ((vs @ ys, [], []), (ct, lhs));
   36.74                      val ((vs'', all_vals), (eq', ct')) = mk_simpl_code sg case_tab
   36.75                        false fs (tm_bs @ ts) ty_bs thm_bs ((vs', vals), rhs);
   36.76                      val (old_vals, eq_vals) = splitAt (i, all_vals);
   36.77 -                    val vs''' = vs @ filter (fn v => exists
   36.78 +                    val vs''' = vs @ List.filter (fn v => exists
   36.79                        (fn (_, ((v', _), _)) => v = v') old_vals) (vs'' \\ vs');
   36.80                      val insts2 = map (fn (t, s) => Pretty.block [Pretty.str "(",
   36.81 -                      inst_ty false ty_bs' t (the (assoc (thm_bs, t))), Pretty.str ",",
   36.82 +                      inst_ty false ty_bs' t (valOf (assoc (thm_bs, t))), Pretty.str ",",
   36.83                        Pretty.brk 1, Pretty.str (s ^ ")")]) ((fvs ~~ xs) @
   36.84 -                        (map (fn (v, s) => (the (assoc (rs, v)), s)) tm_bs));
   36.85 +                        (map (fn (v, s) => (valOf (assoc (rs, v)), s)) tm_bs));
   36.86                      val eq'' = if null insts1 andalso null insts2 then Pretty.str name
   36.87                        else parens (eq' <> "") [Pretty.str
   36.88                            (if null cvs then "Thm.instantiate" else "Drule.instantiate"),
   36.89 @@ -293,7 +293,7 @@
   36.90                    in
   36.91                      ((vs''', old_vals), Pretty.block [pretty_pattern false lhs,
   36.92                        Pretty.str " =>",
   36.93 -                      Pretty.brk 1, mk_let "let" 2 (tm_vals @ flat (map (snd o snd) eq_vals))
   36.94 +                      Pretty.brk 1, mk_let "let" 2 (tm_vals @ List.concat (map (snd o snd) eq_vals))
   36.95                          [Pretty.str ("(" ^ ct' ^ ","), Pretty.brk 1, eq''', Pretty.str ")"]])
   36.96                    end;
   36.97  
   36.98 @@ -308,7 +308,7 @@
   36.99                    fvals @ ty_vals @
  36.100                    [mk_val [ct', eq'] ([Pretty.str "(case", Pretty.brk 1,
  36.101                      Pretty.str ("term_of " ^ ct ^ " of"), Pretty.brk 1] @
  36.102 -                    flat (separate [Pretty.brk 1, Pretty.str "| "]
  36.103 +                    List.concat (separate [Pretty.brk 1, Pretty.str "| "]
  36.104                        (map single case_ps)) @ [Pretty.str ")"])]
  36.105                in
  36.106                  if b then
  36.107 @@ -334,7 +334,7 @@
  36.108                val b = forall (unint sg fs) us;
  36.109                val (q, eqs) = foldl_map
  36.110                  (mk_simpl_code sg case_tab (not b) fs ts ty_bs thm_bs) ((vs, vals), us);
  36.111 -              val ((vs', vals'), (eqf, ctf)) = if is_some (lookup sg fs f) andalso b
  36.112 +              val ((vs', vals'), (eqf, ctf)) = if isSome (lookup sg fs f) andalso b
  36.113                  then (q, ("", ""))
  36.114                  else mk_simpl_code sg case_tab (not b) fs ts ty_bs thm_bs (q, f);
  36.115                val ct = variant vs' "ct";
  36.116 @@ -372,38 +372,38 @@
  36.117  
  36.118  fun mk_funs_code sg case_tab fs fs' =
  36.119    let
  36.120 -    val case_thms = mapfilter (fn s => (case Symtab.lookup (case_tab, s) of
  36.121 +    val case_thms = List.mapPartial (fn s => (case Symtab.lookup (case_tab, s) of
  36.122          NONE => NONE
  36.123        | SOME thms => SOME (unsuffix "_case" (Sign.base_name s) ^ ".cases",
  36.124            map (fn i => Sign.base_name s ^ "_" ^ string_of_int i)
  36.125              (1 upto length thms) ~~ thms)))
  36.126 -      (foldr add_term_consts (map (prop_of o snd)
  36.127 -        (flat (map (#3 o snd) fs')), []));
  36.128 +      (Library.foldr add_term_consts (map (prop_of o snd)
  36.129 +        (List.concat (map (#3 o snd) fs')), []));
  36.130      val case_vals = map (fn (s, cs) => mk_vall (map fst cs)
  36.131        [Pretty.str "map my_mk_meta_eq", Pretty.brk 1,
  36.132         Pretty.str ("(thms \"" ^ s ^ "\")")]) case_thms;
  36.133 -    val (vs, thm_bs, thm_vals) = foldl mk_term_bindings (([], [], []),
  36.134 -      flat (map (map (apsnd prop_of) o #3 o snd) fs') @
  36.135 -      map (apsnd prop_of) (flat (map snd case_thms)));
  36.136 +    val (vs, thm_bs, thm_vals) = Library.foldl mk_term_bindings (([], [], []),
  36.137 +      List.concat (map (map (apsnd prop_of) o #3 o snd) fs') @
  36.138 +      map (apsnd prop_of) (List.concat (map snd case_thms)));
  36.139  
  36.140      fun mk_fun_code (prfx, (fname, d, eqns)) =
  36.141        let
  36.142          val (f, ts) = strip_comb (lhs_of (snd (hd eqns)));
  36.143          val args = variantlist (replicate (length ts) "ct", vs);
  36.144 -        val (vs', ty_bs, ty_vals) = foldl mk_type_bindings
  36.145 +        val (vs', ty_bs, ty_vals) = Library.foldl mk_type_bindings
  36.146            ((vs @ args, [], []), args ~~ map fastype_of ts);
  36.147          val insts1 = map mk_tyinst ty_bs;
  36.148  
  36.149          fun mk_eqn_code (name, eqn) =
  36.150            let
  36.151              val (_, argts) = strip_comb (lhs_of eqn);
  36.152 -            val (vs'', tm_bs, tm_vals) = foldl (decomp_term_code false)
  36.153 +            val (vs'', tm_bs, tm_vals) = Library.foldl (decomp_term_code false)
  36.154                ((vs', [], []), args ~~ argts);
  36.155              val ((vs''', eq_vals), (eq, ct)) = mk_simpl_code sg case_tab false fs
  36.156                (tm_bs @ filter_out (is_Var o fst) thm_bs) ty_bs thm_bs
  36.157                ((vs'', []), rhs_of eqn);
  36.158              val insts2 = map (fn (t, s) => Pretty.block [Pretty.str "(",
  36.159 -              inst_ty false ty_bs t (the (assoc (thm_bs, t))), Pretty.str ",", Pretty.brk 1,
  36.160 +              inst_ty false ty_bs t (valOf (assoc (thm_bs, t))), Pretty.str ",", Pretty.brk 1,
  36.161                Pretty.str (s ^ ")")]) tm_bs
  36.162              val eq' = if null insts1 andalso null insts2 then Pretty.str name
  36.163                else parens (eq <> "") [Pretty.str "Thm.instantiate",
  36.164 @@ -417,7 +417,7 @@
  36.165              Pretty.block [parens (length argts > 1)
  36.166                  (Pretty.commas (map (pretty_pattern false) argts)),
  36.167                Pretty.str " =>",
  36.168 -              Pretty.brk 1, mk_let "let" 2 (ty_vals @ tm_vals @ flat (map (snd o snd) eq_vals))
  36.169 +              Pretty.brk 1, mk_let "let" 2 (ty_vals @ tm_vals @ List.concat (map (snd o snd) eq_vals))
  36.170                  [Pretty.str ("(" ^ ct ^ ","), Pretty.brk 1, eq'', Pretty.str ")"]]
  36.171            end;
  36.172  
  36.173 @@ -441,7 +441,7 @@
  36.174            [Pretty.str " =", Pretty.brk 1, Pretty.str "(case", Pretty.brk 1,
  36.175             Pretty.list "(" ")" (map (fn s => Pretty.str ("term_of " ^ s)) args),
  36.176             Pretty.str " of", Pretty.brk 1] @
  36.177 -          flat (separate [Pretty.brk 1, Pretty.str "| "]
  36.178 +          List.concat (separate [Pretty.brk 1, Pretty.str "| "]
  36.179              (map (single o mk_eqn_code) eqns)) @ [Pretty.str ")"] @ default))
  36.180        end;
  36.181  
  36.182 @@ -458,19 +458,19 @@
  36.183      val eqns' = map attach_term eqns;
  36.184      fun mk_node (s, _, (_, th) :: _) = (s, get_head th);
  36.185      fun mk_edges (s, _, ths) = map (pair s) (distinct
  36.186 -      (mapfilter (fn t => apsome #1 (lookup sg eqns' t))
  36.187 -        (flat (map (term_consts' o prop_of o snd) ths))));
  36.188 -    val gr = foldr (uncurry Graph.add_edge)
  36.189 -      (map (pair "" o #1) eqns @ flat (map mk_edges eqns),
  36.190 -       foldr (uncurry Graph.new_node)
  36.191 +      (List.mapPartial (fn t => Option.map #1 (lookup sg eqns' t))
  36.192 +        (List.concat (map (term_consts' o prop_of o snd) ths))));
  36.193 +    val gr = Library.foldr (uncurry Graph.add_edge)
  36.194 +      (map (pair "" o #1) eqns @ List.concat (map mk_edges eqns),
  36.195 +       Library.foldr (uncurry Graph.new_node)
  36.196           (("", Bound 0) :: map mk_node eqns, Graph.empty));
  36.197      val keys = rev (Graph.all_succs gr [""] \ "");
  36.198      fun gr_ord (x :: _, y :: _) =
  36.199        int_ord (find_index (equal x) keys, find_index (equal y) keys);
  36.200 -    val scc = map (fn xs => filter (fn (_, (s, _, _)) => s mem xs) eqns')
  36.201 +    val scc = map (fn xs => List.filter (fn (_, (s, _, _)) => s mem xs) eqns')
  36.202        (sort gr_ord (Graph.strong_conn gr \ [""]));
  36.203    in
  36.204 -    flat (separate [Pretty.str ";", Pretty.fbrk, Pretty.str " ", Pretty.fbrk]
  36.205 +    List.concat (separate [Pretty.str ";", Pretty.fbrk, Pretty.str " ", Pretty.fbrk]
  36.206        (map (fn eqns'' => [mk_funs_code sg case_tab eqns' eqns'']) scc)) @
  36.207      [Pretty.str ";", Pretty.fbrk]
  36.208    end;
  36.209 @@ -482,7 +482,7 @@
  36.210        let val (i', eqs') = foldl_map attach_name (i, eqs)
  36.211        in (i', (s, b, eqs')) end;
  36.212      val (_, eqns') = foldl_map attach_names (1, eqns);
  36.213 -    val (names, thms) = split_list (flat (map #3 eqns'));
  36.214 +    val (names, thms) = split_list (List.concat (map #3 eqns'));
  36.215      val s = setmp print_mode [] Pretty.string_of
  36.216        (mk_let "local" 2 [mk_vall names [Pretty.str "!SimprocsCodegen.simp_thms"]]
  36.217          (mk_simprocs_code sg eqns'))
    37.1 --- a/src/HOL/Matrix/fspmlp.ML	Thu Mar 03 09:22:35 2005 +0100
    37.2 +++ b/src/HOL/Matrix/fspmlp.ML	Thu Mar 03 12:43:01 2005 +0100
    37.3 @@ -145,7 +145,7 @@
    37.4  				     NONE => NONE
    37.5  				   | SOME src_sure_bound => SOME (FloatArith.add x (mult_btype src_sure_bound coeff)))
    37.6  		    in
    37.7 -			case foldl add_src_bound (SOME row_bound, sources) of
    37.8 +			case Library.foldl add_src_bound (SOME row_bound, sources) of
    37.9  			    NONE => sure_bound
   37.10  			  | new_sure_bound as (SOME new_bound) => 
   37.11  			    (case sure_bound of 
   37.12 @@ -234,7 +234,7 @@
   37.13  						add_edge g (src_index, LOWER) dest_key row_index coeff
   37.14  					end
   37.15  			    in	    
   37.16 -				foldl fold_src_nodes ((add_row_bound g dest_key row_index row_bound), approx_a)
   37.17 +				Library.foldl fold_src_nodes ((add_row_bound g dest_key row_index row_bound), approx_a)
   37.18  			    end
   37.19  		    end
   37.20  	    in
   37.21 @@ -251,7 +251,7 @@
   37.22  			else
   37.23  			    g
   37.24  		    end
   37.25 -		  | _ => foldl fold_dest_nodes (g, approx_a)
   37.26 +		  | _ => Library.foldl fold_dest_nodes (g, approx_a)
   37.27  	    end
   37.28  	
   37.29  	val g = FloatSparseMatrixBuilder.m_fold calcr VarGraph.empty A
    38.1 --- a/src/HOL/MicroJava/BV/BVExample.thy	Thu Mar 03 09:22:35 2005 +0100
    38.2 +++ b/src/HOL/MicroJava/BV/BVExample.thy	Thu Mar 03 12:43:01 2005 +0100
    38.3 @@ -454,7 +454,7 @@
    38.4    "op :"   ("(_ mem _)")
    38.5    "op Un"  ("(_ union _)")
    38.6    "image"  ("map")
    38.7 -  "UNION"  ("(fn A => fn f => flat (map f A))")
    38.8 +  "UNION"  ("(fn A => fn f => List.concat (map f A))")
    38.9    "Bex"    ("(fn A => fn f => exists f A)")
   38.10    "Ball"   ("(fn A => fn f => forall f A)")
   38.11    "some_elem" ("hd")
    39.1 --- a/src/HOL/Modelcheck/EindhovenSyn.ML	Thu Mar 03 09:22:35 2005 +0100
    39.2 +++ b/src/HOL/Modelcheck/EindhovenSyn.ML	Thu Mar 03 12:43:01 2005 +0100
    39.3 @@ -7,7 +7,7 @@
    39.4  fun mc_eindhoven_tac i state =
    39.5  let val sign = #sign (rep_thm state)
    39.6  in 
    39.7 -case drop(i-1,prems_of state) of
    39.8 +case Library.drop(i-1,prems_of state) of
    39.9     [] => Seq.empty |
   39.10     subgoal::_ => 
   39.11  	let val concl = Logic.strip_imp_concl subgoal;
    40.1 --- a/src/HOL/Modelcheck/MuckeSyn.ML	Thu Mar 03 09:22:35 2005 +0100
    40.2 +++ b/src/HOL/Modelcheck/MuckeSyn.ML	Thu Mar 03 12:43:01 2005 +0100
    40.3 @@ -51,14 +51,14 @@
    40.4  		     REPEAT (resolve_tac prems 1)]);
    40.5  
    40.6    val sig_move_thm = #sign (rep_thm move_thm);
    40.7 -  val bCterm = cterm_of sig_move_thm (the (search_var "b" (concl_of move_thm)));
    40.8 -  val aCterm = cterm_of sig_move_thm (the (search_var "a" (hd(prems_of move_thm)))); 
    40.9 +  val bCterm = cterm_of sig_move_thm (valOf (search_var "b" (concl_of move_thm)));
   40.10 +  val aCterm = cterm_of sig_move_thm (valOf (search_var "a" (hd(prems_of move_thm)))); 
   40.11  
   40.12  in
   40.13  
   40.14  fun move_mus i state =
   40.15  let val sign = #sign (rep_thm state);
   40.16 -    val (subgoal::_) = drop(i-1,prems_of state);
   40.17 +    val (subgoal::_) = Library.drop(i-1,prems_of state);
   40.18      val concl = Logic.strip_imp_concl subgoal; (* recursive mu's in prems? *)
   40.19      val redex = search_mu concl;
   40.20      val idx = let val t = #maxidx (rep_thm state) in 
   40.21 @@ -84,7 +84,7 @@
   40.22  (* Normally t can be user-instantiated by the value thy of the Isabelle context     *)
   40.23  fun call_mucke_tac i state =
   40.24  let val sign = #sign (rep_thm state);
   40.25 -    val (subgoal::_) = drop(i-1,prems_of state);
   40.26 +    val (subgoal::_) = Library.drop(i-1,prems_of state);
   40.27      val OraAss = invoke_oracle MuckeSyn.thy "Mucke" (sign,MuckeOracleExn (subgoal));
   40.28  in 
   40.29  (cut_facts_tac [OraAss] i) state
   40.30 @@ -166,7 +166,7 @@
   40.31  (* the interface *)
   40.32  
   40.33  fun mc_mucke_tac defs i state =
   40.34 -  (case drop (i - 1, Thm.prems_of state) of
   40.35 +  (case Library.drop (i - 1, Thm.prems_of state) of
   40.36      [] => PureGeneral.Seq.empty
   40.37    | subgoal :: _ =>
   40.38        EVERY [
    41.1 --- a/src/HOL/Modelcheck/mucke_oracle.ML	Thu Mar 03 09:22:35 2005 +0100
    41.2 +++ b/src/HOL/Modelcheck/mucke_oracle.ML	Thu Mar 03 12:43:01 2005 +0100
    41.3 @@ -96,7 +96,7 @@
    41.4  
    41.5  fun if_full_simp_tac sset i state =
    41.6  let val sign = #sign (rep_thm state);
    41.7 -        val (subgoal::_) = drop(i-1,prems_of state);
    41.8 +        val (subgoal::_) = Library.drop(i-1,prems_of state);
    41.9          val prems = Logic.strip_imp_prems subgoal;
   41.10  	val concl = Logic.strip_imp_concl subgoal;
   41.11  	val prems = prems @ [concl];
   41.12 @@ -253,10 +253,10 @@
   41.13        fun newName (Var(ix,_), (pairs,used)) = 
   41.14            let val v = variant used (string_of_indexname ix)
   41.15            in  ((ix,v)::pairs, v::used)  end;
   41.16 -      val (alist, _) = foldr newName (vars, ([], used));
   41.17 +      val (alist, _) = Library.foldr newName (vars, ([], used));
   41.18        fun mk_inst (Var(v,T)) = 
   41.19            (Var(v,T),
   41.20 -           Free(the (assoc(alist,v)), T));
   41.21 +           Free(valOf (assoc(alist,v)), T));
   41.22        val insts = map mk_inst vars;
   41.23    in subst_atomic insts t end;
   41.24  
    42.1 --- a/src/HOL/Product_Type.thy	Thu Mar 03 09:22:35 2005 +0100
    42.2 +++ b/src/HOL/Product_Type.thy	Thu Mar 03 12:43:01 2005 +0100
    42.3 @@ -816,7 +816,7 @@
    42.4              val (gr1, qs) = foldl_map mk_code (gr, ps);
    42.5              val (gr2, pu) = Codegen.invoke_codegen thy dep false (gr1, u)
    42.6            in
    42.7 -            SOME (gr2, Pretty.blk (0, [Pretty.str "let ", Pretty.blk (0, flat
    42.8 +            SOME (gr2, Pretty.blk (0, [Pretty.str "let ", Pretty.blk (0, List.concat
    42.9                  (separate [Pretty.str ";", Pretty.brk 1] (map (fn (pl, pr) =>
   42.10                    [Pretty.block [Pretty.str "val ", pl, Pretty.str " =",
   42.11                       Pretty.brk 1, pr]]) qs))),
    43.1 --- a/src/HOL/Prolog/HOHH.ML	Thu Mar 03 09:22:35 2005 +0100
    43.2 +++ b/src/HOL/Prolog/HOHH.ML	Thu Mar 03 12:43:01 2005 +0100
    43.3 @@ -63,7 +63,7 @@
    43.4  	imp_all];	  (* "((!x. D) :- G) = (!x. D :- G)" *)
    43.5  
    43.6  (*val hyp_resolve_tac = METAHYPS (fn prems => 
    43.7 -				  resolve_tac (flat (map atomizeD prems)) 1);
    43.8 +				  resolve_tac (List.concat (map atomizeD prems)) 1);
    43.9    -- is nice, but cannot instantiate unknowns in the assumptions *)
   43.10  fun hyp_resolve_tac i st = let
   43.11  	fun ap (Const("All",_)$Abs(_,_,t))=(case ap t of (k,a,t) => (k+1,a  ,t))
   43.12 @@ -98,10 +98,10 @@
   43.13  		else no_tac);
   43.14  	val ptacs = mapn (fn n => fn t => 
   43.15  			  pres_tac (ap (HOLogic.dest_Trueprop t)) n i) 0 prems;
   43.16 -	in foldl (op APPEND) (no_tac, ptacs) st end;
   43.17 +	in Library.foldl (op APPEND) (no_tac, ptacs) st end;
   43.18  
   43.19  fun ptac prog = let
   43.20 -  val proga = flat (map atomizeD prog)			(* atomize the prog *)
   43.21 +  val proga = List.concat (map atomizeD prog)			(* atomize the prog *)
   43.22    in	(REPEAT_DETERM1 o FIRST' [
   43.23  		rtac TrueI,			(* "True" *)
   43.24  		rtac conjI,			(* "[| P; Q |] ==> P & Q" *)
    44.1 --- a/src/HOL/Tools/Presburger/cooper_dec.ML	Thu Mar 03 09:22:35 2005 +0100
    44.2 +++ b/src/HOL/Tools/Presburger/cooper_dec.ML	Thu Mar 03 12:43:01 2005 +0100
    44.3 @@ -442,7 +442,7 @@
    44.4     val ts = coeffs_of t
    44.5     in case ts of
    44.6       [] => raise DVD_UNKNOWN
    44.7 -    |_  => foldr (fn(k,r) => r andalso (k mod dn = 0)) (ts,true)
    44.8 +    |_  => Library.foldr (fn(k,r) => r andalso (k mod dn = 0)) (ts,true)
    44.9     end;
   44.10  
   44.11  
   44.12 @@ -736,7 +736,7 @@
   44.13               in (rw,HOLogic.mk_disj(F',rf)) 
   44.14  	     end)
   44.15      val f = if b then linear_add else linear_sub
   44.16 -    val p_elements = foldr (fn (i,l) => l union (map (fn e => f [] e (mk_numeral i)) st)) (1 upto d,[])
   44.17 +    val p_elements = Library.foldr (fn (i,l) => l union (map (fn e => f [] e (mk_numeral i)) st)) (1 upto d,[])
   44.18      in h p_elements
   44.19      end;
   44.20  
   44.21 @@ -873,7 +873,7 @@
   44.22  fun lift_qelim afn nfn qfn isat = 
   44.23   let   fun qelim x vars p = 
   44.24    let val cjs = conjuncts p 
   44.25 -      val (ycjs,ncjs) = partition (has_bound) cjs in 
   44.26 +      val (ycjs,ncjs) = List.partition (has_bound) cjs in 
   44.27        (if ycjs = [] then p else 
   44.28                            let val q = (qfn vars ((HOLogic.exists_const HOLogic.intT 
   44.29  			  ) $ Abs(x,HOLogic.intT,(list_conj ycjs)))) in 
    45.1 --- a/src/HOL/Tools/Presburger/presburger.ML	Thu Mar 03 09:22:35 2005 +0100
    45.2 +++ b/src/HOL/Tools/Presburger/presburger.ML	Thu Mar 03 12:43:01 2005 +0100
    45.3 @@ -148,21 +148,21 @@
    45.4        if body_type T mem [iT, nT] 
    45.5           andalso not (ts = []) andalso forall (null o loose_bnos) ts 
    45.6        then [fm]
    45.7 -      else foldl op union ([], map getfuncs ts)
    45.8 +      else Library.foldl op union ([], map getfuncs ts)
    45.9    | (Var (_, T), ts as _ :: _) =>
   45.10        if body_type T mem [iT, nT] 
   45.11           andalso not (ts = []) andalso forall (null o loose_bnos) ts then [fm]
   45.12 -      else foldl op union ([], map getfuncs ts)
   45.13 +      else Library.foldl op union ([], map getfuncs ts)
   45.14    | (Const (s, T), ts) =>
   45.15        if (s, T) mem allowed_consts orelse not (body_type T mem [iT, nT])
   45.16 -      then foldl op union ([], map getfuncs ts)
   45.17 +      then Library.foldl op union ([], map getfuncs ts)
   45.18        else [fm]
   45.19    | (Abs (s, T, t), _) => getfuncs t
   45.20    | _ => [];
   45.21  
   45.22  
   45.23  fun abstract_pres sg fm = 
   45.24 -  foldr (fn (t, u) =>
   45.25 +  Library.foldr (fn (t, u) =>
   45.26        let val T = fastype_of t
   45.27        in all T $ Abs ("x", T, abstract_over (t, u)) end)
   45.28           (getfuncs fm, fm);
   45.29 @@ -198,7 +198,7 @@
   45.30   abstracted over.*)
   45.31   
   45.32  fun relevant ps t = (term_typed_consts t) subset allowed_consts andalso 
   45.33 -  map (fn i => snd (nth_elem (i, ps))) (loose_bnos t) @
   45.34 +  map (fn i => snd (List.nth (ps, i))) (loose_bnos t) @
   45.35    map (snd o dest_Free) (term_frees t) @ map (snd o dest_Var) (term_vars t)
   45.36    subset [iT, nT]
   45.37    andalso not (has_free_funcs t);
   45.38 @@ -217,13 +217,13 @@
   45.39          (HOLogic.all_const T $ Abs (s, T, P), n)
   45.40        else (incr_boundvars ~1 P, n-1)
   45.41      fun mk_all2 (v, t) = HOLogic.all_const (fastype_of v) $ lambda v t;
   45.42 -    val (rhs,irhs) = partition (relevant (rev ps)) hs
   45.43 +    val (rhs,irhs) = List.partition (relevant (rev ps)) hs
   45.44      val np = length ps
   45.45 -    val (fm',np) =  foldr (fn ((x, T), (fm,n)) => mk_all ((x, T), (fm,n)))
   45.46 -      (ps,(foldr HOLogic.mk_imp (rhs, c), np))
   45.47 -    val (vs, _) = partition (fn t => q orelse (type_of t) = nT)
   45.48 +    val (fm',np) =  Library.foldr (fn ((x, T), (fm,n)) => mk_all ((x, T), (fm,n)))
   45.49 +      (ps,(Library.foldr HOLogic.mk_imp (rhs, c), np))
   45.50 +    val (vs, _) = List.partition (fn t => q orelse (type_of t) = nT)
   45.51        (term_frees fm' @ term_vars fm');
   45.52 -    val fm2 = foldr mk_all2 (vs, fm')
   45.53 +    val fm2 = Library.foldr mk_all2 (vs, fm')
   45.54    in (fm2, np + length vs, length rhs) end;
   45.55  
   45.56  (*Object quantifier to meta --*)
   45.57 @@ -300,7 +300,7 @@
   45.58   in
   45.59     Method.simple_args 
   45.60    (Scan.optional (Args.$$$ "(" |-- Scan.repeat1 parse_flag --| Args.$$$ ")") [] >>
   45.61 -    curry (foldl op |>) (true, false))
   45.62 +    curry (Library.foldl op |>) (true, false))
   45.63      (fn (q,a) => fn _ => meth q a 1)
   45.64    end;
   45.65  
    46.1 --- a/src/HOL/Tools/datatype_abs_proofs.ML	Thu Mar 03 09:22:35 2005 +0100
    46.2 +++ b/src/HOL/Tools/datatype_abs_proofs.ML	Thu Mar 03 12:43:01 2005 +0100
    46.3 @@ -54,9 +54,9 @@
    46.4    let
    46.5      val _ = message "Proving case distinction theorems ...";
    46.6  
    46.7 -    val descr' = flat descr;
    46.8 +    val descr' = List.concat descr;
    46.9      val recTs = get_rec_types descr' sorts;
   46.10 -    val newTs = take (length (hd descr), recTs);
   46.11 +    val newTs = Library.take (length (hd descr), recTs);
   46.12  
   46.13      val {maxidx, ...} = rep_thm induct;
   46.14      val induct_Ps = map head_of (HOLogic.dest_conj (HOLogic.dest_Trueprop (concl_of induct)));
   46.15 @@ -67,11 +67,11 @@
   46.16            Abs ("z", T', Const ("True", T''))) induct_Ps;
   46.17          val P = Abs ("z", T, HOLogic.imp $ HOLogic.mk_eq (Var (("a", maxidx+1), T), Bound 0) $
   46.18            Var (("P", 0), HOLogic.boolT))
   46.19 -        val insts = take (i, dummyPs) @ (P::(drop (i + 1, dummyPs)));
   46.20 +        val insts = Library.take (i, dummyPs) @ (P::(Library.drop (i + 1, dummyPs)));
   46.21          val cert = cterm_of (Theory.sign_of thy);
   46.22          val insts' = (map cert induct_Ps) ~~ (map cert insts);
   46.23 -        val induct' = refl RS ((nth_elem (i,
   46.24 -          split_conj_thm (cterm_instantiate insts' induct))) RSN (2, rev_mp))
   46.25 +        val induct' = refl RS ((List.nth
   46.26 +          (split_conj_thm (cterm_instantiate insts' induct), i)) RSN (2, rev_mp))
   46.27  
   46.28        in prove_goalw_cterm [] (cert t) (fn prems =>
   46.29          [rtac induct' 1,
   46.30 @@ -95,10 +95,10 @@
   46.31      val big_name = space_implode "_" new_type_names;
   46.32      val thy0 = add_path flat_names big_name thy;
   46.33  
   46.34 -    val descr' = flat descr;
   46.35 +    val descr' = List.concat descr;
   46.36      val recTs = get_rec_types descr' sorts;
   46.37 -    val used = foldr add_typ_tfree_names (recTs, []);
   46.38 -    val newTs = take (length (hd descr), recTs);
   46.39 +    val used = Library.foldr add_typ_tfree_names (recTs, []);
   46.40 +    val newTs = Library.take (length (hd descr), recTs);
   46.41  
   46.42      val induct_Ps = map head_of (HOLogic.dest_conj (HOLogic.dest_Trueprop (concl_of induct)));
   46.43  
   46.44 @@ -127,27 +127,27 @@
   46.45            in (case (strip_dtyp dt, strip_type U) of
   46.46               ((_, DtRec m), (Us, _)) =>
   46.47                 let
   46.48 -                 val free2 = mk_Free "y" (Us ---> nth_elem (m, rec_result_Ts)) k;
   46.49 +                 val free2 = mk_Free "y" (Us ---> List.nth (rec_result_Ts, m)) k;
   46.50                   val i = length Us
   46.51                 in (j + 1, k + 1, HOLogic.mk_Trueprop (HOLogic.list_all
   46.52                       (map (pair "x") Us, HOLogic.mk_mem (HOLogic.mk_prod
   46.53                         (app_bnds free1 i, app_bnds free2 i),
   46.54 -                         nth_elem (m, rec_sets)))) :: prems,
   46.55 +                         List.nth (rec_sets, m)))) :: prems,
   46.56                     free1::t1s, free2::t2s)
   46.57                 end
   46.58             | _ => (j + 1, k, prems, free1::t1s, t2s))
   46.59            end;
   46.60  
   46.61          val Ts = map (typ_of_dtyp descr' sorts) cargs;
   46.62 -        val (_, _, prems, t1s, t2s) = foldr mk_prem (cargs ~~ Ts, (1, 1, [], [], []))
   46.63 +        val (_, _, prems, t1s, t2s) = Library.foldr mk_prem (cargs ~~ Ts, (1, 1, [], [], []))
   46.64  
   46.65        in (rec_intr_ts @ [Logic.list_implies (prems, HOLogic.mk_Trueprop (HOLogic.mk_mem
   46.66          (HOLogic.mk_prod (list_comb (Const (cname, Ts ---> T), t1s),
   46.67 -          list_comb (nth_elem (l, rec_fns), t1s @ t2s)), set_name)))], l + 1)
   46.68 +          list_comb (List.nth (rec_fns, l), t1s @ t2s)), set_name)))], l + 1)
   46.69        end;
   46.70  
   46.71 -    val (rec_intr_ts, _) = foldl (fn (x, ((d, T), set_name)) =>
   46.72 -      foldl (make_rec_intr T set_name) (x, #3 (snd d)))
   46.73 +    val (rec_intr_ts, _) = Library.foldl (fn (x, ((d, T), set_name)) =>
   46.74 +      Library.foldl (make_rec_intr T set_name) (x, #3 (snd d)))
   46.75          (([], 0), descr' ~~ recTs ~~ rec_sets);
   46.76  
   46.77      val (thy1, {intrs = rec_intrs, elims = rec_elims, ...}) =
   46.78 @@ -163,16 +163,16 @@
   46.79        let
   46.80          val distinct_tac = (etac Pair_inject 1) THEN
   46.81            (if i < length newTs then
   46.82 -             full_simp_tac (HOL_ss addsimps (nth_elem (i, dist_rewrites))) 1
   46.83 +             full_simp_tac (HOL_ss addsimps (List.nth (dist_rewrites, i))) 1
   46.84             else full_simp_tac dist_ss 1);
   46.85  
   46.86          val inject = map (fn r => r RS iffD1)
   46.87 -          (if i < length newTs then nth_elem (i, constr_inject)
   46.88 -            else #inject (the (Symtab.lookup (dt_info, tname))));
   46.89 +          (if i < length newTs then List.nth (constr_inject, i)
   46.90 +            else #inject (valOf (Symtab.lookup (dt_info, tname))));
   46.91  
   46.92          fun mk_unique_constr_tac n ((tac, intr::intrs, j), (cname, cargs)) =
   46.93            let
   46.94 -            val k = length (filter is_rec_type cargs)
   46.95 +            val k = length (List.filter is_rec_type cargs)
   46.96  
   46.97            in (EVERY [DETERM tac,
   46.98                  REPEAT (etac ex1E 1), rtac ex1I 1,
   46.99 @@ -189,7 +189,7 @@
  46.100                intrs, j + 1)
  46.101            end;
  46.102  
  46.103 -        val (tac', intrs', _) = foldl (mk_unique_constr_tac (length constrs))
  46.104 +        val (tac', intrs', _) = Library.foldl (mk_unique_constr_tac (length constrs))
  46.105            ((tac, intrs, 0), constrs);
  46.106  
  46.107        in (tac', intrs') end;
  46.108 @@ -206,7 +206,7 @@
  46.109            ((1 upto length recTs) ~~ recTs ~~ rec_unique_ts);
  46.110          val induct' = cterm_instantiate ((map cert induct_Ps) ~~
  46.111            (map cert insts)) induct;
  46.112 -        val (tac, _) = foldl mk_unique_tac
  46.113 +        val (tac, _) = Library.foldl mk_unique_tac
  46.114            (((rtac induct' THEN_ALL_NEW ObjectLogic.atomize_tac) 1
  46.115                THEN rewtac (mk_meta_eq choice_eq), rec_intrs),
  46.116              descr' ~~ rec_elims ~~ recTs ~~ rec_result_Ts);
  46.117 @@ -255,7 +255,7 @@
  46.118    in
  46.119      thy2 |> Theory.add_path (space_implode "_" new_type_names) |>
  46.120      PureThy.add_thmss [(("recs", rec_thms), [])] |>>
  46.121 -    Theory.parent_path |> apsnd (pair reccomb_names o flat)
  46.122 +    Theory.parent_path |> apsnd (pair reccomb_names o List.concat)
  46.123    end;
  46.124  
  46.125  
  46.126 @@ -267,10 +267,10 @@
  46.127  
  46.128      val thy1 = add_path flat_names (space_implode "_" new_type_names) thy;
  46.129  
  46.130 -    val descr' = flat descr;
  46.131 +    val descr' = List.concat descr;
  46.132      val recTs = get_rec_types descr' sorts;
  46.133 -    val used = foldr add_typ_tfree_names (recTs, []);
  46.134 -    val newTs = take (length (hd descr), recTs);
  46.135 +    val used = Library.foldr add_typ_tfree_names (recTs, []);
  46.136 +    val newTs = Library.take (length (hd descr), recTs);
  46.137      val T' = TFree (variant used "'t", HOLogic.typeS);
  46.138  
  46.139      fun mk_dummyT dt = binder_types (typ_of_dtyp descr' sorts dt) ---> T';
  46.140 @@ -278,7 +278,7 @@
  46.141      val case_dummy_fns = map (fn (_, (_, _, constrs)) => map (fn (_, cargs) =>
  46.142        let
  46.143          val Ts = map (typ_of_dtyp descr' sorts) cargs;
  46.144 -        val Ts' = map mk_dummyT (filter is_rec_type cargs)
  46.145 +        val Ts' = map mk_dummyT (List.filter is_rec_type cargs)
  46.146        in Const ("arbitrary", Ts @ Ts' ---> T')
  46.147        end) constrs) descr';
  46.148  
  46.149 @@ -287,15 +287,15 @@
  46.150  
  46.151      (* define case combinators via primrec combinators *)
  46.152  
  46.153 -    val (case_defs, thy2) = foldl (fn ((defs, thy),
  46.154 +    val (case_defs, thy2) = Library.foldl (fn ((defs, thy),
  46.155        ((((i, (_, _, constrs)), T), name), recname)) =>
  46.156          let
  46.157            val (fns1, fns2) = ListPair.unzip (map (fn ((_, cargs), j) =>
  46.158              let
  46.159                val Ts = map (typ_of_dtyp descr' sorts) cargs;
  46.160 -              val Ts' = Ts @ map mk_dummyT (filter is_rec_type cargs);
  46.161 +              val Ts' = Ts @ map mk_dummyT (List.filter is_rec_type cargs);
  46.162                val frees' = map (uncurry (mk_Free "x")) (Ts' ~~ (1 upto length Ts'));
  46.163 -              val frees = take (length cargs, frees');
  46.164 +              val frees = Library.take (length cargs, frees');
  46.165                val free = mk_Free "f" (Ts ---> T') j
  46.166              in
  46.167               (free, list_abs_free (map dest_Free frees',
  46.168 @@ -303,20 +303,20 @@
  46.169              end) (constrs ~~ (1 upto length constrs)));
  46.170  
  46.171            val caseT = (map (snd o dest_Free) fns1) @ [T] ---> T';
  46.172 -          val fns = (flat (take (i, case_dummy_fns))) @
  46.173 -            fns2 @ (flat (drop (i + 1, case_dummy_fns)));
  46.174 +          val fns = (List.concat (Library.take (i, case_dummy_fns))) @
  46.175 +            fns2 @ (List.concat (Library.drop (i + 1, case_dummy_fns)));
  46.176            val reccomb = Const (recname, (map fastype_of fns) @ [T] ---> T');
  46.177            val decl = (Sign.base_name name, caseT, NoSyn);
  46.178            val def = ((Sign.base_name name) ^ "_def",
  46.179              Logic.mk_equals (list_comb (Const (name, caseT), fns1),
  46.180 -              list_comb (reccomb, (flat (take (i, case_dummy_fns))) @
  46.181 -                fns2 @ (flat (drop (i + 1, case_dummy_fns))) )));
  46.182 +              list_comb (reccomb, (List.concat (Library.take (i, case_dummy_fns))) @
  46.183 +                fns2 @ (List.concat (Library.drop (i + 1, case_dummy_fns))) )));
  46.184            val (thy', [def_thm]) = thy |>
  46.185              Theory.add_consts_i [decl] |> (PureThy.add_defs_i false o map Thm.no_attributes) [def];
  46.186  
  46.187          in (defs @ [def_thm], thy')
  46.188          end) (([], thy1), (hd descr) ~~ newTs ~~ case_names ~~
  46.189 -          (take (length newTs, reccomb_names)));
  46.190 +          (Library.take (length newTs, reccomb_names)));
  46.191  
  46.192      val case_thms = map (map (fn t => prove_goalw_cterm (case_defs @
  46.193        (map mk_meta_eq primrec_thms)) (cterm_of (Theory.sign_of thy2) t)
  46.194 @@ -338,9 +338,9 @@
  46.195    let
  46.196      val _ = message "Proving equations for case splitting ...";
  46.197  
  46.198 -    val descr' = flat descr;
  46.199 +    val descr' = List.concat descr;
  46.200      val recTs = get_rec_types descr' sorts;
  46.201 -    val newTs = take (length (hd descr), recTs);
  46.202 +    val newTs = Library.take (length (hd descr), recTs);
  46.203  
  46.204      fun prove_split_thms ((((((t1, t2), inject), dist_rewrites'),
  46.205          exhaustion), case_thms'), T) =
  46.206 @@ -372,7 +372,7 @@
  46.207  fun prove_size_thms flat_names new_type_names descr sorts reccomb_names primrec_thms thy =
  46.208    if exists (fn (_, (_, _, constrs)) => exists (fn (_, cargs) => exists (fn dt =>
  46.209      is_rec_type dt andalso not (null (fst (strip_dtyp dt)))) cargs) constrs)
  46.210 -      (flat descr)
  46.211 +      (List.concat descr)
  46.212    then
  46.213      (thy, [])
  46.214    else
  46.215 @@ -382,13 +382,13 @@
  46.216      val big_name = space_implode "_" new_type_names;
  46.217      val thy1 = add_path flat_names big_name thy;
  46.218  
  46.219 -    val descr' = flat descr;
  46.220 +    val descr' = List.concat descr;
  46.221      val recTs = get_rec_types descr' sorts;
  46.222  
  46.223      val size_name = "Nat.size";
  46.224      val size_names = replicate (length (hd descr)) size_name @
  46.225        map (Sign.full_name (Theory.sign_of thy1)) (DatatypeProp.indexify_names
  46.226 -        (map (fn T => name_of_typ T ^ "_size") (drop (length (hd descr), recTs))));
  46.227 +        (map (fn T => name_of_typ T ^ "_size") (Library.drop (length (hd descr), recTs))));
  46.228      val def_names = map (fn s => s ^ "_def") (DatatypeProp.indexify_names
  46.229        (map (fn T => name_of_typ T ^ "_size") recTs));
  46.230  
  46.231 @@ -397,20 +397,20 @@
  46.232      fun make_sizefun (_, cargs) =
  46.233        let
  46.234          val Ts = map (typ_of_dtyp descr' sorts) cargs;
  46.235 -        val k = length (filter is_rec_type cargs);
  46.236 +        val k = length (List.filter is_rec_type cargs);
  46.237          val t = if k = 0 then HOLogic.zero else
  46.238            foldl1 plus (map Bound (k - 1 downto 0) @ [HOLogic.mk_nat 1])
  46.239        in
  46.240 -        foldr (fn (T, t') => Abs ("x", T, t')) (Ts @ replicate k HOLogic.natT, t)
  46.241 +        Library.foldr (fn (T, t') => Abs ("x", T, t')) (Ts @ replicate k HOLogic.natT, t)
  46.242        end;
  46.243  
  46.244 -    val fs = flat (map (fn (_, (_, _, constrs)) => map make_sizefun constrs) descr');
  46.245 +    val fs = List.concat (map (fn (_, (_, _, constrs)) => map make_sizefun constrs) descr');
  46.246      val fTs = map fastype_of fs;
  46.247  
  46.248      val (thy', size_def_thms) = thy1 |>
  46.249        Theory.add_consts_i (map (fn (s, T) =>
  46.250          (Sign.base_name s, T --> HOLogic.natT, NoSyn))
  46.251 -          (drop (length (hd descr), size_names ~~ recTs))) |>
  46.252 +          (Library.drop (length (hd descr), size_names ~~ recTs))) |>
  46.253        (PureThy.add_defs_i true o map Thm.no_attributes) (map (fn (((s, T), def_name), rec_name) =>
  46.254          (def_name, Logic.mk_equals (Const (s, T --> HOLogic.natT),
  46.255            list_comb (Const (rec_name, fTs @ [T] ---> HOLogic.natT), fs))))
  46.256 @@ -426,7 +426,7 @@
  46.257    in
  46.258      thy' |> Theory.add_path big_name |>
  46.259      PureThy.add_thmss [(("size", size_thms), [])] |>>
  46.260 -    Theory.parent_path |> apsnd flat
  46.261 +    Theory.parent_path |> apsnd List.concat
  46.262    end;
  46.263  
  46.264  fun prove_weak_case_congs new_type_names descr sorts thy =
    47.1 --- a/src/HOL/Tools/datatype_aux.ML	Thu Mar 03 09:22:35 2005 +0100
    47.2 +++ b/src/HOL/Tools/datatype_aux.ML	Thu Mar 03 12:43:01 2005 +0100
    47.3 @@ -71,7 +71,7 @@
    47.4  fun message s = if !quiet_mode then () else writeln s;
    47.5  
    47.6  (* FIXME: move to library ? *)
    47.7 -fun foldl1 f (x::xs) = foldl f (x, xs);
    47.8 +fun foldl1 f (x::xs) = Library.foldl f (x, xs);
    47.9  
   47.10  fun add_path flat_names s = if flat_names then I else Theory.add_path s;
   47.11  fun parent_path flat_names = if flat_names then I else Theory.parent_path;
   47.12 @@ -108,7 +108,7 @@
   47.13  
   47.14  
   47.15  fun cong_tac i st = (case Logic.strip_assums_concl
   47.16 -  (nth_elem (i - 1, prems_of st)) of
   47.17 +  (List.nth (prems_of st, i - 1)) of
   47.18      _ $ (_ $ (f $ x) $ (g $ y)) =>
   47.19        let
   47.20          val cong' = lift_rule (st, i) cong;
   47.21 @@ -128,7 +128,7 @@
   47.22    let
   47.23      val ts = HOLogic.dest_conj (HOLogic.dest_Trueprop (concl_of indrule));
   47.24      val ts' = HOLogic.dest_conj (HOLogic.dest_Trueprop
   47.25 -      (Logic.strip_imp_concl (nth_elem (i - 1, prems_of st))));
   47.26 +      (Logic.strip_imp_concl (List.nth (prems_of st, i - 1))));
   47.27      val getP = if can HOLogic.dest_imp (hd ts) then
   47.28        (apfst SOME) o HOLogic.dest_imp else pair NONE;
   47.29      fun abstr (t1, t2) = (case t1 of
   47.30 @@ -148,14 +148,14 @@
   47.31  fun exh_tac exh_thm_of i state =
   47.32    let
   47.33      val sg = Thm.sign_of_thm state;
   47.34 -    val prem = nth_elem (i - 1, prems_of state);
   47.35 +    val prem = List.nth (prems_of state, i - 1);
   47.36      val params = Logic.strip_params prem;
   47.37      val (_, Type (tname, _)) = hd (rev params);
   47.38      val exhaustion = lift_rule (state, i) (exh_thm_of tname);
   47.39      val prem' = hd (prems_of exhaustion);
   47.40      val _ $ (_ $ lhs $ _) = hd (rev (Logic.strip_assums_hyp prem'));
   47.41      val exhaustion' = cterm_instantiate [(cterm_of sg (head_of lhs),
   47.42 -      cterm_of sg (foldr (fn ((_, T), t) => Abs ("z", T, t))
   47.43 +      cterm_of sg (Library.foldr (fn ((_, T), t) => Abs ("z", T, t))
   47.44          (params, Bound 0)))] exhaustion
   47.45    in compose_tac (false, exhaustion', nprems_of exhaustion) i state
   47.46    end;
   47.47 @@ -228,7 +228,7 @@
   47.48  
   47.49  fun name_of_typ (Type (s, Ts)) =
   47.50        let val s' = Sign.base_name s
   47.51 -      in space_implode "_" (filter (not o equal "") (map name_of_typ Ts) @
   47.52 +      in space_implode "_" (List.filter (not o equal "") (map name_of_typ Ts) @
   47.53          [if Syntax.is_identifier s' then s' else "x"])
   47.54        end
   47.55    | name_of_typ _ = "";
   47.56 @@ -242,9 +242,9 @@
   47.57               DtRec (find_index (curry op = tname o fst) new_dts)
   47.58             else error ("Illegal occurence of recursive type " ^ tname));
   47.59  
   47.60 -fun typ_of_dtyp descr sorts (DtTFree a) = TFree (a, the (assoc (sorts, a)))
   47.61 +fun typ_of_dtyp descr sorts (DtTFree a) = TFree (a, valOf (assoc (sorts, a)))
   47.62    | typ_of_dtyp descr sorts (DtRec i) =
   47.63 -      let val (s, ds, _) = the (assoc (descr, i))
   47.64 +      let val (s, ds, _) = valOf (assoc (descr, i))
   47.65        in Type (s, map (typ_of_dtyp descr sorts) ds) end
   47.66    | typ_of_dtyp descr sorts (DtType (s, ds)) =
   47.67        Type (s, map (typ_of_dtyp descr sorts) ds);
   47.68 @@ -252,8 +252,8 @@
   47.69  (* find all non-recursive types in datatype description *)
   47.70  
   47.71  fun get_nonrec_types descr sorts =
   47.72 -  map (typ_of_dtyp descr sorts) (foldl (fn (Ts, (_, (_, _, constrs))) =>
   47.73 -    foldl (fn (Ts', (_, cargs)) =>
   47.74 +  map (typ_of_dtyp descr sorts) (Library.foldl (fn (Ts, (_, (_, _, constrs))) =>
   47.75 +    Library.foldl (fn (Ts', (_, cargs)) =>
   47.76        filter_out is_rec_type cargs union Ts') (Ts, constrs)) ([], descr));
   47.77  
   47.78  (* get all recursive types in datatype description *)
   47.79 @@ -264,22 +264,22 @@
   47.80  (* get all branching types *)
   47.81  
   47.82  fun get_branching_types descr sorts =
   47.83 -  map (typ_of_dtyp descr sorts) (foldl (fn (Ts, (_, (_, _, constrs))) =>
   47.84 -    foldl (fn (Ts', (_, cargs)) => foldr op union (map (fst o strip_dtyp)
   47.85 +  map (typ_of_dtyp descr sorts) (Library.foldl (fn (Ts, (_, (_, _, constrs))) =>
   47.86 +    Library.foldl (fn (Ts', (_, cargs)) => Library.foldr op union (map (fst o strip_dtyp)
   47.87        cargs, Ts')) (Ts, constrs)) ([], descr));
   47.88  
   47.89 -fun get_arities descr = foldl (fn (is, (_, (_, _, constrs))) =>
   47.90 -  foldl (fn (is', (_, cargs)) => map (length o fst o strip_dtyp)
   47.91 -    (filter is_rec_type cargs) union is') (is, constrs)) ([], descr);
   47.92 +fun get_arities descr = Library.foldl (fn (is, (_, (_, _, constrs))) =>
   47.93 +  Library.foldl (fn (is', (_, cargs)) => map (length o fst o strip_dtyp)
   47.94 +    (List.filter is_rec_type cargs) union is') (is, constrs)) ([], descr);
   47.95  
   47.96  (* nonemptiness check for datatypes *)
   47.97  
   47.98  fun check_nonempty descr =
   47.99    let
  47.100 -    val descr' = flat descr;
  47.101 +    val descr' = List.concat descr;
  47.102      fun is_nonempty_dt is i =
  47.103        let
  47.104 -        val (_, _, constrs) = the (assoc (descr', i));
  47.105 +        val (_, _, constrs) = valOf (assoc (descr', i));
  47.106          fun arg_nonempty (_, DtRec i) = if i mem is then false
  47.107                else is_nonempty_dt (i::is) i
  47.108            | arg_nonempty _ = true;
  47.109 @@ -303,8 +303,8 @@
  47.110           NONE => typ_error T (tname ^ " is not a datatype - can't use it in\
  47.111             \ nested recursion")
  47.112         | (SOME {index, descr, ...}) =>
  47.113 -           let val (_, vars, _) = the (assoc (descr, index));
  47.114 -               val subst = ((map dest_DtTFree vars) ~~ dts) handle LIST _ =>
  47.115 +           let val (_, vars, _) = valOf (assoc (descr, index));
  47.116 +               val subst = ((map dest_DtTFree vars) ~~ dts) handle UnequalLengths =>
  47.117                   typ_error T ("Type constructor " ^ tname ^ " used with wrong\
  47.118                    \ number of arguments")
  47.119             in (i + index, map (fn (j, (tn, args, cs)) => (i + j,
  47.120 @@ -333,18 +333,18 @@
  47.121      (* unfold a constructor *)
  47.122  
  47.123      fun unfold_constr ((i, constrs, descrs), (cname, cargs)) =
  47.124 -      let val (i', cargs', descrs') = foldl unfold_arg ((i, [], descrs), cargs)
  47.125 +      let val (i', cargs', descrs') = Library.foldl unfold_arg ((i, [], descrs), cargs)
  47.126        in (i', constrs @ [(cname, cargs')], descrs') end;
  47.127  
  47.128      (* unfold a single datatype *)
  47.129  
  47.130      fun unfold_datatype ((i, dtypes, descrs), (j, (tname, tvars, constrs))) =
  47.131        let val (i', constrs', descrs') =
  47.132 -        foldl unfold_constr ((i, [], descrs), constrs)
  47.133 +        Library.foldl unfold_constr ((i, [], descrs), constrs)
  47.134        in (i', dtypes @ [(j, (tname, tvars, constrs'))], descrs')
  47.135        end;
  47.136  
  47.137 -    val (i', descr', descrs) = foldl unfold_datatype ((i, [],[]), descr);
  47.138 +    val (i', descr', descrs) = Library.foldl unfold_datatype ((i, [],[]), descr);
  47.139  
  47.140    in (descr' :: descrs, i') end;
  47.141  
    48.1 --- a/src/HOL/Tools/datatype_codegen.ML	Thu Mar 03 09:22:35 2005 +0100
    48.2 +++ b/src/HOL/Tools/datatype_codegen.ML	Thu Mar 03 12:43:01 2005 +0100
    48.3 @@ -17,7 +17,7 @@
    48.4  
    48.5  fun mk_tuple [p] = p
    48.6    | mk_tuple ps = Pretty.block (Pretty.str "(" ::
    48.7 -      flat (separate [Pretty.str ",", Pretty.brk 1] (map single ps)) @
    48.8 +      List.concat (separate [Pretty.str ",", Pretty.brk 1] (map single ps)) @
    48.9          [Pretty.str ")"]);
   48.10  
   48.11  (**** datatype definition ****)
   48.12 @@ -26,16 +26,16 @@
   48.13  
   48.14  fun find_nonempty (descr: DatatypeAux.descr) is i =
   48.15    let
   48.16 -    val (_, _, constrs) = the (assoc (descr, i));
   48.17 +    val (_, _, constrs) = valOf (assoc (descr, i));
   48.18      fun arg_nonempty (_, DatatypeAux.DtRec i) = if i mem is then NONE
   48.19 -          else apsome (curry op + 1 o snd) (find_nonempty descr (i::is) i)
   48.20 +          else Option.map (curry op + 1 o snd) (find_nonempty descr (i::is) i)
   48.21        | arg_nonempty _ = SOME 0;
   48.22 -    fun max xs = foldl
   48.23 +    fun max xs = Library.foldl
   48.24        (fn (NONE, _) => NONE
   48.25          | (SOME i, SOME j) => SOME (Int.max (i, j))
   48.26          | (_, NONE) => NONE) (SOME 0, xs);
   48.27      val xs = sort (int_ord o pairself snd)
   48.28 -      (mapfilter (fn (s, dts) => apsome (pair s)
   48.29 +      (List.mapPartial (fn (s, dts) => Option.map (pair s)
   48.30          (max (map (arg_nonempty o DatatypeAux.strip_dtyp) dts))) constrs)
   48.31    in case xs of [] => NONE | x :: _ => SOME x end;
   48.32  
   48.33 @@ -44,8 +44,8 @@
   48.34      val sg = sign_of thy;
   48.35      val tab = DatatypePackage.get_datatypes thy;
   48.36  
   48.37 -    val descr' = filter (can (map DatatypeAux.dest_DtTFree o #2 o snd)) descr;
   48.38 -    val rtnames = map (#1 o snd) (filter (fn (_, (_, _, cs)) =>
   48.39 +    val descr' = List.filter (can (map DatatypeAux.dest_DtTFree o #2 o snd)) descr;
   48.40 +    val rtnames = map (#1 o snd) (List.filter (fn (_, (_, _, cs)) =>
   48.41        exists (exists DatatypeAux.is_rec_type o snd) cs) descr');
   48.42  
   48.43      val (_, (_, _, (cname, _) :: _)) :: _ = descr';
   48.44 @@ -67,11 +67,11 @@
   48.45                 (if null tvs then [] else
   48.46                    [mk_tuple (map Pretty.str tvs), Pretty.str " "]) @
   48.47                 [Pretty.str (mk_type_id sg tname ^ " ="), Pretty.brk 1] @
   48.48 -               flat (separate [Pretty.brk 1, Pretty.str "| "]
   48.49 +               List.concat (separate [Pretty.brk 1, Pretty.str "| "]
   48.50                   (map (fn (cname, ps') => [Pretty.block
   48.51                     (Pretty.str (mk_const_id sg cname) ::
   48.52                      (if null ps' then [] else
   48.53 -                     flat ([Pretty.str " of", Pretty.brk 1] ::
   48.54 +                     List.concat ([Pretty.str " of", Pretty.brk 1] ::
   48.55                         separate [Pretty.str " *", Pretty.brk 1]
   48.56                           (map single ps'))))]) ps))) :: rest)
   48.57            end;
   48.58 @@ -94,7 +94,7 @@
   48.59                   else parens (Pretty.block [Pretty.str (mk_const_id sg cname),
   48.60                      Pretty.brk 1, mk_tuple args]),
   48.61                   Pretty.str " =", Pretty.brk 1] @
   48.62 -                 flat (separate [Pretty.str " $", Pretty.brk 1]
   48.63 +                 List.concat (separate [Pretty.str " $", Pretty.brk 1]
   48.64                     ([Pretty.str ("Const (\"" ^ cname ^ "\","), Pretty.brk 1,
   48.65                       mk_type false (Ts ---> T), Pretty.str ")"] ::
   48.66                      map (fn (x, U) => [Pretty.block [mk_term_of sg false U,
   48.67 @@ -108,7 +108,7 @@
   48.68              val tvs = map DatatypeAux.dest_DtTFree dts;
   48.69              val sorts = map (rpair []) tvs;
   48.70              val (cs1, cs2) =
   48.71 -              partition (exists DatatypeAux.is_rec_type o snd) cs;
   48.72 +              List.partition (exists DatatypeAux.is_rec_type o snd) cs;
   48.73              val SOME (cname, _) = find_nonempty descr [i] i;
   48.74  
   48.75              fun mk_delay p = Pretty.block
   48.76 @@ -130,7 +130,7 @@
   48.77              fun mk_choice [c] = mk_constr "(i-1)" false c
   48.78                | mk_choice cs = Pretty.block [Pretty.str "one_of",
   48.79                    Pretty.brk 1, Pretty.blk (1, Pretty.str "[" ::
   48.80 -                  flat (separate [Pretty.str ",", Pretty.fbrk]
   48.81 +                  List.concat (separate [Pretty.str ",", Pretty.fbrk]
   48.82                      (map (single o mk_delay o mk_constr "(i-1)" false) cs)) @
   48.83                    [Pretty.str "]"]), Pretty.brk 1, Pretty.str "()"];
   48.84  
   48.85 @@ -155,7 +155,7 @@
   48.86                   [Pretty.block [Pretty.str "(case", Pretty.brk 1,
   48.87                     Pretty.str "i", Pretty.brk 1, Pretty.str "of",
   48.88                     Pretty.brk 1, Pretty.str "0 =>", Pretty.brk 1,
   48.89 -                   mk_constr "0" true (cname, the (assoc (cs, cname))),
   48.90 +                   mk_constr "0" true (cname, valOf (assoc (cs, cname))),
   48.91                     Pretty.brk 1, Pretty.str "| _ =>", Pretty.brk 1,
   48.92                     mk_choice cs1, Pretty.str ")"]]
   48.93                 else [mk_choice cs2])) ::
   48.94 @@ -199,18 +199,18 @@
   48.95         invoke_codegen thy dep brack (gr, eta_expand c ts (i+1))
   48.96      else
   48.97        let
   48.98 -        val ts1 = take (i, ts);
   48.99 -        val t :: ts2 = drop (i, ts);
  48.100 -        val names = foldr add_term_names (ts1,
  48.101 -          map (fst o fst o dest_Var) (foldr add_term_vars (ts1, [])));
  48.102 -        val (Ts, dT) = split_last (take (i+1, fst (strip_type T)));
  48.103 +        val ts1 = Library.take (i, ts);
  48.104 +        val t :: ts2 = Library.drop (i, ts);
  48.105 +        val names = Library.foldr add_term_names (ts1,
  48.106 +          map (fst o fst o dest_Var) (Library.foldr add_term_vars (ts1, [])));
  48.107 +        val (Ts, dT) = split_last (Library.take (i+1, fst (strip_type T)));
  48.108  
  48.109          fun pcase gr [] [] [] = ([], gr)
  48.110            | pcase gr ((cname, cargs)::cs) (t::ts) (U::Us) =
  48.111                let
  48.112                  val j = length cargs;
  48.113                  val xs = variantlist (replicate j "x", names);
  48.114 -                val Us' = take (j, fst (strip_type U));
  48.115 +                val Us' = Library.take (j, fst (strip_type U));
  48.116                  val frees = map Free (xs ~~ Us');
  48.117                  val (gr0, cp) = invoke_codegen thy dep false
  48.118                    (gr, list_comb (Const (cname, Us' ---> dT), frees));
  48.119 @@ -222,7 +222,7 @@
  48.120                end;
  48.121  
  48.122          val (ps1, gr1) = pcase gr constrs ts1 Ts;
  48.123 -        val ps = flat (separate [Pretty.brk 1, Pretty.str "| "] ps1);
  48.124 +        val ps = List.concat (separate [Pretty.brk 1, Pretty.str "| "] ps1);
  48.125          val (gr2, p) = invoke_codegen thy dep false (gr1, t);
  48.126          val (gr3, ps2) = foldl_map (invoke_codegen thy dep true) (gr2, ts2)
  48.127        in (gr3, (if not (null ts2) andalso brack then parens else I)
  48.128 @@ -257,15 +257,15 @@
  48.129     (c as Const (s, T), ts) =>
  48.130         (case find_first (fn (_, {index, descr, case_name, ...}) =>
  48.131           s = case_name orelse
  48.132 -           is_some (assoc (#3 (the (assoc (descr, index))), s)))
  48.133 +           isSome (assoc (#3 (valOf (assoc (descr, index))), s)))
  48.134               (Symtab.dest (DatatypePackage.get_datatypes thy)) of
  48.135            NONE => NONE
  48.136          | SOME (tname, {index, descr, ...}) =>
  48.137 -           if is_some (get_assoc_code thy s T) then NONE else
  48.138 +           if isSome (get_assoc_code thy s T) then NONE else
  48.139             let val SOME (_, _, constrs) = assoc (descr, index)
  48.140             in (case (assoc (constrs, s), strip_type T) of
  48.141                 (NONE, _) => SOME (pretty_case thy gr dep brack
  48.142 -                 (#3 (the (assoc (descr, index)))) c ts)
  48.143 +                 (#3 (valOf (assoc (descr, index)))) c ts)
  48.144               | (SOME args, (_, Type _)) => SOME (pretty_constr thy
  48.145                   (fst (invoke_tycodegen thy dep false (gr, snd (strip_type T))))
  48.146                   dep brack args c ts)
  48.147 @@ -277,7 +277,7 @@
  48.148        (case Symtab.lookup (DatatypePackage.get_datatypes thy, s) of
  48.149           NONE => NONE
  48.150         | SOME {descr, ...} =>
  48.151 -           if is_some (get_assoc_type thy s) then NONE else
  48.152 +           if isSome (get_assoc_type thy s) then NONE else
  48.153             let val (gr', ps) = foldl_map
  48.154               (invoke_tycodegen thy dep false) (gr, Ts)
  48.155             in SOME (add_dt_defs thy dep gr' descr,
    49.1 --- a/src/HOL/Tools/datatype_package.ML	Thu Mar 03 09:22:35 2005 +0100
    49.2 +++ b/src/HOL/Tools/datatype_package.ML	Thu Mar 03 12:43:01 2005 +0100
    49.3 @@ -125,15 +125,15 @@
    49.4  
    49.5  fun constrs_of_sg sg tname = (case datatype_info_sg sg tname of
    49.6     SOME {index, descr, ...} =>
    49.7 -     let val (_, _, constrs) = the (assoc (descr, index))
    49.8 -     in SOME (map (fn (cname, _) => Const (cname, the (Sign.const_type sg cname))) constrs)
    49.9 +     let val (_, _, constrs) = valOf (assoc (descr, index))
   49.10 +     in SOME (map (fn (cname, _) => Const (cname, valOf (Sign.const_type sg cname))) constrs)
   49.11       end
   49.12   | _ => NONE);
   49.13  
   49.14  val constrs_of = constrs_of_sg o Theory.sign_of;
   49.15  
   49.16  fun case_const_of thy tname = (case datatype_info thy tname of
   49.17 -   SOME {case_name, ...} => SOME (Const (case_name, the (Sign.const_type
   49.18 +   SOME {case_name, ...} => SOME (Const (case_name, valOf (Sign.const_type
   49.19       (Theory.sign_of thy) case_name)))
   49.20   | _ => NONE);
   49.21  
   49.22 @@ -169,7 +169,7 @@
   49.23  fun occs_in_prems tacf vars =
   49.24    SUBGOAL (fn (Bi, i) =>
   49.25             (if  exists (fn Free (a, _) => a mem vars)
   49.26 -                      (foldr add_term_frees (#2 (strip_context Bi), []))
   49.27 +                      (Library.foldr add_term_frees (#2 (strip_context Bi), []))
   49.28               then warning "Induction variable occurs also among premises!"
   49.29               else ();
   49.30              tacf i));
   49.31 @@ -182,9 +182,9 @@
   49.32  fun prep_var (Var (ixn, _), SOME x) = SOME (ixn, x)
   49.33    | prep_var _ = NONE;
   49.34  
   49.35 -fun prep_inst (concl, xs) =	(*exception LIST*)
   49.36 +fun prep_inst (concl, xs) =	(*exception UnequalLengths *)
   49.37    let val vs = InductAttrib.vars_of concl
   49.38 -  in mapfilter prep_var (Library.drop (length vs - length xs, vs) ~~ xs) end;
   49.39 +  in List.mapPartial prep_var (Library.drop (length vs - length xs, vs) ~~ xs) end;
   49.40  
   49.41  in
   49.42  
   49.43 @@ -196,11 +196,11 @@
   49.44        (case opt_rule of
   49.45          SOME r => (r, "Induction rule")
   49.46        | NONE =>
   49.47 -          let val tn = find_tname (hd (mapfilter I (flat varss))) Bi
   49.48 +          let val tn = find_tname (hd (List.mapPartial I (List.concat varss))) Bi
   49.49            in (#induction (datatype_info_sg_err sign tn), "Induction rule for type " ^ tn) end);
   49.50  
   49.51      val concls = HOLogic.dest_concls (Thm.concl_of rule);
   49.52 -    val insts = flat (map prep_inst (concls ~~ varss)) handle LIST _ =>
   49.53 +    val insts = List.concat (map prep_inst (concls ~~ varss)) handle UnequalLengths =>
   49.54        error (rule_name ^ " has different numbers of variables");
   49.55    in occs_in_prems (inst_tac insts rule) (map #2 insts) i state end;
   49.56  
   49.57 @@ -272,20 +272,20 @@
   49.58  local
   49.59  
   49.60  fun dt_recs (DtTFree _) = []
   49.61 -  | dt_recs (DtType (_, dts)) = flat (map dt_recs dts)
   49.62 +  | dt_recs (DtType (_, dts)) = List.concat (map dt_recs dts)
   49.63    | dt_recs (DtRec i) = [i];
   49.64  
   49.65  fun dt_cases (descr: descr) (_, args, constrs) =
   49.66    let
   49.67 -    fun the_bname i = Sign.base_name (#1 (the (assoc (descr, i))));
   49.68 -    val bnames = map the_bname (distinct (flat (map dt_recs args)));
   49.69 +    fun the_bname i = Sign.base_name (#1 (valOf (assoc (descr, i))));
   49.70 +    val bnames = map the_bname (distinct (List.concat (map dt_recs args)));
   49.71    in map (fn (c, _) => space_implode "_" (Sign.base_name c :: bnames)) constrs end;
   49.72  
   49.73  
   49.74  fun induct_cases descr =
   49.75 -  DatatypeProp.indexify_names (flat (map (dt_cases descr) (map #2 descr)));
   49.76 +  DatatypeProp.indexify_names (List.concat (map (dt_cases descr) (map #2 descr)));
   49.77  
   49.78 -fun exhaust_cases descr i = dt_cases descr (the (assoc (descr, i)));
   49.79 +fun exhaust_cases descr i = dt_cases descr (valOf (assoc (descr, i)));
   49.80  
   49.81  in
   49.82  
   49.83 @@ -293,18 +293,18 @@
   49.84  
   49.85  fun mk_case_names_exhausts descr new =
   49.86    map (RuleCases.case_names o exhaust_cases descr o #1)
   49.87 -    (filter (fn ((_, (name, _, _))) => name mem_string new) descr);
   49.88 +    (List.filter (fn ((_, (name, _, _))) => name mem_string new) descr);
   49.89  
   49.90  end;
   49.91  
   49.92  fun add_rules simps case_thms size_thms rec_thms inject distinct
   49.93                    weak_case_congs cong_att =
   49.94    (#1 o PureThy.add_thmss [(("simps", simps), []),
   49.95 -    (("", flat case_thms @ size_thms @ 
   49.96 -          flat distinct  @ rec_thms), [Simplifier.simp_add_global]),
   49.97 +    (("", List.concat case_thms @ size_thms @ 
   49.98 +          List.concat distinct  @ rec_thms), [Simplifier.simp_add_global]),
   49.99      (("", size_thms @ rec_thms), [RecfunCodegen.add]),
  49.100 -    (("", flat inject),               [iff_add_global]),
  49.101 -    (("", flat distinct RL [notE]),   [Classical.safe_elim_global]),
  49.102 +    (("", List.concat inject),               [iff_add_global]),
  49.103 +    (("", List.concat distinct RL [notE]),   [Classical.safe_elim_global]),
  49.104      (("", weak_case_congs),           [cong_att])]);
  49.105  
  49.106  
  49.107 @@ -325,7 +325,7 @@
  49.108         (("", exhaustion), [InductAttrib.cases_type_global name])];
  49.109      fun unnamed_rule i =
  49.110        (("", proj i induction), [InductAttrib.induct_type_global ""]);
  49.111 -    val rules = flat (map named_rules infos) @ map unnamed_rule (length infos upto n - 1);
  49.112 +    val rules = List.concat (map named_rules infos) @ map unnamed_rule (length infos upto n - 1);
  49.113    in #1 o PureThy.add_thms rules end;
  49.114  
  49.115  
  49.116 @@ -393,7 +393,7 @@
  49.117  fun case_tr sg [t, u] =
  49.118      let
  49.119        fun case_error s name ts = raise TERM ("Error in case expression" ^
  49.120 -        if_none (apsome (curry op ^ " for datatype ") name) "" ^ ":\n" ^ s, ts);
  49.121 +        getOpt (Option.map (curry op ^ " for datatype ") name, "") ^ ":\n" ^ s, ts);
  49.122        fun dest_case1 (Const ("_case1", _) $ t $ u) = (case strip_comb t of
  49.123              (Const (s, _), ts) => (Sign.intern_const sg s, ts)
  49.124            | (Free (s, _), ts) => (Sign.intern_const sg s, ts)
  49.125 @@ -413,13 +413,13 @@
  49.126              Syntax.const "split" $ abstr (x, abstr (y, body))
  49.127          | abstr (t, _) = case_error "Illegal pattern" NONE [t];
  49.128      in case find_first (fn (_, {descr, index, ...}) =>
  49.129 -      exists (equal cname o fst) (#3 (snd (nth_elem (index, descr))))) tab of
  49.130 +      exists (equal cname o fst) (#3 (snd (List.nth (descr, index))))) tab of
  49.131          NONE => case_error ("Not a datatype constructor: " ^ cname) NONE [u]
  49.132        | SOME (tname, {descr, case_name, index, ...}) =>
  49.133          let
  49.134            val _ = if exists (equal "dummy_pattern" o fst o fst) cases' then
  49.135              case_error "Illegal occurrence of '_' dummy pattern" (SOME tname) [u] else ();
  49.136 -          val (_, (_, dts, constrs)) = nth_elem (index, descr);
  49.137 +          val (_, (_, dts, constrs)) = List.nth (descr, index);
  49.138            val sorts = map (rpair [] o dest_DtTFree) dts;
  49.139            fun find_case (cases, (s, dt)) =
  49.140              (case find_first (equal s o fst o fst) cases' of
  49.141 @@ -431,7 +431,7 @@
  49.142                   if length dt <> length vs then
  49.143                      case_error ("Wrong number of arguments for constructor " ^ s)
  49.144                        (SOME tname) vs
  49.145 -                 else (cases \ c, foldr abstr (vs, t)))
  49.146 +                 else (cases \ c, Library.foldr abstr (vs, t)))
  49.147            val (cases'', fs) = foldl_map find_case (cases', constrs)
  49.148          in case (cases'', length constrs = length cases', default) of
  49.149              ([], true, SOME _) =>
  49.150 @@ -473,7 +473,7 @@
  49.151            NONE => (body, [cname]) :: cs
  49.152          | SOME cnames => overwrite (cs, (body, cnames @ [cname])));
  49.153      val cases' = sort (int_ord o Library.swap o pairself (length o snd))
  49.154 -      (foldl count_cases ([], cases));
  49.155 +      (Library.foldl count_cases ([], cases));
  49.156      fun mk_case1 (cname, (vs, body), _) = Syntax.const "_case1" $
  49.157        list_comb (Syntax.const cname, vs) $ body;
  49.158    in
  49.159 @@ -490,7 +490,7 @@
  49.160               [("dummy_pattern", ([], default), false)]))
  49.161    end;
  49.162  
  49.163 -fun make_case_tr' case_names descr = flat (map
  49.164 +fun make_case_tr' case_names descr = List.concat (map
  49.165    (fn ((_, (_, _, constrs)), case_name) => map (rpair (case_tr' constrs))
  49.166      (NameSpace.accesses' case_name)) (descr ~~ case_names));
  49.167  
  49.168 @@ -542,7 +542,7 @@
  49.169  (********************* axiomatic introduction of datatypes ********************)
  49.170  
  49.171  fun add_and_get_axioms_atts label tnames attss ts thy =
  49.172 -  foldr (fn (((tname, atts), t), (thy', axs)) =>
  49.173 +  Library.foldr (fn (((tname, atts), t), (thy', axs)) =>
  49.174      let
  49.175        val (thy'', [ax]) = thy' |>
  49.176          Theory.add_path tname |>
  49.177 @@ -554,7 +554,7 @@
  49.178    add_and_get_axioms_atts label tnames (replicate (length tnames) []);
  49.179  
  49.180  fun add_and_get_axiomss label tnames tss thy =
  49.181 -  foldr (fn ((tname, ts), (thy', axss)) =>
  49.182 +  Library.foldr (fn ((tname, ts), (thy', axss)) =>
  49.183      let
  49.184        val (thy'', [axs]) = thy' |>
  49.185          Theory.add_path tname |>
  49.186 @@ -565,10 +565,10 @@
  49.187  fun add_datatype_axm flat_names new_type_names descr sorts types_syntax constr_syntax dt_info
  49.188      case_names_induct case_names_exhausts thy =
  49.189    let
  49.190 -    val descr' = flat descr;
  49.191 +    val descr' = List.concat descr;
  49.192      val recTs = get_rec_types descr' sorts;
  49.193 -    val used = foldr add_typ_tfree_names (recTs, []);
  49.194 -    val newTs = take (length (hd descr), recTs);
  49.195 +    val used = Library.foldr add_typ_tfree_names (recTs, []);
  49.196 +    val newTs = Library.take (length (hd descr), recTs);
  49.197  
  49.198      val no_size = exists (fn (_, (_, _, constrs)) => exists (fn (_, cargs) => exists
  49.199        (fn dt => is_rec_type dt andalso not (null (fst (strip_dtyp dt))))
  49.200 @@ -591,7 +591,7 @@
  49.201          (1 upto (length descr')));
  49.202  
  49.203      val size_names = DatatypeProp.indexify_names
  49.204 -      (map (fn T => name_of_typ T ^ "_size") (drop (length (hd descr), recTs)));
  49.205 +      (map (fn T => name_of_typ T ^ "_size") (Library.drop (length (hd descr), recTs)));
  49.206  
  49.207      val freeT = TFree (variant used "'t", HOLogic.typeS);
  49.208      val case_fn_Ts = map (fn (i, (_, _, constrs)) =>
  49.209 @@ -605,7 +605,7 @@
  49.210  
  49.211        (** new types **)
  49.212  
  49.213 -      curry (foldr (fn (((name, mx), tvs), thy') => thy' |>
  49.214 +      curry (Library.foldr (fn (((name, mx), tvs), thy') => thy' |>
  49.215            TypedefPackage.add_typedecls [(name, tvs, mx)]))
  49.216          (types_syntax ~~ tyvars) |>
  49.217        add_path flat_names (space_implode "_" new_type_names) |>
  49.218 @@ -631,12 +631,12 @@
  49.219  
  49.220        (if no_size then I else Theory.add_consts_i (map (fn (s, T) =>
  49.221          (Sign.base_name s, T --> HOLogic.natT, NoSyn))
  49.222 -          (size_names ~~ drop (length (hd descr), recTs)))) |>
  49.223 +          (size_names ~~ Library.drop (length (hd descr), recTs)))) |>
  49.224  
  49.225        (** constructors **)
  49.226  
  49.227        parent_path flat_names |>
  49.228 -      curry (foldr (fn (((((_, (_, _, constrs)), T), tname),
  49.229 +      curry (Library.foldr (fn (((((_, (_, _, constrs)), T), tname),
  49.230          constr_syntax'), thy') => thy' |>
  49.231            add_path flat_names tname |>
  49.232              Theory.add_consts_i (map (fn ((_, cargs), (cname, mx)) =>
  49.233 @@ -686,7 +686,7 @@
  49.234          exhaustion ~~ replicate (length (hd descr)) QuickAndDirty ~~ inject ~~
  49.235            nchotomys ~~ case_congs ~~ weak_case_congs);
  49.236  
  49.237 -    val simps = flat (distinct @ inject @ case_thms) @ size_thms @ rec_thms;
  49.238 +    val simps = List.concat (distinct @ inject @ case_thms) @ size_thms @ rec_thms;
  49.239      val split_thms = split ~~ split_asm;
  49.240  
  49.241      val thy12 = thy11 |>
  49.242 @@ -694,7 +694,7 @@
  49.243        Theory.add_path (space_implode "_" new_type_names) |>
  49.244        add_rules simps case_thms size_thms rec_thms inject distinct
  49.245                  weak_case_congs Simplifier.cong_add_global |> 
  49.246 -      put_datatypes (foldr Symtab.update (dt_infos, dt_info)) |>
  49.247 +      put_datatypes (Library.foldr Symtab.update (dt_infos, dt_info)) |>
  49.248        add_cases_induct dt_infos induct |>
  49.249        Theory.parent_path |>
  49.250        (#1 o store_thmss "splits" new_type_names (map (fn (x, y) => [x, y]) split_thms)) |>
  49.251 @@ -741,18 +741,18 @@
  49.252      val (thy11, size_thms) = DatatypeAbsProofs.prove_size_thms flat_names new_type_names
  49.253        descr sorts reccomb_names rec_thms thy10;
  49.254  
  49.255 -    val dt_infos = map (make_dt_info (flat descr) induct reccomb_names rec_thms)
  49.256 +    val dt_infos = map (make_dt_info (List.concat descr) induct reccomb_names rec_thms)
  49.257        ((0 upto length (hd descr) - 1) ~~ (hd descr) ~~ case_names ~~ case_thms ~~
  49.258          casedist_thms ~~ simproc_dists ~~ inject ~~ nchotomys ~~ case_congs ~~ weak_case_congs);
  49.259  
  49.260 -    val simps = flat (distinct @ inject @ case_thms) @ size_thms @ rec_thms;
  49.261 +    val simps = List.concat (distinct @ inject @ case_thms) @ size_thms @ rec_thms;
  49.262  
  49.263      val thy12 = thy11 |>
  49.264        Theory.add_advanced_trfuns ([], [], make_case_tr' case_names (hd descr), []) |>
  49.265        Theory.add_path (space_implode "_" new_type_names) |>
  49.266        add_rules simps case_thms size_thms rec_thms inject distinct
  49.267                  weak_case_congs (Simplifier.change_global_ss (op addcongs)) |> 
  49.268 -      put_datatypes (foldr Symtab.update (dt_infos, dt_info)) |>
  49.269 +      put_datatypes (Library.foldr Symtab.update (dt_infos, dt_info)) |>
  49.270        add_cases_induct dt_infos induct |>
  49.271        Theory.parent_path |>
  49.272        (#1 o store_thmss "splits" new_type_names (map (fn (x, y) => [x, y]) split_thms)) |>
  49.273 @@ -778,7 +778,7 @@
  49.274      val _ = Theory.requires thy0 "Inductive" "datatype representations";
  49.275  
  49.276      fun app_thmss srcs thy = foldl_map (fn (thy, x) => apply_theorems x thy) (thy, srcs);
  49.277 -    fun app_thm src thy = apsnd Library.hd (apply_theorems [src] thy);
  49.278 +    fun app_thm src thy = apsnd hd (apply_theorems [src] thy);
  49.279  
  49.280      val (((thy1, induction), inject), distinct) = thy0
  49.281        |> app_thmss raw_distinct
  49.282 @@ -796,7 +796,7 @@
  49.283        | get_typ t = err t;
  49.284  
  49.285      val dtnames = map get_typ (HOLogic.dest_conj (HOLogic.dest_Trueprop (Thm.concl_of induction')));
  49.286 -    val new_type_names = if_none alt_names (map fst dtnames);
  49.287 +    val new_type_names = getOpt (alt_names, map fst dtnames);
  49.288  
  49.289      fun get_constr t = (case Logic.strip_assums_concl t of
  49.290          _ $ (_ $ t') => (case head_of t' of
  49.291 @@ -854,13 +854,13 @@
  49.292        ((0 upto length descr - 1) ~~ descr ~~ case_names ~~ case_thms ~~ casedist_thms ~~
  49.293          map FewConstrs distinct ~~ inject ~~ nchotomys ~~ case_congs ~~ weak_case_congs);
  49.294  
  49.295 -    val simps = flat (distinct @ inject @ case_thms) @ size_thms @ rec_thms;
  49.296 +    val simps = List.concat (distinct @ inject @ case_thms) @ size_thms @ rec_thms;
  49.297  
  49.298      val thy11 = thy10 |>
  49.299        Theory.add_advanced_trfuns ([], [], make_case_tr' case_names descr, []) |>
  49.300        add_rules simps case_thms size_thms rec_thms inject distinct
  49.301                  weak_case_congs (Simplifier.change_global_ss (op addcongs)) |> 
  49.302 -      put_datatypes (foldr Symtab.update (dt_infos, dt_info)) |>
  49.303 +      put_datatypes (Library.foldr Symtab.update (dt_infos, dt_info)) |>
  49.304        add_cases_induct dt_infos induction' |>
  49.305        Theory.parent_path |>
  49.306        (#1 o store_thmss "splits" new_type_names (map (fn (x, y) => [x, y]) split_thms)) |>
  49.307 @@ -915,8 +915,8 @@
  49.308        let
  49.309          fun prep_constr ((constrs, constr_syntax', sorts'), (cname, cargs, mx')) =
  49.310            let
  49.311 -            val (cargs', sorts'') = foldl (prep_typ sign) (([], sorts'), cargs);
  49.312 -            val _ = (case foldr add_typ_tfree_names (cargs', []) \\ tvs of
  49.313 +            val (cargs', sorts'') = Library.foldl (prep_typ sign) (([], sorts'), cargs);
  49.314 +            val _ = (case Library.foldr add_typ_tfree_names (cargs', []) \\ tvs of
  49.315                  [] => ()
  49.316                | vs => error ("Extra type variables on rhs: " ^ commas vs))
  49.317            in (constrs @ [((if flat_names then Sign.full_name sign else
  49.318 @@ -928,7 +928,7 @@
  49.319                " of datatype " ^ tname);
  49.320  
  49.321          val (constrs', constr_syntax', sorts') =
  49.322 -          foldl prep_constr (([], [], sorts), constrs)
  49.323 +          Library.foldl prep_constr (([], [], sorts), constrs)
  49.324  
  49.325        in
  49.326          case duplicates (map fst constrs') of
  49.327 @@ -940,7 +940,7 @@
  49.328               " in datatype " ^ tname)
  49.329        end;
  49.330  
  49.331 -    val (dts', constr_syntax, sorts', i) = foldl prep_dt_spec (([], [], [], 0), dts);
  49.332 +    val (dts', constr_syntax, sorts', i) = Library.foldl prep_dt_spec (([], [], [], 0), dts);
  49.333      val sorts = sorts' @ (map (rpair (Sign.defaultS sign)) (tyvars \\ map fst sorts'));
  49.334      val dt_info = get_datatypes thy;
  49.335      val (descr, _) = unfold_datatypes sign dts' sorts dt_info dts' i;
  49.336 @@ -948,7 +948,7 @@
  49.337        if err then error ("NONEmptiness check failed for datatype " ^ s)
  49.338        else raise exn;
  49.339  
  49.340 -    val descr' = flat descr;
  49.341 +    val descr' = List.concat descr;
  49.342      val case_names_induct = mk_case_names_induct descr';
  49.343      val case_names_exhausts = mk_case_names_exhausts descr' (map #1 new_dts);
  49.344    in
    50.1 --- a/src/HOL/Tools/datatype_prop.ML	Thu Mar 03 09:22:35 2005 +0100
    50.2 +++ b/src/HOL/Tools/datatype_prop.ML	Thu Mar 03 12:43:01 2005 +0100
    50.3 @@ -64,7 +64,7 @@
    50.4  
    50.5  fun make_injs descr sorts =
    50.6    let
    50.7 -    val descr' = flat descr;
    50.8 +    val descr' = List.concat descr;
    50.9  
   50.10      fun make_inj T ((cname, cargs), injs) =
   50.11        if null cargs then injs else
   50.12 @@ -80,22 +80,22 @@
   50.13               (map HOLogic.mk_eq (frees ~~ frees')))))::injs
   50.14          end;
   50.15  
   50.16 -  in map (fn (d, T) => foldr (make_inj T) (#3 (snd d), []))
   50.17 -    ((hd descr) ~~ take (length (hd descr), get_rec_types descr' sorts))
   50.18 +  in map (fn (d, T) => Library.foldr (make_inj T) (#3 (snd d), []))
   50.19 +    ((hd descr) ~~ Library.take (length (hd descr), get_rec_types descr' sorts))
   50.20    end;
   50.21  
   50.22  (********************************* induction **********************************)
   50.23  
   50.24  fun make_ind descr sorts =
   50.25    let
   50.26 -    val descr' = flat descr;
   50.27 +    val descr' = List.concat descr;
   50.28      val recTs = get_rec_types descr' sorts;
   50.29      val pnames = if length descr' = 1 then ["P"]
   50.30        else map (fn i => "P" ^ string_of_int i) (1 upto length descr');
   50.31  
   50.32      fun make_pred i T =
   50.33        let val T' = T --> HOLogic.boolT
   50.34 -      in Free (nth_elem (i, pnames), T') end;
   50.35 +      in Free (List.nth (pnames, i), T') end;
   50.36  
   50.37      fun make_ind_prem k T (cname, cargs) =
   50.38        let
   50.39 @@ -105,11 +105,11 @@
   50.40              (make_pred (body_index dt) U $ app_bnds (Free (s, T)) (length Us)))
   50.41            end;
   50.42  
   50.43 -        val recs = filter is_rec_type cargs;
   50.44 +        val recs = List.filter is_rec_type cargs;
   50.45          val Ts = map (typ_of_dtyp descr' sorts) cargs;
   50.46          val recTs' = map (typ_of_dtyp descr' sorts) recs;
   50.47          val tnames = variantlist (make_tnames Ts, pnames);
   50.48 -        val rec_tnames = map fst (filter (is_rec_type o snd) (tnames ~~ cargs));
   50.49 +        val rec_tnames = map fst (List.filter (is_rec_type o snd) (tnames ~~ cargs));
   50.50          val frees = tnames ~~ Ts;
   50.51          val prems = map mk_prem (recs ~~ rec_tnames ~~ recTs');
   50.52  
   50.53 @@ -118,7 +118,7 @@
   50.54            list_comb (Const (cname, Ts ---> T), map Free frees))))
   50.55        end;
   50.56  
   50.57 -    val prems = flat (map (fn ((i, (_, _, constrs)), T) =>
   50.58 +    val prems = List.concat (map (fn ((i, (_, _, constrs)), T) =>
   50.59        map (make_ind_prem i T) constrs) (descr' ~~ recTs));
   50.60      val tnames = make_tnames recTs;
   50.61      val concl = HOLogic.mk_Trueprop (foldr1 (HOLogic.mk_binop "op &")
   50.62 @@ -131,7 +131,7 @@
   50.63  
   50.64  fun make_casedists descr sorts =
   50.65    let
   50.66 -    val descr' = flat descr;
   50.67 +    val descr' = List.concat descr;
   50.68  
   50.69      fun make_casedist_prem T (cname, cargs) =
   50.70        let
   50.71 @@ -149,29 +149,29 @@
   50.72        end
   50.73  
   50.74    in map make_casedist
   50.75 -    ((hd descr) ~~ take (length (hd descr), get_rec_types descr' sorts))
   50.76 +    ((hd descr) ~~ Library.take (length (hd descr), get_rec_types descr' sorts))
   50.77    end;
   50.78  
   50.79  (*************** characteristic equations for primrec combinator **************)
   50.80  
   50.81  fun make_primrec_Ts descr sorts used =
   50.82    let
   50.83 -    val descr' = flat descr;
   50.84 +    val descr' = List.concat descr;
   50.85  
   50.86      val rec_result_Ts = map TFree (variantlist (replicate (length descr') "'t", used) ~~
   50.87        replicate (length descr') HOLogic.typeS);
   50.88  
   50.89 -    val reccomb_fn_Ts = flat (map (fn (i, (_, _, constrs)) =>
   50.90 +    val reccomb_fn_Ts = List.concat (map (fn (i, (_, _, constrs)) =>
   50.91        map (fn (_, cargs) =>
   50.92          let
   50.93            val Ts = map (typ_of_dtyp descr' sorts) cargs;
   50.94 -          val recs = filter (is_rec_type o fst) (cargs ~~ Ts);
   50.95 +          val recs = List.filter (is_rec_type o fst) (cargs ~~ Ts);
   50.96  
   50.97            fun mk_argT (dt, T) =
   50.98 -            binder_types T ---> nth_elem (body_index dt, rec_result_Ts);
   50.99 +            binder_types T ---> List.nth (rec_result_Ts, body_index dt);
  50.100  
  50.101            val argTs = Ts @ map mk_argT recs
  50.102 -        in argTs ---> nth_elem (i, rec_result_Ts)
  50.103 +        in argTs ---> List.nth (rec_result_Ts, i)
  50.104          end) constrs) descr');
  50.105  
  50.106    in (rec_result_Ts, reccomb_fn_Ts) end;
  50.107 @@ -180,9 +180,9 @@
  50.108    let
  50.109      val sign = Theory.sign_of thy;
  50.110  
  50.111 -    val descr' = flat descr;
  50.112 +    val descr' = List.concat descr;
  50.113      val recTs = get_rec_types descr' sorts;
  50.114 -    val used = foldr add_typ_tfree_names (recTs, []);
  50.115 +    val used = Library.foldr add_typ_tfree_names (recTs, []);
  50.116  
  50.117      val (rec_result_Ts, reccomb_fn_Ts) = make_primrec_Ts descr sorts used;
  50.118  
  50.119 @@ -200,18 +200,18 @@
  50.120  
  50.121      fun make_primrec T comb_t ((ts, f::fs), (cname, cargs)) =
  50.122        let
  50.123 -        val recs = filter is_rec_type cargs;
  50.124 +        val recs = List.filter is_rec_type cargs;
  50.125          val Ts = map (typ_of_dtyp descr' sorts) cargs;
  50.126          val recTs' = map (typ_of_dtyp descr' sorts) recs;
  50.127          val tnames = make_tnames Ts;
  50.128 -        val rec_tnames = map fst (filter (is_rec_type o snd) (tnames ~~ cargs));
  50.129 +        val rec_tnames = map fst (List.filter (is_rec_type o snd) (tnames ~~ cargs));
  50.130          val frees = map Free (tnames ~~ Ts);
  50.131          val frees' = map Free (rec_tnames ~~ recTs');
  50.132  
  50.133          fun mk_reccomb ((dt, T), t) =
  50.134            let val (Us, U) = strip_type T
  50.135            in list_abs (map (pair "x") Us,
  50.136 -            nth_elem (body_index dt, reccombs) $ app_bnds t (length Us))
  50.137 +            List.nth (reccombs, body_index dt) $ app_bnds t (length Us))
  50.138            end;
  50.139  
  50.140          val reccombs' = map mk_reccomb (recs ~~ recTs' ~~ frees')
  50.141 @@ -221,8 +221,8 @@
  50.142           list_comb (f, frees @ reccombs')))], fs)
  50.143        end
  50.144  
  50.145 -  in fst (foldl (fn (x, ((dt, T), comb_t)) =>
  50.146 -    foldl (make_primrec T comb_t) (x, #3 (snd dt)))
  50.147 +  in fst (Library.foldl (fn (x, ((dt, T), comb_t)) =>
  50.148 +    Library.foldl (make_primrec T comb_t) (x, #3 (snd dt)))
  50.149        (([], rec_fns), descr' ~~ recTs ~~ reccombs))
  50.150    end;
  50.151  
  50.152 @@ -230,10 +230,10 @@
  50.153  
  50.154  fun make_case_combs new_type_names descr sorts thy fname =
  50.155    let
  50.156 -    val descr' = flat descr;
  50.157 +    val descr' = List.concat descr;
  50.158      val recTs = get_rec_types descr' sorts;
  50.159 -    val used = foldr add_typ_tfree_names (recTs, []);
  50.160 -    val newTs = take (length (hd descr), recTs);
  50.161 +    val used = Library.foldr add_typ_tfree_names (recTs, []);
  50.162 +    val newTs = Library.take (length (hd descr), recTs);
  50.163      val T' = TFree (variant used "'t", HOLogic.typeS);
  50.164  
  50.165      val case_fn_Ts = map (fn (i, (_, _, constrs)) =>
  50.166 @@ -254,9 +254,9 @@
  50.167  
  50.168  fun make_cases new_type_names descr sorts thy =
  50.169    let
  50.170 -    val descr' = flat descr;
  50.171 +    val descr' = List.concat descr;
  50.172      val recTs = get_rec_types descr' sorts;
  50.173 -    val newTs = take (length (hd descr), recTs);
  50.174 +    val newTs = Library.take (length (hd descr), recTs);
  50.175  
  50.176      fun make_case T comb_t ((cname, cargs), f) =
  50.177        let
  50.178 @@ -276,9 +276,9 @@
  50.179  
  50.180  fun make_distincts new_type_names descr sorts thy =
  50.181    let
  50.182 -    val descr' = flat descr;
  50.183 +    val descr' = List.concat descr;
  50.184      val recTs = get_rec_types descr' sorts;
  50.185 -    val newTs = take (length (hd descr), recTs);
  50.186 +    val newTs = Library.take (length (hd descr), recTs);
  50.187  
  50.188      (**** number of constructors < dtK : C_i ... ~= C_j ... ****)
  50.189  
  50.190 @@ -315,10 +315,10 @@
  50.191  
  50.192  fun make_splits new_type_names descr sorts thy =
  50.193    let
  50.194 -    val descr' = flat descr;
  50.195 +    val descr' = List.concat descr;
  50.196      val recTs = get_rec_types descr' sorts;
  50.197 -    val used' = foldr add_typ_tfree_names (recTs, []);
  50.198 -    val newTs = take (length (hd descr), recTs);
  50.199 +    val used' = Library.foldr add_typ_tfree_names (recTs, []);
  50.200 +    val newTs = Library.take (length (hd descr), recTs);
  50.201      val T' = TFree (variant used' "'t", HOLogic.typeS);
  50.202      val P = Free ("P", T' --> HOLogic.boolT);
  50.203  
  50.204 @@ -334,13 +334,13 @@
  50.205              val eqn = HOLogic.mk_eq (Free ("x", T),
  50.206                list_comb (Const (cname, Ts ---> T), frees));
  50.207              val P' = P $ list_comb (f, frees)
  50.208 -          in ((foldr (fn (Free (s, T), t) => HOLogic.mk_all (s, T, t))
  50.209 +          in ((Library.foldr (fn (Free (s, T), t) => HOLogic.mk_all (s, T, t))
  50.210                  (frees, HOLogic.imp $ eqn $ P'))::t1s,
  50.211 -              (foldr (fn (Free (s, T), t) => HOLogic.mk_exists (s, T, t))
  50.212 +              (Library.foldr (fn (Free (s, T), t) => HOLogic.mk_exists (s, T, t))
  50.213                  (frees, HOLogic.conj $ eqn $ (HOLogic.Not $ P')))::t2s)
  50.214            end;
  50.215  
  50.216 -        val (t1s, t2s) = foldr process_constr (constrs ~~ fs, ([], []));
  50.217 +        val (t1s, t2s) = Library.foldr process_constr (constrs ~~ fs, ([], []));
  50.218          val lhs = P $ (comb_t $ Free ("x", T))
  50.219        in
  50.220          (HOLogic.mk_Trueprop (HOLogic.mk_eq (lhs, mk_conj t1s)),
  50.221 @@ -356,13 +356,13 @@
  50.222  
  50.223  fun make_size descr sorts thy =
  50.224    let
  50.225 -    val descr' = flat descr;
  50.226 +    val descr' = List.concat descr;
  50.227      val recTs = get_rec_types descr' sorts;
  50.228  
  50.229      val size_name = "Nat.size";
  50.230      val size_names = replicate (length (hd descr)) size_name @
  50.231        map (Sign.intern_const (Theory.sign_of thy)) (indexify_names
  50.232 -        (map (fn T => name_of_typ T ^ "_size") (drop (length (hd descr), recTs))));
  50.233 +        (map (fn T => name_of_typ T ^ "_size") (Library.drop (length (hd descr), recTs))));
  50.234      val size_consts = map (fn (s, T) =>
  50.235        Const (s, T --> HOLogic.natT)) (size_names ~~ recTs);
  50.236  
  50.237 @@ -370,12 +370,12 @@
  50.238  
  50.239      fun make_size_eqn size_const T (cname, cargs) =
  50.240        let
  50.241 -        val recs = filter is_rec_type cargs;
  50.242 +        val recs = List.filter is_rec_type cargs;
  50.243          val Ts = map (typ_of_dtyp descr' sorts) cargs;
  50.244          val recTs = map (typ_of_dtyp descr' sorts) recs;
  50.245          val tnames = make_tnames Ts;
  50.246 -        val rec_tnames = map fst (filter (is_rec_type o snd) (tnames ~~ cargs));
  50.247 -        val ts = map (fn ((r, s), T) => nth_elem (dest_DtRec r, size_consts) $
  50.248 +        val rec_tnames = map fst (List.filter (is_rec_type o snd) (tnames ~~ cargs));
  50.249 +        val ts = map (fn ((r, s), T) => List.nth (size_consts, dest_DtRec r) $
  50.250            Free (s, T)) (recs ~~ rec_tnames ~~ recTs);
  50.251          val t = if ts = [] then HOLogic.zero else
  50.252            foldl1 plus (ts @ [HOLogic.mk_nat 1])
  50.253 @@ -385,7 +385,7 @@
  50.254        end
  50.255  
  50.256    in
  50.257 -    flat (map (fn (((_, (_, _, constrs)), size_const), T) =>
  50.258 +    List.concat (map (fn (((_, (_, _, constrs)), size_const), T) =>
  50.259        map (make_size_eqn size_const T) constrs) (descr' ~~ size_consts ~~ recTs))
  50.260    end;
  50.261  
  50.262 @@ -465,9 +465,9 @@
  50.263  
  50.264  fun make_nchotomys descr sorts =
  50.265    let
  50.266 -    val descr' = flat descr;
  50.267 +    val descr' = List.concat descr;
  50.268      val recTs = get_rec_types descr' sorts;
  50.269 -    val newTs = take (length (hd descr), recTs);
  50.270 +    val newTs = Library.take (length (hd descr), recTs);
  50.271  
  50.272      fun mk_eqn T (cname, cargs) =
  50.273        let
  50.274 @@ -475,7 +475,7 @@
  50.275          val tnames = variantlist (make_tnames Ts, ["v"]);
  50.276          val frees = tnames ~~ Ts
  50.277        in
  50.278 -        foldr (fn ((s, T'), t) => HOLogic.mk_exists (s, T', t))
  50.279 +        Library.foldr (fn ((s, T'), t) => HOLogic.mk_exists (s, T', t))
  50.280            (frees, HOLogic.mk_eq (Free ("v", T),
  50.281              list_comb (Const (cname, Ts ---> T), map Free frees)))
  50.282        end
    51.1 --- a/src/HOL/Tools/datatype_realizer.ML	Thu Mar 03 09:22:35 2005 +0100
    51.2 +++ b/src/HOL/Tools/datatype_realizer.ML	Thu Mar 03 12:43:01 2005 +0100
    51.3 @@ -53,23 +53,23 @@
    51.4  
    51.5      fun make_pred i T U r x =
    51.6        if i mem is then
    51.7 -        Free (nth_elem (i, pnames), T --> U --> HOLogic.boolT) $ r $ x
    51.8 -      else Free (nth_elem (i, pnames), U --> HOLogic.boolT) $ x;
    51.9 +        Free (List.nth (pnames, i), T --> U --> HOLogic.boolT) $ r $ x
   51.10 +      else Free (List.nth (pnames, i), U --> HOLogic.boolT) $ x;
   51.11  
   51.12      fun mk_all i s T t =
   51.13        if i mem is then list_all_free ([(s, T)], t) else t;
   51.14  
   51.15 -    val (prems, rec_fns) = split_list (flat (snd (foldl_map
   51.16 +    val (prems, rec_fns) = split_list (List.concat (snd (foldl_map
   51.17        (fn (j, ((i, (_, _, constrs)), T)) => foldl_map (fn (j, (cname, cargs)) =>
   51.18          let
   51.19            val Ts = map (typ_of_dtyp descr sorts) cargs;
   51.20            val tnames = variantlist (DatatypeProp.make_tnames Ts, pnames);
   51.21 -          val recs = filter (is_rec_type o fst o fst) (cargs ~~ tnames ~~ Ts);
   51.22 +          val recs = List.filter (is_rec_type o fst o fst) (cargs ~~ tnames ~~ Ts);
   51.23            val frees = tnames ~~ Ts;
   51.24  
   51.25            fun mk_prems vs [] = 
   51.26                  let
   51.27 -                  val rT = nth_elem (i, rec_result_Ts);
   51.28 +                  val rT = List.nth (rec_result_Ts, i);
   51.29                    val vs' = filter_out is_unit vs;
   51.30                    val f = mk_Free "f" (map fastype_of vs' ---> rT) j;
   51.31                    val f' = Pattern.eta_contract (list_abs_free
   51.32 @@ -83,7 +83,7 @@
   51.33                    val k = body_index dt;
   51.34                    val (Us, U) = strip_type T;
   51.35                    val i = length Us;
   51.36 -                  val rT = nth_elem (k, rec_result_Ts);
   51.37 +                  val rT = List.nth (rec_result_Ts, k);
   51.38                    val r = Free ("r" ^ s, Us ---> rT);
   51.39                    val (p, f) = mk_prems (vs @ [r]) ds
   51.40                  in (mk_all k ("r" ^ s) (Us ---> rT) (Logic.mk_implies
   51.41 @@ -107,7 +107,7 @@
   51.42        (list_comb (Const (s, fTs ---> T --> U), rec_fns) $ Bound 0) (Bound 0)))
   51.43          (descr ~~ recTs ~~ rec_result_Ts ~~ rec_names);
   51.44      val r = if null is then Extraction.nullt else
   51.45 -      foldr1 HOLogic.mk_prod (mapfilter (fn (((((i, _), T), U), s), tname) =>
   51.46 +      foldr1 HOLogic.mk_prod (List.mapPartial (fn (((((i, _), T), U), s), tname) =>
   51.47          if i mem is then SOME
   51.48            (list_comb (Const (s, fTs ---> T --> U), rec_fns) $ Free (tname, T))
   51.49          else NONE) (descr ~~ recTs ~~ rec_result_Ts ~~ rec_names ~~ tnames));
   51.50 @@ -130,22 +130,22 @@
   51.51  
   51.52      val {path, ...} = Sign.rep_sg sg;
   51.53      val ind_name = Thm.name_of_thm induction;
   51.54 -    val vs = map (fn i => nth_elem (i, pnames)) is;
   51.55 +    val vs = map (fn i => List.nth (pnames, i)) is;
   51.56      val (thy', thm') = thy
   51.57        |> Theory.absolute_path
   51.58        |> PureThy.store_thm
   51.59          ((space_implode "_" (ind_name :: vs @ ["correctness"]), thm), [])
   51.60 -      |>> Theory.add_path (NameSpace.pack (if_none path []));
   51.61 +      |>> Theory.add_path (NameSpace.pack (getOpt (path,[])));
   51.62  
   51.63      val ivs = Drule.vars_of_terms
   51.64        [Logic.varify (DatatypeProp.make_ind [descr] sorts)];
   51.65      val rvs = Drule.vars_of_terms [prop_of thm'];
   51.66      val ivs1 = map Var (filter_out (fn (_, T) =>
   51.67        tname_of (body_type T) mem ["set", "bool"]) ivs);
   51.68 -    val ivs2 = map (fn (ixn, _) => Var (ixn, the (assoc (rvs, ixn)))) ivs;
   51.69 +    val ivs2 = map (fn (ixn, _) => Var (ixn, valOf (assoc (rvs, ixn)))) ivs;
   51.70  
   51.71 -    val prf = foldr forall_intr_prf (ivs2,
   51.72 -      foldr (fn ((f, p), prf) =>
   51.73 +    val prf = Library.foldr forall_intr_prf (ivs2,
   51.74 +      Library.foldr (fn ((f, p), prf) =>
   51.75          (case head_of (strip_abs_body f) of
   51.76             Free (s, T) =>
   51.77               let val T' = Type.varifyT T
   51.78 @@ -156,7 +156,7 @@
   51.79             (rec_fns ~~ prems_of thm, Proofterm.proof_combP
   51.80               (prf_of thm', map PBound (length prems - 1 downto 0))));
   51.81  
   51.82 -    val r' = if null is then r else Logic.varify (foldr (uncurry lambda)
   51.83 +    val r' = if null is then r else Logic.varify (Library.foldr (uncurry lambda)
   51.84        (map Logic.unvarify ivs1 @ filter_out is_unit
   51.85          (map (head_of o strip_abs_body) rec_fns), r));
   51.86  
   51.87 @@ -184,7 +184,7 @@
   51.88        end;
   51.89  
   51.90      val SOME (_, _, constrs) = assoc (descr, index);
   51.91 -    val T = nth_elem (index, get_rec_types descr sorts);
   51.92 +    val T = List.nth (get_rec_types descr sorts, index);
   51.93      val (rs, prems) = split_list (map (make_casedist_prem T) constrs);
   51.94      val r = Const (case_name, map fastype_of rs ---> T --> rT);
   51.95  
   51.96 @@ -205,11 +205,11 @@
   51.97      val (thy', thm') = thy
   51.98        |> Theory.absolute_path
   51.99        |> PureThy.store_thm ((exh_name ^ "_P_correctness", thm), [])
  51.100 -      |>> Theory.add_path (NameSpace.pack (if_none path []));
  51.101 +      |>> Theory.add_path (NameSpace.pack (getOpt (path,[])));
  51.102  
  51.103      val P = Var (("P", 0), rT' --> HOLogic.boolT);
  51.104      val prf = forall_intr_prf (y, forall_intr_prf (P,
  51.105 -      foldr (fn ((p, r), prf) =>
  51.106 +      Library.foldr (fn ((p, r), prf) =>
  51.107          forall_intr_prf (Logic.varify r, AbsP ("H", SOME (Logic.varify p),
  51.108            prf))) (prems ~~ rs, Proofterm.proof_combP (prf_of thm',
  51.109              map PBound (length prems - 1 downto 0)))));
  51.110 @@ -225,8 +225,8 @@
  51.111  
  51.112  fun add_dt_realizers sorts infos thy = if !proofs < 2 then thy else
  51.113    (message "Adding realizers for induction and case analysis ..."; thy
  51.114 -   |> curry (foldr (make_ind sorts (hd infos)))
  51.115 +   |> curry (Library.foldr (make_ind sorts (hd infos)))
  51.116       (subsets 0 (length (#descr (hd infos)) - 1))
  51.117 -   |> curry (foldr (make_casedists sorts)) infos);
  51.118 +   |> curry (Library.foldr (make_casedists sorts)) infos);
  51.119  
  51.120  end;
    52.1 --- a/src/HOL/Tools/datatype_rep_proofs.ML	Thu Mar 03 09:22:35 2005 +0100
    52.2 +++ b/src/HOL/Tools/datatype_rep_proofs.ML	Thu Mar 03 12:43:01 2005 +0100
    52.3 @@ -35,7 +35,7 @@
    52.4  
    52.5  
    52.6  fun exh_thm_of (dt_info : datatype_info Symtab.table) tname =
    52.7 -  #exhaustion (the (Symtab.lookup (dt_info, tname)));
    52.8 +  #exhaustion (valOf (Symtab.lookup (dt_info, tname)));
    52.9  
   52.10  (******************************************************************************)
   52.11  
   52.12 @@ -62,7 +62,7 @@
   52.13           "In0_eq", "In1_eq", "In0_not_In1", "In1_not_In0",
   52.14           "Lim_inject", "Suml_inject", "Sumr_inject"];
   52.15  
   52.16 -    val descr' = flat descr;
   52.17 +    val descr' = List.concat descr;
   52.18  
   52.19      val big_name = space_implode "_" new_type_names;
   52.20      val thy1 = add_path flat_names big_name thy;
   52.21 @@ -78,11 +78,11 @@
   52.22      val branchT = if null branchTs then HOLogic.unitT
   52.23        else fold_bal (fn (T, U) => Type ("+", [T, U])) branchTs;
   52.24      val arities = get_arities descr' \ 0;
   52.25 -    val unneeded_vars = hd tyvars \\ foldr add_typ_tfree_names (leafTs' @ branchTs, []);
   52.26 -    val leafTs = leafTs' @ (map (fn n => TFree (n, the (assoc (sorts, n)))) unneeded_vars);
   52.27 +    val unneeded_vars = hd tyvars \\ Library.foldr add_typ_tfree_names (leafTs' @ branchTs, []);
   52.28 +    val leafTs = leafTs' @ (map (fn n => TFree (n, valOf (assoc (sorts, n)))) unneeded_vars);
   52.29      val recTs = get_rec_types descr' sorts;
   52.30 -    val newTs = take (length (hd descr), recTs);
   52.31 -    val oldTs = drop (length (hd descr), recTs);
   52.32 +    val newTs = Library.take (length (hd descr), recTs);
   52.33 +    val oldTs = Library.drop (length (hd descr), recTs);
   52.34      val sumT = if null leafTs then HOLogic.unitT
   52.35        else fold_bal (fn (T, U) => Type ("+", [T, U])) leafTs;
   52.36      val Univ_elT = HOLogic.mk_setT (Type (node_name, [sumT, branchT]));
   52.37 @@ -134,7 +134,7 @@
   52.38        in mk_inj branchT (length branchTs) (1 + find_index_eq T' branchTs)
   52.39        end;
   52.40  
   52.41 -    val mk_lim = foldr (fn (T, t) => Lim $ mk_fun_inj T (Abs ("x", T, t)));
   52.42 +    val mk_lim = Library.foldr (fn (T, t) => Lim $ mk_fun_inj T (Abs ("x", T, t)));
   52.43  
   52.44      (************** generate introduction rules for representing set **********)
   52.45  
   52.46 @@ -152,7 +152,7 @@
   52.47                    app_bnds (mk_Free "x" (Ts ---> Univ_elT) j) (length Ts)
   52.48                in (j + 1, list_all (map (pair "x") Ts,
   52.49                    HOLogic.mk_Trueprop (HOLogic.mk_mem (free_t,
   52.50 -                    Const (nth_elem (k, rep_set_names), UnivT)))) :: prems,
   52.51 +                    Const (List.nth (rep_set_names, k), UnivT)))) :: prems,
   52.52                  mk_lim (Ts, free_t) :: ts)
   52.53                end
   52.54            | _ =>
   52.55 @@ -160,7 +160,7 @@
   52.56                in (j + 1, prems, (Leaf $ mk_inj T (mk_Free "x" T j))::ts)
   52.57                end);
   52.58  
   52.59 -        val (_, prems, ts) = foldr mk_prem (cargs, (1, [], []));
   52.60 +        val (_, prems, ts) = Library.foldr mk_prem (cargs, (1, [], []));
   52.61          val concl = HOLogic.mk_Trueprop (HOLogic.mk_mem
   52.62            (mk_univ_inj ts n i, Const (s, UnivT)))
   52.63        in Logic.list_implies (prems, concl)
   52.64 @@ -168,7 +168,7 @@
   52.65  
   52.66      val consts = map (fn s => Const (s, UnivT)) rep_set_names;
   52.67  
   52.68 -    val intr_ts = flat (map (fn ((_, (_, _, constrs)), rep_set_name) =>
   52.69 +    val intr_ts = List.concat (map (fn ((_, (_, _, constrs)), rep_set_name) =>
   52.70        map (make_intr rep_set_name (length constrs))
   52.71          ((1 upto (length constrs)) ~~ constrs)) (descr' ~~ rep_set_names));
   52.72  
   52.73 @@ -179,21 +179,21 @@
   52.74  
   52.75      (********************************* typedef ********************************)
   52.76  
   52.77 -    val thy3 = add_path flat_names big_name (foldl (fn (thy, ((((name, mx), tvs), c), name')) =>
   52.78 +    val thy3 = add_path flat_names big_name (Library.foldl (fn (thy, ((((name, mx), tvs), c), name')) =>
   52.79        setmp TypedefPackage.quiet_mode true
   52.80          (TypedefPackage.add_typedef_i false (SOME name') (name, tvs, mx) c NONE
   52.81            (rtac exI 1 THEN
   52.82              QUIET_BREADTH_FIRST (has_fewer_prems 1)
   52.83              (resolve_tac rep_intrs 1))) thy |> #1)
   52.84                (parent_path flat_names thy2, types_syntax ~~ tyvars ~~
   52.85 -                (take (length newTs, consts)) ~~ new_type_names));
   52.86 +                (Library.take (length newTs, consts)) ~~ new_type_names));
   52.87  
   52.88      (*********************** definition of constructors ***********************)
   52.89  
   52.90      val big_rep_name = (space_implode "_" new_type_names) ^ "_Rep_";
   52.91      val rep_names = map (curry op ^ "Rep_") new_type_names;
   52.92      val rep_names' = map (fn i => big_rep_name ^ (string_of_int i))
   52.93 -      (1 upto (length (flat (tl descr))));
   52.94 +      (1 upto (length (List.concat (tl descr))));
   52.95      val all_rep_names = map (Sign.intern_const (Theory.sign_of thy3)) rep_names @
   52.96        map (Sign.full_name (Theory.sign_of thy3)) rep_names';
   52.97  
   52.98 @@ -211,12 +211,12 @@
   52.99                val free_t = mk_Free "x" T j
  52.100            in (case (strip_dtyp dt, strip_type T) of
  52.101                ((_, DtRec m), (Us, U)) => (j + 1, free_t :: l_args, mk_lim (Us,
  52.102 -                Const (nth_elem (m, all_rep_names), U --> Univ_elT) $
  52.103 +                Const (List.nth (all_rep_names, m), U --> Univ_elT) $
  52.104                    app_bnds free_t (length Us)) :: r_args)
  52.105              | _ => (j + 1, free_t::l_args, (Leaf $ mk_inj T free_t)::r_args))
  52.106            end;
  52.107  
  52.108 -        val (_, l_args, r_args) = foldr constr_arg (cargs, (1, [], []));
  52.109 +        val (_, l_args, r_args) = Library.foldr constr_arg (cargs, (1, [], []));
  52.110          val constrT = (map (typ_of_dtyp descr' sorts) cargs) ---> T;
  52.111          val abs_name = Sign.intern_const (Theory.sign_of thy) ("Abs_" ^ tname);
  52.112          val rep_name = Sign.intern_const (Theory.sign_of thy) ("Rep_" ^ tname);
  52.113 @@ -243,14 +243,14 @@
  52.114            (Const (Sign.intern_const sg ("Rep_" ^ tname), T --> Univ_elT));
  52.115          val cong' = standard (cterm_instantiate [(cterm_of sg cong_f, rep_const)] arg_cong);
  52.116          val dist = standard (cterm_instantiate [(cterm_of sg distinct_f, rep_const)] distinct_lemma);
  52.117 -        val (thy', defs', eqns', _) = foldl ((make_constr_def tname T) (length constrs))
  52.118 +        val (thy', defs', eqns', _) = Library.foldl ((make_constr_def tname T) (length constrs))
  52.119            ((add_path flat_names tname thy, defs, [], 1), constrs ~~ constr_syntax)
  52.120        in
  52.121          (parent_path flat_names thy', defs', eqns @ [eqns'],
  52.122            rep_congs @ [cong'], dist_lemmas @ [dist])
  52.123        end;
  52.124  
  52.125 -    val (thy4, constr_defs, constr_rep_eqns, rep_congs, dist_lemmas) = foldl dt_constr_defs
  52.126 +    val (thy4, constr_defs, constr_rep_eqns, rep_congs, dist_lemmas) = Library.foldl dt_constr_defs
  52.127        ((thy3 |> Theory.add_consts_i iso_decls |> parent_path flat_names, [], [], [], []),
  52.128          hd descr ~~ new_type_names ~~ newTs ~~ constr_syntax);
  52.129  
  52.130 @@ -300,7 +300,7 @@
  52.131  
  52.132      val newT_iso_inj_thms = map prove_newT_iso_inj_thm
  52.133        (new_type_names ~~ newT_iso_axms ~~ newTs ~~
  52.134 -        take (length newTs, rep_set_names));
  52.135 +        Library.take (length newTs, rep_set_names));
  52.136  
  52.137      (********* isomorphisms between existing types and "unfolded" types *******)
  52.138  
  52.139 @@ -318,8 +318,8 @@
  52.140      fun make_iso_def k ks n ((fs, eqns, i), (cname, cargs)) =
  52.141        let
  52.142          val argTs = map (typ_of_dtyp descr' sorts) cargs;
  52.143 -        val T = nth_elem (k, recTs);
  52.144 -        val rep_name = nth_elem (k, all_rep_names);
  52.145 +        val T = List.nth (recTs, k);
  52.146 +        val rep_name = List.nth (all_rep_names, k);
  52.147          val rep_const = Const (rep_name, T --> Univ_elT);
  52.148          val constr = Const (cname, argTs ---> T);
  52.149  
  52.150 @@ -334,17 +334,17 @@
  52.151                     Ts @ [Us ---> Univ_elT])
  52.152                  else
  52.153                    (i2 + 1, i2', ts @ [mk_lim (Us,
  52.154 -                     Const (nth_elem (j, all_rep_names), U --> Univ_elT) $
  52.155 +                     Const (List.nth (all_rep_names, j), U --> Univ_elT) $
  52.156                         app_bnds (mk_Free "x" T' i2) (length Us))], Ts)
  52.157              | _ => (i2 + 1, i2', ts @ [Leaf $ mk_inj T' (mk_Free "x" T' i2)], Ts))
  52.158            end;
  52.159  
  52.160 -        val (i2, i2', ts, Ts) = foldl (process_arg ks) ((1, 1, [], []), cargs);
  52.161 +        val (i2, i2', ts, Ts) = Library.foldl (process_arg ks) ((1, 1, [], []), cargs);
  52.162          val xs = map (uncurry (mk_Free "x")) (argTs ~~ (1 upto (i2 - 1)));
  52.163          val ys = map (uncurry (mk_Free "y")) (Ts ~~ (1 upto (i2' - 1)));
  52.164          val f = list_abs_free (map dest_Free (xs @ ys), mk_univ_inj ts n i);
  52.165  
  52.166 -        val (_, _, ts', _) = foldl (process_arg []) ((1, 1, [], []), cargs);
  52.167 +        val (_, _, ts', _) = Library.foldl (process_arg []) ((1, 1, [], []), cargs);
  52.168          val eqn = HOLogic.mk_Trueprop (HOLogic.mk_eq
  52.169            (rep_const $ list_comb (constr, xs), mk_univ_inj ts' n i))
  52.170  
  52.171 @@ -356,16 +356,16 @@
  52.172        let
  52.173          val ks = map fst ds;
  52.174          val (_, (tname, _, _)) = hd ds;
  52.175 -        val {rec_rewrites, rec_names, ...} = the (Symtab.lookup (dt_info, tname));
  52.176 +        val {rec_rewrites, rec_names, ...} = valOf (Symtab.lookup (dt_info, tname));
  52.177  
  52.178          fun process_dt ((fs, eqns, isos), (k, (tname, _, constrs))) =
  52.179            let
  52.180 -            val (fs', eqns', _) = foldl (make_iso_def k ks (length constrs))
  52.181 +            val (fs', eqns', _) = Library.foldl (make_iso_def k ks (length constrs))
  52.182                ((fs, eqns, 1), constrs);
  52.183 -            val iso = (nth_elem (k, recTs), nth_elem (k, all_rep_names))
  52.184 +            val iso = (List.nth (recTs, k), List.nth (all_rep_names, k))
  52.185            in (fs', eqns', isos @ [iso]) end;
  52.186          
  52.187 -        val (fs, eqns, isos) = foldl process_dt (([], [], []), ds);
  52.188 +        val (fs, eqns, isos) = Library.foldl process_dt (([], [], []), ds);
  52.189          val fTs = map fastype_of fs;
  52.190          val defs = map (fn (rec_name, (T, iso_name)) => ((Sign.base_name iso_name) ^ "_def",
  52.191            equals (T --> Univ_elT) $ Const (iso_name, T --> Univ_elT) $
  52.192 @@ -380,7 +380,7 @@
  52.193  
  52.194        in (thy', char_thms' @ char_thms) end;
  52.195  
  52.196 -    val (thy5, iso_char_thms) = foldr make_iso_defs
  52.197 +    val (thy5, iso_char_thms) = Library.foldr make_iso_defs
  52.198        (tl descr, (add_path flat_names big_name thy4, []));
  52.199  
  52.200      (* prove isomorphism properties *)
  52.201 @@ -412,13 +412,13 @@
  52.202      fun prove_iso_thms (ds, (inj_thms, elem_thms)) =
  52.203        let
  52.204          val (_, (tname, _, _)) = hd ds;
  52.205 -        val {induction, ...} = the (Symtab.lookup (dt_info, tname));
  52.206 +        val {induction, ...} = valOf (Symtab.lookup (dt_info, tname));
  52.207  
  52.208          fun mk_ind_concl (i, _) =
  52.209            let
  52.210 -            val T = nth_elem (i, recTs);
  52.211 -            val Rep_t = Const (nth_elem (i, all_rep_names), T --> Univ_elT);
  52.212 -            val rep_set_name = nth_elem (i, rep_set_names)
  52.213 +            val T = List.nth (recTs, i);
  52.214 +            val Rep_t = Const (List.nth (all_rep_names, i), T --> Univ_elT);
  52.215 +            val rep_set_name = List.nth (rep_set_names, i)
  52.216            in (HOLogic.all_const T $ Abs ("y", T, HOLogic.imp $
  52.217                  HOLogic.mk_eq (Rep_t $ mk_Free "x" T i, Rep_t $ Bound 0) $
  52.218                    HOLogic.mk_eq (mk_Free "x" T i, Bound 0)),
  52.219 @@ -469,7 +469,7 @@
  52.220        in (inj_thms'' @ inj_thms, elem_thms @ (split_conj_thm elem_thm))
  52.221        end;
  52.222  
  52.223 -    val (iso_inj_thms_unfolded, iso_elem_thms) = foldr prove_iso_thms
  52.224 +    val (iso_inj_thms_unfolded, iso_elem_thms) = Library.foldr prove_iso_thms
  52.225        (tl descr, ([], map #3 newT_iso_axms));
  52.226      val iso_inj_thms = map snd newT_iso_inj_thms @ iso_inj_thms_unfolded;
  52.227  
  52.228 @@ -494,7 +494,7 @@
  52.229        iso_inj_thms_unfolded;
  52.230  
  52.231      val iso_thms = if length descr = 1 then [] else
  52.232 -      drop (length newTs, split_conj_thm
  52.233 +      Library.drop (length newTs, split_conj_thm
  52.234          (prove_goalw_cterm [] (cterm_of (Theory.sign_of thy5) iso_t) (fn _ =>
  52.235             [(indtac rep_induct THEN_ALL_NEW ObjectLogic.atomize_tac) 1,
  52.236              REPEAT (rtac TrueI 1),
  52.237 @@ -503,7 +503,7 @@
  52.238              rewrite_goals_tac (map symmetric range_eqs),
  52.239              REPEAT (EVERY
  52.240                [REPEAT (eresolve_tac ([rangeE, ex1_implies_ex RS exE] @
  52.241 -                 flat (map (mk_funs_inv o #1) newT_iso_axms)) 1),
  52.242 +                 List.concat (map (mk_funs_inv o #1) newT_iso_axms)) 1),
  52.243                 TRY (hyp_subst_tac 1),
  52.244                 rtac (sym RS range_eqI) 1,
  52.245                 resolve_tac iso_char_thms 1])])));
  52.246 @@ -513,7 +513,7 @@
  52.247        map2 (fn (r_inj, r) => f_myinv_f OF [r_inj, r RS mp])
  52.248          (iso_inj_thms_unfolded, iso_thms);
  52.249  
  52.250 -    val Abs_inverse_thms = flat (map mk_funs_inv Abs_inverse_thms');
  52.251 +    val Abs_inverse_thms = List.concat (map mk_funs_inv Abs_inverse_thms');
  52.252  
  52.253      (******************* freeness theorems for constructors *******************)
  52.254  
  52.255 @@ -596,23 +596,23 @@
  52.256  
  52.257      fun mk_indrule_lemma ((prems, concls), ((i, _), T)) =
  52.258        let
  52.259 -        val Rep_t = Const (nth_elem (i, all_rep_names), T --> Univ_elT) $
  52.260 +        val Rep_t = Const (List.nth (all_rep_names, i), T --> Univ_elT) $
  52.261            mk_Free "x" T i;
  52.262  
  52.263          val Abs_t = if i < length newTs then
  52.264              Const (Sign.intern_const (Theory.sign_of thy6)
  52.265 -              ("Abs_" ^ (nth_elem (i, new_type_names))), Univ_elT --> T)
  52.266 +              ("Abs_" ^ (List.nth (new_type_names, i))), Univ_elT --> T)
  52.267            else Const ("Inductive.myinv", [T --> Univ_elT, Univ_elT] ---> T) $
  52.268 -            Const (nth_elem (i, all_rep_names), T --> Univ_elT)
  52.269 +            Const (List.nth (all_rep_names, i), T --> Univ_elT)
  52.270  
  52.271        in (prems @ [HOLogic.imp $ HOLogic.mk_mem (Rep_t,
  52.272 -            Const (nth_elem (i, rep_set_names), UnivT)) $
  52.273 +            Const (List.nth (rep_set_names, i), UnivT)) $
  52.274                (mk_Free "P" (T --> HOLogic.boolT) (i + 1) $ (Abs_t $ Rep_t))],
  52.275            concls @ [mk_Free "P" (T --> HOLogic.boolT) (i + 1) $ mk_Free "x" T i])
  52.276        end;
  52.277  
  52.278      val (indrule_lemma_prems, indrule_lemma_concls) =
  52.279 -      foldl mk_indrule_lemma (([], []), (descr' ~~ recTs));
  52.280 +      Library.foldl mk_indrule_lemma (([], []), (descr' ~~ recTs));
  52.281  
  52.282      val cert = cterm_of (Theory.sign_of thy6);
  52.283  
    53.1 --- a/src/HOL/Tools/inductive_codegen.ML	Thu Mar 03 09:22:35 2005 +0100
    53.2 +++ b/src/HOL/Tools/inductive_codegen.ML	Thu Mar 03 12:43:01 2005 +0100
    53.3 @@ -49,12 +49,12 @@
    53.4    in (case concl_of thm of
    53.5        _ $ (Const ("op :", _) $ _ $ t) => (case head_of t of
    53.6          Const (s, _) =>
    53.7 -          let val cs = foldr add_term_consts (prems_of thm, [])
    53.8 +          let val cs = Library.foldr add_term_consts (prems_of thm, [])
    53.9            in (CodegenData.put
   53.10              {intros = Symtab.update ((s,
   53.11 -               if_none (Symtab.lookup (intros, s)) [] @ [thm]), intros),
   53.12 -             graph = foldr (uncurry (Graph.add_edge o pair s))
   53.13 -               (cs, foldl add_node (graph, s :: cs)),
   53.14 +               getOpt (Symtab.lookup (intros, s), []) @ [thm]), intros),
   53.15 +             graph = Library.foldr (uncurry (Graph.add_edge o pair s))
   53.16 +               (cs, Library.foldl add_node (graph, s :: cs)),
   53.17               eqns = eqns} thy, thm)
   53.18            end
   53.19        | _ => (warn thm; p))
   53.20 @@ -62,7 +62,7 @@
   53.21          Const (s, _) =>
   53.22            (CodegenData.put {intros = intros, graph = graph,
   53.23               eqns = Symtab.update ((s,
   53.24 -               if_none (Symtab.lookup (eqns, s)) [] @ [thm]), eqns)} thy, thm)
   53.25 +               getOpt (Symtab.lookup (eqns, s), []) @ [thm]), eqns)} thy, thm)
   53.26        | _ => (warn thm; p))
   53.27      | _ => (warn thm; p))
   53.28    end;
   53.29 @@ -77,7 +77,7 @@
   53.30          let val SOME names = find_first
   53.31            (fn xs => s mem xs) (Graph.strong_conn graph)
   53.32          in SOME (names, preprocess thy
   53.33 -          (flat (map (fn s => the (Symtab.lookup (intros, s))) names)))
   53.34 +          (List.concat (map (fn s => valOf (Symtab.lookup (intros, s))) names)))
   53.35          end
   53.36    end;
   53.37  
   53.38 @@ -117,14 +117,14 @@
   53.39    in (case (optf, strip_comb t) of
   53.40        (SOME f, (Const (name, _), args)) =>
   53.41          (case assoc (extra_fs, name) of
   53.42 -           NONE => overwrite (fs, (name, if_none
   53.43 -             (apsome (mg_factor f) (assoc (fs, name))) f))
   53.44 +           NONE => overwrite (fs, (name, getOpt
   53.45 +             (Option.map (mg_factor f) (assoc (fs, name)), f)))
   53.46           | SOME (fs', f') => (mg_factor f (FFix f');
   53.47 -             foldl (infer_factors sg extra_fs)
   53.48 -               (fs, map (apsome FFix) fs' ~~ args)))
   53.49 +             Library.foldl (infer_factors sg extra_fs)
   53.50 +               (fs, map (Option.map FFix) fs' ~~ args)))
   53.51      | (SOME f, (Var ((name, _), _), [])) =>
   53.52 -        overwrite (fs, (name, if_none
   53.53 -          (apsome (mg_factor f) (assoc (fs, name))) f))
   53.54 +        overwrite (fs, (name, getOpt
   53.55 +          (Option.map (mg_factor f) (assoc (fs, name)), f)))
   53.56      | (NONE, _) => fs
   53.57      | _ => err "Illegal term")
   53.58        handle Factors => err "Product factor mismatch in"
   53.59 @@ -139,7 +139,7 @@
   53.60  
   53.61  fun is_constrt thy =
   53.62    let
   53.63 -    val cnstrs = flat (flat (map
   53.64 +    val cnstrs = List.concat (List.concat (map
   53.65        (map (fn (_, (_, _, cs)) => map (apsnd length) cs) o #descr o snd)
   53.66        (Symtab.dest (DatatypePackage.get_datatypes thy))));
   53.67      fun check t = (case strip_comb t of
   53.68 @@ -167,11 +167,11 @@
   53.69      string_of_mode ms)) modes));
   53.70  
   53.71  val term_vs = map (fst o fst o dest_Var) o term_vars;
   53.72 -val terms_vs = distinct o flat o (map term_vs);
   53.73 +val terms_vs = distinct o List.concat o (map term_vs);
   53.74  
   53.75  (** collect all Vars in a term (with duplicates!) **)
   53.76  fun term_vTs t = map (apfst fst o dest_Var)
   53.77 -  (filter is_Var (foldl_aterms (op :: o Library.swap) ([], t)));
   53.78 +  (List.filter is_Var (foldl_aterms (op :: o Library.swap) ([], t)));
   53.79  
   53.80  fun get_args _ _ [] = ([], [])
   53.81    | get_args is i (x::xs) = (if i mem is then apfst else apsnd) (cons x)
   53.82 @@ -190,18 +190,18 @@
   53.83  fun cprod ([], ys) = []
   53.84    | cprod (x :: xs, ys) = map (pair x) ys @ cprod (xs, ys);
   53.85  
   53.86 -fun cprods xss = foldr (map op :: o cprod) (xss, [[]]);
   53.87 +fun cprods xss = Library.foldr (map op :: o cprod) (xss, [[]]);
   53.88  
   53.89  datatype mode = Mode of (int list option list * int list) * mode option list;
   53.90  
   53.91  fun modes_of modes t =
   53.92    let
   53.93 -    fun mk_modes name args = flat
   53.94 +    fun mk_modes name args = List.concat
   53.95        (map (fn (m as (iss, is)) => map (Mode o pair m) (cprods (map
   53.96          (fn (NONE, _) => [NONE]
   53.97            | (SOME js, arg) => map SOME
   53.98 -              (filter (fn Mode ((_, js'), _) => js=js') (modes_of modes arg)))
   53.99 -                (iss ~~ args)))) (the (assoc (modes, name))))
  53.100 +              (List.filter (fn Mode ((_, js'), _) => js=js') (modes_of modes arg)))
  53.101 +                (iss ~~ args)))) (valOf (assoc (modes, name))))
  53.102  
  53.103    in (case strip_comb t of
  53.104        (Const ("op =", Type (_, [T, _])), _) =>
  53.105 @@ -215,14 +215,14 @@
  53.106  datatype indprem = Prem of term list * term | Sidecond of term;
  53.107  
  53.108  fun select_mode_prem thy modes vs ps =
  53.109 -  find_first (is_some o snd) (ps ~~ map
  53.110 +  find_first (isSome o snd) (ps ~~ map
  53.111      (fn Prem (us, t) => find_first (fn Mode ((_, is), _) =>
  53.112            let
  53.113              val (in_ts, out_ts) = get_args is 1 us;
  53.114 -            val (out_ts', in_ts') = partition (is_constrt thy) out_ts;
  53.115 -            val vTs = flat (map term_vTs out_ts');
  53.116 +            val (out_ts', in_ts') = List.partition (is_constrt thy) out_ts;
  53.117 +            val vTs = List.concat (map term_vTs out_ts');
  53.118              val dupTs = map snd (duplicates vTs) @
  53.119 -              mapfilter (curry assoc vTs) vs;
  53.120 +              List.mapPartial (curry assoc vTs) vs;
  53.121            in
  53.122              terms_vs (in_ts @ in_ts') subset vs andalso
  53.123              forall (is_eqT o fastype_of) in_ts' andalso
  53.124 @@ -235,7 +235,7 @@
  53.125  
  53.126  fun check_mode_clause thy arg_vs modes (iss, is) (ts, ps) =
  53.127    let
  53.128 -    val modes' = modes @ mapfilter
  53.129 +    val modes' = modes @ List.mapPartial
  53.130        (fn (_, NONE) => NONE | (v, SOME js) => SOME (v, [([], js)]))
  53.131          (arg_vs ~~ iss);
  53.132      fun check_mode_prems vs [] = SOME vs
  53.133 @@ -244,11 +244,11 @@
  53.134          | SOME (x, _) => check_mode_prems
  53.135              (case x of Prem (us, _) => vs union terms_vs us | _ => vs)
  53.136              (filter_out (equal x) ps));
  53.137 -    val (in_ts, in_ts') = partition (is_constrt thy) (fst (get_args is 1 ts));
  53.138 +    val (in_ts, in_ts') = List.partition (is_constrt thy) (fst (get_args is 1 ts));
  53.139      val in_vs = terms_vs in_ts;
  53.140      val concl_vs = terms_vs ts
  53.141    in
  53.142 -    forall is_eqT (map snd (duplicates (flat (map term_vTs in_ts)))) andalso
  53.143 +    forall is_eqT (map snd (duplicates (List.concat (map term_vTs in_ts)))) andalso
  53.144      forall (is_eqT o fastype_of) in_ts' andalso
  53.145      (case check_mode_prems (arg_vs union in_vs) ps of
  53.146         NONE => false
  53.147 @@ -257,7 +257,7 @@
  53.148  
  53.149  fun check_modes_pred thy arg_vs preds modes (p, ms) =
  53.150    let val SOME rs = assoc (preds, p)
  53.151 -  in (p, filter (fn m => case find_index
  53.152 +  in (p, List.filter (fn m => case find_index
  53.153      (not o check_mode_clause thy arg_vs modes m) rs of
  53.154        ~1 => true
  53.155      | i => (message ("Clause " ^ string_of_int (i+1) ^ " of " ^
  53.156 @@ -283,7 +283,7 @@
  53.157    in mk_eqs x xs end;
  53.158  
  53.159  fun mk_tuple xs = Pretty.block (Pretty.str "(" ::
  53.160 -  flat (separate [Pretty.str ",", Pretty.brk 1] (map single xs)) @
  53.161 +  List.concat (separate [Pretty.str ",", Pretty.brk 1] (map single xs)) @
  53.162    [Pretty.str ")"]);
  53.163  
  53.164  (* convert nested pairs to n-tuple *)
  53.165 @@ -351,8 +351,8 @@
  53.166    | is_exhaustive _ = false;
  53.167  
  53.168  fun compile_match nvs eq_ps out_ps success_p can_fail =
  53.169 -  let val eqs = flat (separate [Pretty.str " andalso", Pretty.brk 1]
  53.170 -    (map single (flat (map (mk_eq o snd) nvs) @ eq_ps)));
  53.171 +  let val eqs = List.concat (separate [Pretty.str " andalso", Pretty.brk 1]
  53.172 +    (map single (List.concat (map (mk_eq o snd) nvs) @ eq_ps)));
  53.173    in
  53.174      Pretty.block
  53.175       ([Pretty.str "(fn ", mk_tuple out_ps, Pretty.str " =>", Pretty.brk 1] @
  53.176 @@ -367,7 +367,7 @@
  53.177  
  53.178  fun modename thy s (iss, is) = space_implode "__"
  53.179    (mk_const_id (sign_of thy) s ::
  53.180 -    map (space_implode "_" o map string_of_int) (mapfilter I iss @ [is]));
  53.181 +    map (space_implode "_" o map string_of_int) (List.mapPartial I iss @ [is]));
  53.182  
  53.183  fun compile_expr thy dep brack (gr, (NONE, t)) =
  53.184        apsnd single (invoke_codegen thy dep brack (gr, t))
  53.185 @@ -380,13 +380,13 @@
  53.186            (compile_expr thy dep true) (gr, ms ~~ args);
  53.187        in (gr', (if brack andalso not (null ps) then
  53.188          single o parens o Pretty.block else I)
  53.189 -          (flat (separate [Pretty.brk 1]
  53.190 +          (List.concat (separate [Pretty.brk 1]
  53.191              ([Pretty.str (modename thy name mode)] :: ps))))
  53.192        end;
  53.193  
  53.194  fun compile_clause thy gr dep all_vs arg_vs modes (iss, is) (ts, ps) =
  53.195    let
  53.196 -    val modes' = modes @ mapfilter
  53.197 +    val modes' = modes @ List.mapPartial
  53.198        (fn (_, NONE) => NONE | (v, SOME js) => SOME (v, [([], js)]))
  53.199          (arg_vs ~~ iss);
  53.200  
  53.201 @@ -404,7 +404,7 @@
  53.202        foldl_map check_constrt ((all_vs, []), in_ts);
  53.203  
  53.204      fun is_ind t = (case head_of t of
  53.205 -          Const (s, _) => s = "op =" orelse is_some (assoc (modes, s))
  53.206 +          Const (s, _) => s = "op =" orelse isSome (assoc (modes, s))
  53.207          | Var ((s, _), _) => s mem arg_vs);
  53.208  
  53.209      fun compile_prems out_ts' vs names gr [] =
  53.210 @@ -426,7 +426,7 @@
  53.211            end
  53.212        | compile_prems out_ts vs names gr ps =
  53.213            let
  53.214 -            val vs' = distinct (flat (vs :: map term_vs out_ts));
  53.215 +            val vs' = distinct (List.concat (vs :: map term_vs out_ts));
  53.216              val SOME (p, mode as SOME (Mode ((_, js), _))) =
  53.217                select_mode_prem thy modes' vs' ps;
  53.218              val ps' = filter_out (equal p) ps;
  53.219 @@ -484,16 +484,16 @@
  53.220           (Pretty.str (prfx ^ modename thy s mode) :: map Pretty.str arg_vs) @
  53.221           [Pretty.str " inp ="]),
  53.222          Pretty.brk 1] @
  53.223 -       flat (separate [Pretty.str " ++", Pretty.brk 1] (map single cl_ps))))
  53.224 +       List.concat (separate [Pretty.str " ++", Pretty.brk 1] (map single cl_ps))))
  53.225    end;
  53.226  
  53.227  fun compile_preds thy gr dep all_vs arg_vs modes preds =
  53.228    let val ((gr', _), prs) = foldl_map (fn ((gr, prfx), (s, cls)) =>
  53.229      foldl_map (fn ((gr', prfx'), mode) =>
  53.230        compile_pred thy gr' dep prfx' all_vs arg_vs modes s cls mode)
  53.231 -        ((gr, prfx), the (assoc (modes, s)))) ((gr, "fun "), preds)
  53.232 +        ((gr, prfx), valOf (assoc (modes, s)))) ((gr, "fun "), preds)
  53.233    in
  53.234 -    (gr', space_implode "\n\n" (map Pretty.string_of (flat prs)) ^ ";\n\n")
  53.235 +    (gr', space_implode "\n\n" (map Pretty.string_of (List.concat prs)) ^ ";\n\n")
  53.236    end;
  53.237  
  53.238  (**** processing of introduction rules ****)
  53.239 @@ -502,7 +502,7 @@
  53.240    (string * (int list option list * int list) list) list *
  53.241    (string * (int list list option list * int list list)) list;
  53.242  
  53.243 -fun lookup_modes gr dep = apfst flat (apsnd flat (ListPair.unzip
  53.244 +fun lookup_modes gr dep = apfst List.concat (apsnd List.concat (ListPair.unzip
  53.245    (map ((fn (SOME (Modes x), _) => x | _ => ([], [])) o Graph.get_node gr)
  53.246      (Graph.all_preds gr [dep]))));
  53.247  
  53.248 @@ -520,13 +520,13 @@
  53.249      | SOME xs' => xs inter xs') :: constrain cs ys;
  53.250  
  53.251  fun mk_extra_defs thy gr dep names ts =
  53.252 -  foldl (fn (gr, name) =>
  53.253 +  Library.foldl (fn (gr, name) =>
  53.254      if name mem names then gr
  53.255      else (case get_clauses thy name of
  53.256          NONE => gr
  53.257        | SOME (names, intrs) =>
  53.258            mk_ind_def thy gr dep names [] [] (prep_intrs intrs)))
  53.259 -            (gr, foldr add_term_consts (ts, []))
  53.260 +            (gr, Library.foldr add_term_consts (ts, []))
  53.261  
  53.262  and mk_ind_def thy gr dep names modecs factorcs intrs =
  53.263    let val ids = map (mk_const_id (sign_of thy)) names
  53.264 @@ -534,7 +534,7 @@
  53.265      let
  53.266        val _ $ (_ $ _ $ u) = Logic.strip_imp_concl (hd intrs);
  53.267        val (_, args) = strip_comb u;
  53.268 -      val arg_vs = flat (map term_vs args);
  53.269 +      val arg_vs = List.concat (map term_vs args);
  53.270  
  53.271        fun dest_prem factors (_ $ (p as (Const ("op :", _) $ t $ u))) =
  53.272              (case assoc (factors, case head_of u of
  53.273 @@ -551,11 +551,11 @@
  53.274            val Const (name, _) = head_of u;
  53.275            val prems = map (dest_prem factors) (Logic.strip_imp_prems intr);
  53.276          in
  53.277 -          (overwrite (clauses, (name, if_none (assoc (clauses, name)) [] @
  53.278 -             [(split_prod [] (the (assoc (factors, name))) t, prems)])))
  53.279 +          (overwrite (clauses, (name, getOpt (assoc (clauses, name), []) @
  53.280 +             [(split_prod [] (valOf (assoc (factors, name))) t, prems)])))
  53.281          end;
  53.282  
  53.283 -      fun check_set (Const (s, _)) = s mem names orelse is_some (get_clauses thy s)
  53.284 +      fun check_set (Const (s, _)) = s mem names orelse isSome (get_clauses thy s)
  53.285          | check_set (Var ((s, _), _)) = s mem arg_vs
  53.286          | check_set _ = false;
  53.287  
  53.288 @@ -571,13 +571,13 @@
  53.289            (Graph.new_node (hd ids, (NONE, "")) gr)) (hd ids) names intrs;
  53.290        val (extra_modes, extra_factors) = lookup_modes gr' (hd ids);
  53.291        val fs = constrain factorcs (map (apsnd dest_factors)
  53.292 -        (foldl (add_prod_factors extra_factors) ([], flat (map (fn t =>
  53.293 +        (Library.foldl (add_prod_factors extra_factors) ([], List.concat (map (fn t =>
  53.294            Logic.strip_imp_concl t :: Logic.strip_imp_prems t) intrs))));
  53.295 -      val factors = mapfilter (fn (name, f) =>
  53.296 +      val factors = List.mapPartial (fn (name, f) =>
  53.297          if name mem arg_vs then NONE
  53.298          else SOME (name, (map (curry assoc fs) arg_vs, f))) fs;
  53.299        val clauses =
  53.300 -        foldl (add_clause (fs @ map (apsnd snd) extra_factors)) ([], intrs);
  53.301 +        Library.foldl (add_clause (fs @ map (apsnd snd) extra_factors)) ([], intrs);
  53.302        val modes = constrain modecs
  53.303          (infer_modes thy extra_modes factors arg_vs clauses);
  53.304        val _ = print_factors factors;
  53.305 @@ -606,9 +606,9 @@
  53.306             val gr1 = mk_extra_defs thy
  53.307               (mk_ind_def thy gr dep names [] [] (prep_intrs intrs)) dep names [u];
  53.308             val (modes, factors) = lookup_modes gr1 dep;
  53.309 -           val ts = split_prod [] (snd (the (assoc (factors, s)))) t;
  53.310 +           val ts = split_prod [] (snd (valOf (assoc (factors, s)))) t;
  53.311             val (ts', is) = if is_query then
  53.312 -               fst (foldl mk_mode ((([], []), 1), ts))
  53.313 +               fst (Library.foldl mk_mode ((([], []), 1), ts))
  53.314               else (ts, 1 upto length ts);
  53.315             val mode = find_mode s u modes is;
  53.316             val (gr2, in_ps) = foldl_map
  53.317 @@ -635,7 +635,7 @@
  53.318             SOME (gr2, (if brack then parens else I)
  53.319               (Pretty.block ([Pretty.str "Seq.list_of", Pretty.brk 1,
  53.320                 Pretty.str "("] @
  53.321 -               conv_ntuple' (snd (the (assoc (factors, s))))
  53.322 +               conv_ntuple' (snd (valOf (assoc (factors, s))))
  53.323                   (HOLogic.dest_setT (fastype_of u))
  53.324                   (ps @ [Pretty.brk 1, Pretty.str "()"]) @
  53.325                 [Pretty.str ")"])))
  53.326 @@ -718,7 +718,7 @@
  53.327  
  53.328  fun ?? b = if b then Seq.single () else Seq.empty;
  53.329  
  53.330 -fun ?! s = is_some (Seq.pull s);    
  53.331 +fun ?! s = isSome (Seq.pull s);    
  53.332  
  53.333  fun op_61__1 x = Seq.single x;
  53.334  
    54.1 --- a/src/HOL/Tools/inductive_package.ML	Thu Mar 03 09:22:35 2005 +0100
    54.2 +++ b/src/HOL/Tools/inductive_package.ML	Thu Mar 03 12:43:01 2005 +0100
    54.3 @@ -124,7 +124,7 @@
    54.4  fun put_inductives names info thy =
    54.5    let
    54.6      fun upd ((tab, monos), name) = (Symtab.update_new ((name, info), tab), monos);
    54.7 -    val tab_monos = foldl upd (InductiveData.get thy, names)
    54.8 +    val tab_monos = Library.foldl upd (InductiveData.get thy, names)
    54.9        handle Symtab.DUP name => error ("Duplicate definition of (co)inductive set " ^ quote name);
   54.10    in InductiveData.put tab_monos thy end;
   54.11  
   54.12 @@ -183,16 +183,16 @@
   54.13      fun varify (t, (i, ts)) =
   54.14        let val t' = map_term_types (incr_tvar (i + 1)) (#1 (Type.varify (t, [])))
   54.15        in (maxidx_of_term t', t'::ts) end;
   54.16 -    val (i, cs') = foldr varify (cs, (~1, []));
   54.17 -    val (i', intr_ts') = foldr varify (intr_ts, (i, []));
   54.18 -    val rec_consts = foldl add_term_consts_2 ([], cs');
   54.19 -    val intr_consts = foldl add_term_consts_2 ([], intr_ts');
   54.20 +    val (i, cs') = Library.foldr varify (cs, (~1, []));
   54.21 +    val (i', intr_ts') = Library.foldr varify (intr_ts, (i, []));
   54.22 +    val rec_consts = Library.foldl add_term_consts_2 ([], cs');
   54.23 +    val intr_consts = Library.foldl add_term_consts_2 ([], intr_ts');
   54.24      fun unify (env, (cname, cT)) =
   54.25 -      let val consts = map snd (filter (fn c => fst c = cname) intr_consts)
   54.26 -      in foldl (fn ((env', j'), Tp) => (Type.unify tsig (env', j') Tp))
   54.27 +      let val consts = map snd (List.filter (fn c => fst c = cname) intr_consts)
   54.28 +      in Library.foldl (fn ((env', j'), Tp) => (Type.unify tsig (env', j') Tp))
   54.29            (env, (replicate (length consts) cT) ~~ consts)
   54.30        end;
   54.31 -    val (env, _) = foldl unify ((Vartab.empty, i'), rec_consts);
   54.32 +    val (env, _) = Library.foldl unify ((Vartab.empty, i'), rec_consts);
   54.33      fun typ_subst_TVars_2 env T = let val T' = typ_subst_TVars_Vartab env T
   54.34        in if T = T' then T else typ_subst_TVars_2 env T' end;
   54.35      val subst = fst o Type.freeze_thaw o
   54.36 @@ -237,7 +237,7 @@
   54.37  
   54.38  fun mg_prod_factors ts (fs, t $ u) = if t mem ts then
   54.39          let val f = prod_factors [] u
   54.40 -        in overwrite (fs, (t, f inter if_none (assoc (fs, t)) f)) end
   54.41 +        in overwrite (fs, (t, f inter (curry getOpt) (assoc (fs, t)) f)) end
   54.42        else mg_prod_factors ts (mg_prod_factors ts (fs, t), u)
   54.43    | mg_prod_factors ts (fs, Abs (_, _, t)) = mg_prod_factors ts (fs, t)
   54.44    | mg_prod_factors ts (fs, _) = fs;
   54.45 @@ -256,7 +256,7 @@
   54.46  
   54.47  fun mk_tuple p ps (Type ("*", [T1, T2])) (tms as t::_) =
   54.48        if p mem ps then HOLogic.mk_prod (mk_tuple (1::p) ps T1 tms, 
   54.49 -        mk_tuple (2::p) ps T2 (drop (length (prodT_factors (1::p) ps T1), tms)))
   54.50 +        mk_tuple (2::p) ps T2 (Library.drop (length (prodT_factors (1::p) ps T1), tms)))
   54.51        else t
   54.52    | mk_tuple _ _ _ (t::_) = t;
   54.53  
   54.54 @@ -271,12 +271,12 @@
   54.55  
   54.56  val remove_split = rewrite_rule [split_conv RS eq_reflection];
   54.57  
   54.58 -fun split_rule_vars vs rl = standard (remove_split (foldr split_rule_var'
   54.59 +fun split_rule_vars vs rl = standard (remove_split (Library.foldr split_rule_var'
   54.60    (mg_prod_factors vs ([], Thm.prop_of rl), rl)));
   54.61  
   54.62 -fun split_rule vs rl = standard (remove_split (foldr split_rule_var'
   54.63 -  (mapfilter (fn (t as Var ((a, _), _)) =>
   54.64 -    apsome (pair t) (assoc (vs, a))) (term_vars (Thm.prop_of rl)), rl)));
   54.65 +fun split_rule vs rl = standard (remove_split (Library.foldr split_rule_var'
   54.66 +  (List.mapPartial (fn (t as Var ((a, _), _)) =>
   54.67 +    Option.map (pair t) (assoc (vs, a))) (term_vars (Thm.prop_of rl)), rl)));
   54.68  
   54.69  
   54.70  (** process rules **)
   54.71 @@ -315,7 +315,7 @@
   54.72          if u mem cs then
   54.73            if exists (Logic.occs o rpair t) cs then
   54.74              err_in_rule sg name rule "Recursion term on left of member symbol"
   54.75 -          else seq check_prem (prems ~~ aprems)
   54.76 +          else List.app check_prem (prems ~~ aprems)
   54.77          else err_in_rule sg name rule bad_concl
   54.78        | Const ("all", _) $ _ => err_in_rule sg name rule all_not_allowed
   54.79        | _ => err_in_rule sg name rule bad_concl);
   54.80 @@ -337,7 +337,7 @@
   54.81  
   54.82  fun mk_elims cs cTs params intr_ts intr_names =
   54.83    let
   54.84 -    val used = foldr add_term_names (intr_ts, []);
   54.85 +    val used = Library.foldr add_term_names (intr_ts, []);
   54.86      val [aname, pname] = variantlist (["a", "P"], used);
   54.87      val P = HOLogic.mk_Trueprop (Free (pname, HOLogic.boolT));
   54.88  
   54.89 @@ -353,9 +353,9 @@
   54.90          val a = Free (aname, T);
   54.91  
   54.92          fun mk_elim_prem (_, t, ts) =
   54.93 -          list_all_free (map dest_Free ((foldr add_term_frees (t::ts, [])) \\ params),
   54.94 +          list_all_free (map dest_Free ((Library.foldr add_term_frees (t::ts, [])) \\ params),
   54.95              Logic.list_implies (HOLogic.mk_Trueprop (HOLogic.mk_eq (a, t)) :: ts, P));
   54.96 -        val c_intrs = (filter (equal c o #1 o #1) intrs);
   54.97 +        val c_intrs = (List.filter (equal c o #1 o #1) intrs);
   54.98        in
   54.99          (Logic.list_implies (HOLogic.mk_Trueprop (HOLogic.mk_mem (a, c)) ::
  54.100            map mk_elim_prem (map #1 c_intrs), P), map #2 c_intrs)
  54.101 @@ -369,7 +369,7 @@
  54.102  
  54.103  fun mk_indrule cs cTs params intr_ts =
  54.104    let
  54.105 -    val used = foldr add_term_names (intr_ts, []);
  54.106 +    val used = Library.foldr add_term_names (intr_ts, []);
  54.107  
  54.108      (* predicates for induction rule *)
  54.109  
  54.110 @@ -407,22 +407,22 @@
  54.111            HOLogic.dest_Trueprop (Logic.strip_imp_concl r)
  54.112  
  54.113        in list_all_free (frees,
  54.114 -           Logic.list_implies (map HOLogic.mk_Trueprop (foldr mk_prem
  54.115 +           Logic.list_implies (map HOLogic.mk_Trueprop (Library.foldr mk_prem
  54.116               (map HOLogic.dest_Trueprop (Logic.strip_imp_prems r), [])),
  54.117 -               HOLogic.mk_Trueprop (the (pred_of u) $ t)))
  54.118 +               HOLogic.mk_Trueprop (valOf (pred_of u) $ t)))
  54.119        end;
  54.120  
  54.121      val ind_prems = map mk_ind_prem intr_ts;
  54.122  
  54.123 -    val factors = foldl (mg_prod_factors preds) ([], ind_prems);
  54.124 +    val factors = Library.foldl (mg_prod_factors preds) ([], ind_prems);
  54.125  
  54.126      (* make conclusions for induction rules *)
  54.127  
  54.128      fun mk_ind_concl ((c, P), (ts, x)) =
  54.129        let val T = HOLogic.dest_setT (fastype_of c);
  54.130 -          val ps = if_none (assoc (factors, P)) [];
  54.131 +          val ps = getOpt (assoc (factors, P), []);
  54.132            val Ts = prodT_factors [] ps T;
  54.133 -          val (frees, x') = foldr (fn (T', (fs, s)) =>
  54.134 +          val (frees, x') = Library.foldr (fn (T', (fs, s)) =>
  54.135              ((Free (s, T'))::fs, Symbol.bump_string s)) (Ts, ([], x));
  54.136            val tuple = mk_tuple [] ps T frees;
  54.137        in ((HOLogic.mk_binop "op -->"
  54.138 @@ -430,7 +430,7 @@
  54.139        end;
  54.140  
  54.141      val mutual_ind_concl = HOLogic.mk_Trueprop (foldr1 HOLogic.mk_conj
  54.142 -        (fst (foldr mk_ind_concl (cs ~~ preds, ([], "xa")))))
  54.143 +        (fst (Library.foldr mk_ind_concl (cs ~~ preds, ([], "xa")))))
  54.144  
  54.145    in (preds, ind_prems, mutual_ind_concl,
  54.146      map (apfst (fst o dest_Free)) factors)
  54.147 @@ -481,7 +481,7 @@
  54.148    Goals.prove_goalw_cterm []      (*NO quick_and_dirty_prove_goalw_cterm here!*)
  54.149      (Thm.cterm_of (Theory.sign_of thy) (HOLogic.mk_Trueprop
  54.150        (Const (mono_name, (setT --> setT) --> HOLogic.boolT) $ fp_fun)))
  54.151 -    (fn _ => [rtac monoI 1, REPEAT (ares_tac (flat (map mk_mono monos) @ get_monos thy) 1)]));
  54.152 +    (fn _ => [rtac monoI 1, REPEAT (ares_tac (List.concat (map mk_mono monos) @ get_monos thy) 1)]));
  54.153  
  54.154  
  54.155  (* prove introduction rules *)
  54.156 @@ -628,7 +628,7 @@
  54.157  
  54.158      val dummy = if !trace then
  54.159  		(writeln "ind_prems = ";
  54.160 -		 seq (writeln o Sign.string_of_term sign) ind_prems)
  54.161 +		 List.app (writeln o Sign.string_of_term sign) ind_prems)
  54.162  	    else ();
  54.163  
  54.164      (* make predicate for instantiation of abstract induction rule *)
  54.165 @@ -639,7 +639,7 @@
  54.166               val Type (_, [T1, T2]) = T
  54.167           in Const ("Datatype.sum.sum_case",
  54.168             [T1 --> HOLogic.boolT, T2 --> HOLogic.boolT, T] ---> HOLogic.boolT) $
  54.169 -             mk_ind_pred T1 (take (n, Ps)) $ mk_ind_pred T2 (drop (n, Ps))
  54.170 +             mk_ind_pred T1 (Library.take (n, Ps)) $ mk_ind_pred T2 (Library.drop (n, Ps))
  54.171           end;
  54.172  
  54.173      val ind_pred = mk_ind_pred sumT preds;
  54.174 @@ -655,7 +655,7 @@
  54.175          (HOLogic.mk_Trueprop (HOLogic.mk_eq
  54.176            (mk_vimage cs sumT (HOLogic.Collect_const sumT $ ind_pred) c,
  54.177             HOLogic.Collect_const (HOLogic.dest_setT (fastype_of c)) $
  54.178 -             nth_elem (find_index_eq c cs, preds)))))
  54.179 +             List.nth (preds, find_index_eq c cs)))))
  54.180          (fn _ => [rtac vimage_Collect 1, rewrite_goals_tac sum_case_rewrites, rtac refl 1])) cs;
  54.181  
  54.182      val raw_fp_induct = (mono RS (fp_def RS def_lfp_induct));
  54.183 @@ -707,7 +707,7 @@
  54.184  
  54.185      val fp_name = if coind then gfp_name else lfp_name;
  54.186  
  54.187 -    val used = foldr add_term_names (intr_ts, []);
  54.188 +    val used = Library.foldr add_term_names (intr_ts, []);
  54.189      val [sname, xname] = variantlist (["S", "x"], used);
  54.190  
  54.191      (* transform an introduction rule into a conjunction  *)
  54.192 @@ -723,7 +723,7 @@
  54.193          val Const ("op :", _) $ t $ u =
  54.194            HOLogic.dest_Trueprop (Logic.strip_imp_concl r)
  54.195  
  54.196 -      in foldr (fn ((x, T), P) => HOLogic.mk_exists (x, T, P))
  54.197 +      in Library.foldr (fn ((x, T), P) => HOLogic.mk_exists (x, T, P))
  54.198          (frees, foldr1 HOLogic.mk_conj
  54.199            (((HOLogic.eq_const sumT) $ Free (xname, sumT) $ (mk_inj cs sumT u t))::
  54.200              (map (subst o HOLogic.dest_Trueprop)
    55.1 --- a/src/HOL/Tools/inductive_realizer.ML	Thu Mar 03 09:22:35 2005 +0100
    55.2 +++ b/src/HOL/Tools/inductive_realizer.ML	Thu Mar 03 12:43:01 2005 +0100
    55.3 @@ -41,7 +41,7 @@
    55.4        | strip _ t = t;
    55.5    in strip (add_term_free_names (t, [])) t end;
    55.6  
    55.7 -fun relevant_vars prop = foldr (fn
    55.8 +fun relevant_vars prop = Library.foldr (fn
    55.9        (Var ((a, i), T), vs) => (case strip_type T of
   55.10          (_, Type (s, _)) => if s mem ["bool", "set"] then (a, T) :: vs else vs
   55.11        | _ => vs)
   55.12 @@ -198,13 +198,13 @@
   55.13  fun indrule_realizer thy induct raw_induct rsets params vs rec_names rss intrs dummies =
   55.14    let
   55.15      val concls = HOLogic.dest_conj (HOLogic.dest_Trueprop (concl_of raw_induct));
   55.16 -    val premss = mapfilter (fn (s, rs) => if s mem rsets then
   55.17 -      SOME (map (fn r => nth_elem (find_index_eq (prop_of r) (map prop_of intrs),
   55.18 -        prems_of raw_induct)) rs) else NONE) rss;
   55.19 -    val concls' = mapfilter (fn (s, _) => if s mem rsets then
   55.20 +    val premss = List.mapPartial (fn (s, rs) => if s mem rsets then
   55.21 +      SOME (map (fn r => List.nth (prems_of raw_induct,
   55.22 +        find_index_eq (prop_of r) (map prop_of intrs))) rs) else NONE) rss;
   55.23 +    val concls' = List.mapPartial (fn (s, _) => if s mem rsets then
   55.24          find_first (fn concl => s mem term_consts concl) concls
   55.25        else NONE) rss;
   55.26 -    val fs = flat (snd (foldl_map (fn (intrs, (prems, dummy)) =>
   55.27 +    val fs = List.concat (snd (foldl_map (fn (intrs, (prems, dummy)) =>
   55.28        let
   55.29          val (intrs1, intrs2) = splitAt (length prems, intrs);
   55.30          val fs = map (fn (rule, intr) =>
   55.31 @@ -213,9 +213,9 @@
   55.32            HOLogic.unitT --> body_type (fastype_of (hd fs))) :: fs
   55.33          else fs)
   55.34        end) (intrs, (premss ~~ dummies))));
   55.35 -    val frees = foldl Term.add_frees ([], fs);
   55.36 +    val frees = Library.foldl Term.add_frees ([], fs);
   55.37      val Ts = map fastype_of fs;
   55.38 -    val rlzs = mapfilter (fn (a, concl) =>
   55.39 +    val rlzs = List.mapPartial (fn (a, concl) =>
   55.40        let val T = Extraction.etype_of thy vs [] concl
   55.41        in if T = Extraction.nullT then NONE
   55.42          else SOME (list_comb (Const (a, Ts ---> T), fs))
   55.43 @@ -225,8 +225,8 @@
   55.44        val r = foldr1 HOLogic.mk_prod rlzs;
   55.45        val x = Free ("x", Extraction.etype_of thy vs [] (hd (prems_of induct)));
   55.46        fun name_of_fn intr = "r" ^ Sign.base_name (Thm.name_of_thm intr);
   55.47 -      val r' = list_abs_free (mapfilter (fn intr =>
   55.48 -        apsome (pair (name_of_fn intr)) (assoc (frees, name_of_fn intr))) intrs,
   55.49 +      val r' = list_abs_free (List.mapPartial (fn intr =>
   55.50 +        Option.map (pair (name_of_fn intr)) (assoc (frees, name_of_fn intr))) intrs,
   55.51            if length concls = 1 then r $ x else r)
   55.52      in
   55.53        if length concls = 1 then lambda x r' else r'
   55.54 @@ -253,7 +253,7 @@
   55.55      val xs = rev (Term.add_vars ([], prop_of rule));
   55.56      val vs1 = map Var (filter_out (fn ((a, _), _) => a mem rvs) xs);
   55.57      val rlzvs = rev (Term.add_vars ([], prop_of rrule));
   55.58 -    val vs2 = map (fn (ixn, _) => Var (ixn, the (assoc (rlzvs, ixn)))) xs;
   55.59 +    val vs2 = map (fn (ixn, _) => Var (ixn, valOf (assoc (rlzvs, ixn)))) xs;
   55.60      val rs = gen_rems (op = o pairself fst) (rlzvs, xs);
   55.61  
   55.62      fun mk_prf _ [] prf = prf
   55.63 @@ -265,8 +265,8 @@
   55.64  
   55.65    in (Thm.name_of_thm rule, (vs,
   55.66      if rt = Extraction.nullt then rt else
   55.67 -      foldr (uncurry lambda) (vs1, rt),
   55.68 -    foldr forall_intr_prf (vs2, mk_prf rs prems (Proofterm.proof_combP
   55.69 +      Library.foldr (uncurry lambda) (vs1, rt),
   55.70 +    Library.foldr forall_intr_prf (vs2, mk_prf rs prems (Proofterm.proof_combP
   55.71        (prf_of rrule, map PBound (length prems - 1 downto 0))))))
   55.72    end;
   55.73  
   55.74 @@ -274,7 +274,7 @@
   55.75    let
   55.76      val _ $ (_ $ _ $ S) = concl_of r;
   55.77      val (Const (s, _), _) = strip_comb S;
   55.78 -    val rs = if_none (assoc (rss, s)) [];
   55.79 +    val rs = getOpt (assoc (rss, s), []);
   55.80    in overwrite (rss, (s, rs @ [r])) end;
   55.81  
   55.82  fun add_ind_realizer rsets intrs induct raw_induct elims (thy, vs) =
   55.83 @@ -284,7 +284,7 @@
   55.84      val (_ $ (_ $ _ $ S)) = Logic.strip_imp_concl (prop_of (hd intrs));
   55.85      val (_, params) = strip_comb S;
   55.86      val params' = map dest_Var params;
   55.87 -    val rss = foldl add_rule ([], intrs);
   55.88 +    val rss = Library.foldl add_rule ([], intrs);
   55.89      val (prfx, _) = split_last (NameSpace.unpack (fst (hd rss)));
   55.90      val tnames = map (fn s => space_implode "_" (s ^ "T" :: vs)) rsets;
   55.91      val {path, ...} = Sign.rep_sg (sign_of thy);
   55.92 @@ -300,7 +300,7 @@
   55.93        Theory.add_arities_i (map (fn s =>
   55.94          (s, replicate ar HOLogic.typeS, HOLogic.typeS)) tnames) |>
   55.95          Extraction.add_typeof_eqns_i ty_eqs;
   55.96 -    val dts = mapfilter (fn (s, rs) => if s mem rsets then
   55.97 +    val dts = List.mapPartial (fn (s, rs) => if s mem rsets then
   55.98        SOME (dt_of_intrs thy1' vs rs) else NONE) rss;
   55.99  
  55.100      (** datatype representing computational content of inductive set **)
  55.101 @@ -311,7 +311,7 @@
  55.102            (map #2 dts)) (map (pair false) dts) []) |>>
  55.103        Extraction.add_typeof_eqns_i ty_eqs |>>
  55.104        Extraction.add_realizes_eqns_i rlz_eqs;
  55.105 -    fun get f x = if_none (apsome f x) [];
  55.106 +    fun get f x = getOpt (Option.map f x, []);
  55.107      val rec_names = distinct (map (fst o dest_Const o head_of o fst o
  55.108        HOLogic.dest_eq o HOLogic.dest_Trueprop o prop_of) (get #rec_thms dt_info));
  55.109      val (_, constrss) = foldl_map (fn ((recs, dummies), (s, rs)) =>
  55.110 @@ -328,7 +328,7 @@
  55.111        (Extraction.realizes_of thy2 vs
  55.112          c (prop_of (forall_intr_list (map (cterm_of (sign_of thy2) o Var)
  55.113            (rev (Term.add_vars ([], prop_of intr)) \\ params')) intr))))
  55.114 -            (intrs ~~ flat constrss);
  55.115 +            (intrs ~~ List.concat constrss);
  55.116      val rlzsets = distinct (map (fn rintr => snd (HOLogic.dest_mem
  55.117        (HOLogic.dest_Trueprop (Logic.strip_assums_concl rintr)))) rintrs);
  55.118  
  55.119 @@ -345,7 +345,7 @@
  55.120  
  55.121      (** realizer for induction rule **)
  55.122  
  55.123 -    val Ps = mapfilter (fn _ $ M $ P => if set_of M mem rsets then
  55.124 +    val Ps = List.mapPartial (fn _ $ M $ P => if set_of M mem rsets then
  55.125        SOME (fst (fst (dest_Var (head_of P)))) else NONE)
  55.126          (HOLogic.dest_conj (HOLogic.dest_Trueprop (concl_of raw_induct)));
  55.127  
  55.128 @@ -383,13 +383,13 @@
  55.129        let
  55.130          val (prem :: prems) = prems_of elim;
  55.131          fun reorder1 (p, intr) =
  55.132 -          foldl (fn (t, ((s, _), T)) => all T $ lambda (Free (s, T)) t)
  55.133 +          Library.foldl (fn (t, ((s, _), T)) => all T $ lambda (Free (s, T)) t)
  55.134              (strip_all p, Term.add_vars ([], prop_of intr) \\ params');
  55.135          fun reorder2 (intr, i) =
  55.136            let
  55.137              val fs1 = term_vars (prop_of intr) \\ params;
  55.138              val fs2 = Term.add_vars ([], prop_of intr) \\ params'
  55.139 -          in foldl (fn (t, x) => lambda (Var x) t)
  55.140 +          in Library.foldl (fn (t, x) => lambda (Var x) t)
  55.141              (list_comb (Bound (i + length fs1), fs1), fs2)
  55.142            end;
  55.143          val p = Logic.list_implies
  55.144 @@ -423,24 +423,24 @@
  55.145  
  55.146      (** add realizers to theory **)
  55.147  
  55.148 -    val rintr_thms = flat (map (fn (_, rs) => map (fn r => nth_elem
  55.149 -      (find_index_eq r intrs, #intrs ind_info)) rs) rss);
  55.150 -    val thy4 = foldl add_ind_realizer (thy3, subsets Ps);
  55.151 +    val rintr_thms = List.concat (map (fn (_, rs) => map (fn r => List.nth
  55.152 +      (#intrs ind_info, find_index_eq r intrs)) rs) rss);
  55.153 +    val thy4 = Library.foldl add_ind_realizer (thy3, subsets Ps);
  55.154      val thy5 = Extraction.add_realizers_i
  55.155        (map (mk_realizer thy4 vs params')
  55.156           (map (fn ((rule, rrule), c) => ((rule, rrule), list_comb (c,
  55.157              map Var (rev (Term.add_vars ([], prop_of rule)) \\ params')))) 
  55.158 -              (flat (map snd rss) ~~ rintr_thms ~~ flat constrss))) thy4;
  55.159 -    val elimps = mapfilter (fn (s, intrs) => if s mem rsets then
  55.160 -        apsome (rpair intrs) (find_first (fn (thm, _) =>
  55.161 +              (List.concat (map snd rss) ~~ rintr_thms ~~ List.concat constrss))) thy4;
  55.162 +    val elimps = List.mapPartial (fn (s, intrs) => if s mem rsets then
  55.163 +        Option.map (rpair intrs) (find_first (fn (thm, _) =>
  55.164            s mem term_consts (hd (prems_of thm))) (elims ~~ #elims ind_info))
  55.165        else NONE) rss;
  55.166 -    val thy6 = foldl (fn (thy, p as (((((elim, _), _), _), _), _)) => thy |>
  55.167 +    val thy6 = Library.foldl (fn (thy, p as (((((elim, _), _), _), _), _)) => thy |>
  55.168        add_elim_realizer [] p |> add_elim_realizer [fst (fst (dest_Var
  55.169          (HOLogic.dest_Trueprop (concl_of elim))))] p) (thy5,
  55.170             elimps ~~ get #case_thms dt_info ~~ case_names ~~ dummies)
  55.171  
  55.172 -  in Theory.add_path (NameSpace.pack (if_none path [])) thy6 end;
  55.173 +  in Theory.add_path (NameSpace.pack (getOpt (path, []))) thy6 end;
  55.174  
  55.175  fun add_ind_realizers name rsets thy =
  55.176    let
  55.177 @@ -452,7 +452,7 @@
  55.178      val vss = sort (int_ord o pairself length)
  55.179        (subsets (map fst (relevant_vars S)))
  55.180    in
  55.181 -    foldl (add_ind_realizer rsets intrs induct raw_induct elims) (thy, vss)
  55.182 +    Library.foldl (add_ind_realizer rsets intrs induct raw_induct elims) (thy, vss)
  55.183    end
  55.184  
  55.185  fun rlz_attrib arg (thy, thm) =
  55.186 @@ -462,7 +462,7 @@
  55.187        (case HOLogic.dest_conj (HOLogic.dest_Trueprop (concl_of thm)) of
  55.188             [_] => [set_of (HOLogic.dest_Trueprop (hd (prems_of thm)))]
  55.189           | xs => map (set_of o fst o HOLogic.dest_imp) xs)
  55.190 -         handle TERM _ => err () | LIST _ => err ();
  55.191 +         handle TERM _ => err () | Empty => err ();
  55.192    in 
  55.193      (add_ind_realizers (hd sets) (case arg of
  55.194          NONE => sets | SOME NONE => []
    56.1 --- a/src/HOL/Tools/meson.ML	Thu Mar 03 09:22:35 2005 +0100
    56.2 +++ b/src/HOL/Tools/meson.ML	Thu Mar 03 12:43:01 2005 +0100
    56.3 @@ -164,7 +164,7 @@
    56.4   fun fewerlits(th1,th2) = nliterals(prop_of th1) < nliterals(prop_of th2);
    56.5  
    56.6   (*TAUTOLOGY CHECK SHOULD NOT BE NECESSARY!*)
    56.7 - fun sort_clauses ths = sort (make_ord fewerlits) (filter (not o is_taut) ths);
    56.8 + fun sort_clauses ths = sort (make_ord fewerlits) (List.filter (not o is_taut) ths);
    56.9  
   56.10   (*Convert all suitable free variables to schematic variables*)
   56.11   fun generalize th = forall_elim_vars 0 (forall_intr_frees th);
   56.12 @@ -188,12 +188,12 @@
   56.13       let fun name1 (th, (k,ths)) =
   56.14             (k-1, Thm.name_thm (label ^ string_of_int k, th) :: ths)
   56.15  
   56.16 -     in  fn ths => #2 (foldr name1 (ths, (length ths, [])))  end;
   56.17 +     in  fn ths => #2 (Library.foldr name1 (ths, (length ths, [])))  end;
   56.18  
   56.19   (*Find an all-negative support clause*)
   56.20   fun is_negative th = forall (not o #1) (literals (prop_of th));
   56.21  
   56.22 - val neg_clauses = filter is_negative;
   56.23 + val neg_clauses = List.filter is_negative;
   56.24  
   56.25  
   56.26   (***** MESON PROOF PROCEDURE *****)
   56.27 @@ -211,7 +211,7 @@
   56.28   fun has_reps [] = false
   56.29     | has_reps [_] = false
   56.30     | has_reps [t,u] = (t aconv u)
   56.31 -   | has_reps ts = (foldl ins_term (Net.empty, ts);  false)
   56.32 +   | has_reps ts = (Library.foldl ins_term (Net.empty, ts);  false)
   56.33                     handle INSERT => true;
   56.34  
   56.35   (*Like TRYALL eq_assume_tac, but avoids expensive THEN calls*)
   56.36 @@ -239,7 +239,7 @@
   56.37  (*Sums the sizes of the subgoals, ignoring hypotheses (ancestors)*)
   56.38  local fun addconcl(prem,sz) = size_of_term(Logic.strip_assums_concl prem) + sz
   56.39  in
   56.40 -fun size_of_subgoals st = foldr addconcl (prems_of st, 0)
   56.41 +fun size_of_subgoals st = Library.foldr addconcl (prems_of st, 0)
   56.42  end;
   56.43  
   56.44  (*Negation Normal Form*)
   56.45 @@ -265,12 +265,12 @@
   56.46  (*Make clauses from a list of theorems, previously Skolemized and put into nnf.
   56.47    The resulting clauses are HOL disjunctions.*)
   56.48  fun make_clauses ths =
   56.49 -    sort_clauses (map (generalize o nodups) (foldr cnf (ths,[])));
   56.50 +    sort_clauses (map (generalize o nodups) (Library.foldr cnf (ths,[])));
   56.51  
   56.52  (*Convert a list of clauses to (contrapositive) Horn clauses*)
   56.53  fun make_horns ths =
   56.54      name_thms "Horn#"
   56.55 -      (gen_distinct Drule.eq_thm_prop (foldr (add_contras clause_rules) (ths,[])));
   56.56 +      (gen_distinct Drule.eq_thm_prop (Library.foldr (add_contras clause_rules) (ths,[])));
   56.57  
   56.58  (*Could simply use nprems_of, which would count remaining subgoals -- no
   56.59    discrimination as to their size!  With BEST_FIRST, fails for problem 41.*)
    57.1 --- a/src/HOL/Tools/primrec_package.ML	Thu Mar 03 09:22:35 2005 +0100
    57.2 +++ b/src/HOL/Tools/primrec_package.ML	Thu Mar 03 12:43:01 2005 +0100
    57.3 @@ -76,7 +76,7 @@
    57.4          NONE =>
    57.5            (fname, (tname, rpos, [(cname, (ls, cargs, rs, rhs, eq))]))::rec_fns
    57.6        | SOME (_, rpos', eqns) =>
    57.7 -          if is_some (assoc (eqns, cname)) then
    57.8 +          if isSome (assoc (eqns, cname)) then
    57.9              raise RecError "constructor already occurred as pattern"
   57.10            else if rpos <> rpos' then
   57.11              raise RecError "position of recursive argument inconsistent"
   57.12 @@ -90,7 +90,7 @@
   57.13  
   57.14  fun process_fun sign descr rec_eqns ((i, fname), (fnames, fnss)) =
   57.15    let
   57.16 -    val (_, (tname, _, constrs)) = nth_elem (i, descr);
   57.17 +    val (_, (tname, _, constrs)) = List.nth (descr, i);
   57.18  
   57.19      (* substitute "fname ls x rs" by "y ls rs" for (x, (_, y)) in subs *)
   57.20  
   57.21 @@ -104,11 +104,11 @@
   57.22              if is_Const f andalso (fst (dest_Const f)) mem (map fst rec_eqns) then
   57.23                let
   57.24                  val (fname', _) = dest_Const f;
   57.25 -                val (_, rpos, _) = the (assoc (rec_eqns, fname'));
   57.26 -                val ls = take (rpos, ts);
   57.27 -                val rest = drop (rpos, ts);
   57.28 +                val (_, rpos, _) = valOf (assoc (rec_eqns, fname'));
   57.29 +                val ls = Library.take (rpos, ts);
   57.30 +                val rest = Library.drop (rpos, ts);
   57.31                  val (x', rs) = (hd rest, tl rest)
   57.32 -                  handle LIST _ => raise RecError ("not enough arguments\
   57.33 +                  handle Empty => raise RecError ("not enough arguments\
   57.34                     \ in recursive application\nof function " ^ quote fname' ^ " on rhs");
   57.35                  val (x, xs) = strip_comb x'
   57.36                in 
   57.37 @@ -140,7 +140,7 @@
   57.38                (fnames', fnss', (Const ("arbitrary", dummyT))::fns))
   57.39          | SOME (ls, cargs', rs, rhs, eq) =>
   57.40              let
   57.41 -              val recs = filter (is_rec_type o snd) (cargs' ~~ cargs);
   57.42 +              val recs = List.filter (is_rec_type o snd) (cargs' ~~ cargs);
   57.43                val rargs = map fst recs;
   57.44                val subs = map (rpair dummyT o fst) 
   57.45  		             (rev (rename_wrt_term rhs rargs));
   57.46 @@ -160,8 +160,8 @@
   57.47            raise RecError ("inconsistent functions for datatype " ^ quote tname)
   57.48          else
   57.49            let
   57.50 -            val (_, _, eqns) = the (assoc (rec_eqns, fname));
   57.51 -            val (fnames', fnss', fns) = foldr (trans eqns)
   57.52 +            val (_, _, eqns) = valOf (assoc (rec_eqns, fname));
   57.53 +            val (fnames', fnss', fns) = Library.foldr (trans eqns)
   57.54                (constrs, ((i, fname)::fnames, fnss, []))
   57.55            in
   57.56              (fnames', (i, (fname, #1 (snd (hd eqns)), fns))::fnss')
   57.57 @@ -179,7 +179,7 @@
   57.58       NONE =>
   57.59         let
   57.60           val dummy_fns = map (fn (_, cargs) => Const ("arbitrary",
   57.61 -           replicate ((length cargs) + (length (filter is_rec_type cargs)))
   57.62 +           replicate ((length cargs) + (length (List.filter is_rec_type cargs)))
   57.63               dummyT ---> HOLogic.unitT)) constrs;
   57.64           val _ = warning ("No function definition for datatype " ^ quote tname)
   57.65         in
   57.66 @@ -192,7 +192,7 @@
   57.67  
   57.68  fun make_def sign fs (fname, ls, rec_name, tname) =
   57.69    let
   57.70 -    val rhs = foldr (fn (T, t) => Abs ("", T, t)) 
   57.71 +    val rhs = Library.foldr (fn (T, t) => Abs ("", T, t)) 
   57.72  	            ((map snd ls) @ [dummyT],
   57.73  		     list_comb (Const (rec_name, dummyT),
   57.74  				fs @ map Bound (0 ::(length ls downto 1))));
   57.75 @@ -216,10 +216,10 @@
   57.76    let
   57.77      fun constrs_of (_, (_, _, cs)) =
   57.78        map (fn (cname:string, (_, cargs, _, _, _)) => (cname, map fst cargs)) cs;
   57.79 -    val params_of = Library.assocs (flat (map constrs_of rec_eqns));
   57.80 +    val params_of = Library.assocs (List.concat (map constrs_of rec_eqns));
   57.81    in
   57.82      induction
   57.83 -    |> RuleCases.rename_params (map params_of (flat (map (map #1 o #3 o #2) descr)))
   57.84 +    |> RuleCases.rename_params (map params_of (List.concat (map (map #1 o #3 o #2) descr)))
   57.85      |> RuleCases.save induction
   57.86    end;
   57.87  
   57.88 @@ -228,22 +228,22 @@
   57.89      val (eqns, atts) = split_list eqns_atts;
   57.90      val sg = Theory.sign_of thy;
   57.91      val dt_info = DatatypePackage.get_datatypes thy;
   57.92 -    val rec_eqns = foldr (process_eqn sg) (map snd eqns, []);
   57.93 +    val rec_eqns = Library.foldr (process_eqn sg) (map snd eqns, []);
   57.94      val tnames = distinct (map (#1 o snd) rec_eqns);
   57.95      val dts = find_dts dt_info tnames tnames;
   57.96      val main_fns = 
   57.97  	map (fn (tname, {index, ...}) =>
   57.98  	     (index, 
   57.99 -	      fst (the (find_first (fn f => #1 (snd f) = tname) rec_eqns))))
  57.100 +	      fst (valOf (find_first (fn f => #1 (snd f) = tname) rec_eqns))))
  57.101  	dts;
  57.102      val {descr, rec_names, rec_rewrites, ...} = 
  57.103  	if null dts then
  57.104  	    primrec_err ("datatypes " ^ commas_quote tnames ^ 
  57.105  			 "\nare not mutually recursive")
  57.106  	else snd (hd dts);
  57.107 -    val (fnames, fnss) = foldr (process_fun sg descr rec_eqns)
  57.108 +    val (fnames, fnss) = Library.foldr (process_fun sg descr rec_eqns)
  57.109  	                       (main_fns, ([], []));
  57.110 -    val (fs, defs) = foldr (get_fns fnss) (descr ~~ rec_names, ([], []));
  57.111 +    val (fs, defs) = Library.foldr (get_fns fnss) (descr ~~ rec_names, ([], []));
  57.112      val defs' = map (make_def sg fs) defs;
  57.113      val names1 = map snd fnames;
  57.114      val names2 = map fst rec_eqns;
    58.1 --- a/src/HOL/Tools/prop_logic.ML	Thu Mar 03 09:22:35 2005 +0100
    58.2 +++ b/src/HOL/Tools/prop_logic.ML	Thu Mar 03 12:43:01 2005 +0100
    58.3 @@ -275,7 +275,7 @@
    58.4  
    58.5  	(* prop_formula list -> prop_formula *)
    58.6  
    58.7 -	fun exists xs = foldl SOr (False, xs);
    58.8 +	fun exists xs = Library.foldl SOr (False, xs);
    58.9  
   58.10  (* ------------------------------------------------------------------------- *)
   58.11  (* all: computes the conjunction over a list 'xs' of propositional formulas  *)
   58.12 @@ -283,7 +283,7 @@
   58.13  
   58.14  	(* prop_formula list -> prop_formula *)
   58.15  
   58.16 -	fun all xs = foldl SAnd (True, xs);
   58.17 +	fun all xs = Library.foldl SAnd (True, xs);
   58.18  
   58.19  (* ------------------------------------------------------------------------- *)
   58.20  (* dot_product: ([x1,...,xn], [y1,...,yn]) -> x1*y1+...+xn*yn                *)
    59.1 --- a/src/HOL/Tools/recdef_package.ML	Thu Mar 03 09:22:35 2005 +0100
    59.2 +++ b/src/HOL/Tools/recdef_package.ML	Thu Mar 03 12:43:01 2005 +0100
    59.3 @@ -91,7 +91,7 @@
    59.4      val (del, rest) = Library.partition (Library.equal c o fst) congs;
    59.5    in if null del then (warning ("No recdef congruence rule for " ^ quote c); congs) else rest end;
    59.6  
    59.7 -val add_congs = curry (foldr (uncurry add_cong));
    59.8 +val add_congs = curry (Library.foldr (uncurry add_cong));
    59.9  
   59.10  end;
   59.11  
   59.12 @@ -255,7 +255,7 @@
   59.13      val (thy, (simps' :: rules', [induct'])) =
   59.14        thy
   59.15        |> Theory.add_path bname
   59.16 -      |> PureThy.add_thmss ((("simps", flat rules), simp_att) :: ((eq_names ~~ rules) ~~ eq_atts))
   59.17 +      |> PureThy.add_thmss ((("simps", List.concat rules), simp_att) :: ((eq_names ~~ rules) ~~ eq_atts))
   59.18        |>>> PureThy.add_thms [(("induct", induct), [])];
   59.19      val result = {simps = simps', rules = rules', induct = induct', tcs = tcs};
   59.20      val thy =
   59.21 @@ -312,8 +312,8 @@
   59.22        (case get_recdef thy name of
   59.23          NONE => error ("No recdef definition of constant: " ^ quote name)
   59.24        | SOME {tcs, ...} => tcs);
   59.25 -    val i = if_none opt_i 1;
   59.26 -    val tc = Library.nth_elem (i - 1, tcs) handle Library.LIST _ =>
   59.27 +    val i = getOpt (opt_i, 1);
   59.28 +    val tc = List.nth (tcs, i - 1) handle Subscript =>
   59.29        error ("No termination condition #" ^ string_of_int i ^
   59.30          " in recdef definition of " ^ quote name);
   59.31    in
    60.1 --- a/src/HOL/Tools/recfun_codegen.ML	Thu Mar 03 09:22:35 2005 +0100
    60.2 +++ b/src/HOL/Tools/recfun_codegen.ML	Thu Mar 03 12:43:01 2005 +0100
    60.3 @@ -44,7 +44,7 @@
    60.4    in
    60.5      if Pattern.pattern (lhs_of thm) then
    60.6        (CodegenData.put (Symtab.update ((s,
    60.7 -        thm :: if_none (Symtab.lookup (tab, s)) []), tab)) thy, thm)
    60.8 +        thm :: getOpt (Symtab.lookup (tab, s), [])), tab)) thy, thm)
    60.9      else (warn thm; p)
   60.10    end handle TERM _ => (warn thm; p);
   60.11  
   60.12 @@ -70,7 +70,7 @@
   60.13    (case Symtab.lookup (CodegenData.get thy, s) of
   60.14       NONE => []
   60.15     | SOME thms => preprocess thy (del_redundant thy []
   60.16 -       (filter (fn thm => is_instance thy T
   60.17 +       (List.filter (fn thm => is_instance thy T
   60.18           (snd (const_of (prop_of thm)))) thms)));
   60.19  
   60.20  fun mk_poly_id thy (s, T) = mk_const_id (sign_of thy) s ^
   60.21 @@ -82,7 +82,7 @@
   60.22  
   60.23  fun cycle g (xs, x) =
   60.24    if x mem xs then xs
   60.25 -  else foldl (cycle g) (x :: xs, flat (Graph.find_paths g (x, x)));
   60.26 +  else Library.foldl (cycle g) (x :: xs, List.concat (Graph.find_paths g (x, x)));
   60.27  
   60.28  fun add_rec_funs thy gr dep eqs =
   60.29    let
   60.30 @@ -125,10 +125,10 @@
   60.31               if not (dep mem xs) then
   60.32                 let
   60.33                   val eqs'' = map (dest_eq o prop_of)
   60.34 -                   (flat (map (get_equations thy) cs));
   60.35 +                   (List.concat (map (get_equations thy) cs));
   60.36                   val (gr3, fundef') = mk_fundef "" "fun "
   60.37                     (Graph.add_edge (dname, dep)
   60.38 -                     (foldr (uncurry Graph.new_node) (map (fn k =>
   60.39 +                     (Library.foldr (uncurry Graph.new_node) (map (fn k =>
   60.40                         (k, (SOME (EQN ("", dummyT, dname)), ""))) xs,
   60.41                           Graph.del_nodes xs gr2))) eqs''
   60.42                 in put_code fundef' gr3 end
    61.1 --- a/src/HOL/Tools/record_package.ML	Thu Mar 03 09:22:35 2005 +0100
    61.2 +++ b/src/HOL/Tools/record_package.ML	Thu Mar 03 12:43:01 2005 +0100
    61.3 @@ -160,7 +160,7 @@
    61.4  fun dest_recT (typ as Type (c_ext_type, Ts as (T::_))) =
    61.5        (case try (unsuffix ext_typeN) c_ext_type of
    61.6          NONE => raise TYPE ("RecordPackage.dest_recT", [typ], [])
    61.7 -      | SOME c => ((c, Ts), last_elem Ts))
    61.8 +      | SOME c => ((c, Ts), List.last Ts))
    61.9    | dest_recT typ = raise TYPE ("RecordPackage.dest_recT", [typ], []);
   61.10  
   61.11  fun is_recT T =
   61.12 @@ -180,8 +180,8 @@
   61.13  
   61.14  fun rec_id i T = 
   61.15    let val rTs = dest_recTs T
   61.16 -      val rTs' = if i < 0 then rTs else take (i,rTs)
   61.17 -  in foldl (fn (s,(c,T)) => s ^ c) ("",rTs') end;
   61.18 +      val rTs' = if i < 0 then rTs else Library.take (i,rTs)
   61.19 +  in Library.foldl (fn (s,(c,T)) => s ^ c) ("",rTs') end;
   61.20  
   61.21  (*** extend theory by record definition ***)
   61.22  
   61.23 @@ -426,11 +426,11 @@
   61.24      val varifyT = map_type_tfree varify;
   61.25      val {records,extfields,...} = RecordsData.get_sg sg;
   61.26      val (flds,(more,_)) = split_last (Symtab.lookup_multi (extfields,name));
   61.27 -    val args = map varifyT (snd (#extension (the (Symtab.lookup (records,recname)))));
   61.28 +    val args = map varifyT (snd (#extension (valOf (Symtab.lookup (records,recname)))));
   61.29  
   61.30      val tsig = Sign.tsig_of sg;
   61.31      fun unify (t,env) = Type.unify tsig env t;
   61.32 -    val (subst,_) = foldr unify (but_last args ~~ but_last Ts,(Vartab.empty,0));
   61.33 +    val (subst,_) = Library.foldr unify (but_last args ~~ but_last Ts,(Vartab.empty,0));
   61.34      val flds' = map (apsnd ((Envir.norm_type subst) o varifyT)) flds;
   61.35    in (flds',(more,moreT)) end;
   61.36  
   61.37 @@ -449,7 +449,7 @@
   61.38    let
   61.39      val {records, sel_upd, equalities, extinjects, extsplit, splits, extfields, fieldext} = 
   61.40             RecordsData.get thy;
   61.41 -    val fieldext' = foldl (fn (table,field) => Symtab.update_new ((field,extname_types),table))  
   61.42 +    val fieldext' = Library.foldl (fn (table,field) => Symtab.update_new ((field,extname_types),table))  
   61.43                            (fieldext,fields);
   61.44      val data=make_record_data records sel_upd equalities extinjects extsplit 
   61.45                splits extfields fieldext';
   61.46 @@ -473,11 +473,11 @@
   61.47  
   61.48          fun bad_inst ((x, S), T) =
   61.49            if Sign.of_sort sign (T, S) then NONE else SOME x
   61.50 -        val bads = mapfilter bad_inst (args ~~ types);
   61.51 +        val bads = List.mapPartial bad_inst (args ~~ types);
   61.52  
   61.53          val inst = map fst args ~~ types;
   61.54 -        val subst = Term.map_type_tfree (fn (x, _) => the (assoc (inst, x)));
   61.55 -        val parent' = apsome (apfst (map subst)) parent;
   61.56 +        val subst = Term.map_type_tfree (fn (x, _) => valOf (assoc (inst, x)));
   61.57 +        val parent' = Option.map (apfst (map subst)) parent;
   61.58          val fields' = map (apsnd subst) fields;
   61.59          val extension' = apsnd (map subst) extension;
   61.60        in
   61.61 @@ -504,7 +504,7 @@
   61.62  
   61.63  
   61.64  fun record_update_tr [t, u] =
   61.65 -      foldr (op $) (rev (gen_fields_tr "_updates" "_update" updateN u), t)
   61.66 +      Library.foldr (op $) (rev (gen_fields_tr "_updates" "_update" updateN u), t)
   61.67    | record_update_tr ts = raise TERM ("record_update_tr", ts);
   61.68  
   61.69  fun update_name_tr (Free (x, T) :: ts) = Free (suffix updateN x, T) $$ ts
   61.70 @@ -584,7 +584,7 @@
   61.71                         val (args,rest) = splitargs (map fst flds') fargs;
   61.72                         val vartypes = map Type.varifyT types;
   61.73                         val argtypes = map to_type args;
   61.74 -                       val (subst,_) = foldr unify (vartypes ~~ argtypes,(Vartab.empty,0));
   61.75 +                       val (subst,_) = Library.foldr unify (vartypes ~~ argtypes,(Vartab.empty,0));
   61.76                         val alphas' = map ((Syntax.term_of_typ (! Syntax.show_sorts)) o 
   61.77                                            (Envir.norm_type subst) o Type.varifyT) 
   61.78                                           (but_last alphas);
   61.79 @@ -671,7 +671,7 @@
   61.80                            val flds' = Sign.extern sg Sign.constK f::map NameSpace.base fs; 
   61.81                            val (args',more) = split_last args; 
   61.82                           in (flds'~~args')@field_lst more end
   61.83 -                         handle LIST _ => [("",t)]) 
   61.84 +                         handle UnequalLengths => [("",t)])
   61.85                     | NONE => [("",t)])
   61.86               | NONE => [("",t)])
   61.87         | _ => [("",t)])
   61.88 @@ -777,12 +777,12 @@
   61.89                                              ::map (apfst NameSpace.base) fs; 
   61.90                                  val (args',more) = split_last args; 
   61.91                                  val alphavars = map Type.varifyT (but_last alphas); 
   61.92 -                                val (subst,_)= foldr unify (alphavars~~args',(Vartab.empty,0));
   61.93 +                                val (subst,_)= Library.foldr unify (alphavars~~args',(Vartab.empty,0));
   61.94                                  val flds'' =map (apsnd ((Envir.norm_type subst)o(Type.varifyT)))
   61.95                                                  flds';
   61.96                                in flds''@field_lst more end
   61.97 -                              handle TUNIFY => [("",T)] 
   61.98 -                                   | LIST _=> [("",T)])
   61.99 +                              handle TUNIFY         => [("",T)] 
  61.100 +                                   | UnequalLengths => [("",T)])
  61.101                           | NONE => [("",T)])
  61.102                     | NONE => [("",T)])
  61.103               | NONE => [("",T)]) 
  61.104 @@ -840,7 +840,7 @@
  61.105    let 
  61.106      val {sel_upd={simpset,...},extsplit,...} = RecordsData.get_sg sg;
  61.107      val extsplits = 
  61.108 -            foldl (fn (thms,(n,_)) => (list (Symtab.lookup (extsplit,n)))@thms) 
  61.109 +            Library.foldl (fn (thms,(n,_)) => (list (Symtab.lookup (extsplit,n)))@thms) 
  61.110                      ([],dest_recTs T);
  61.111      val thms = (case get_splits sg (rec_id (~1) T) of
  61.112                     SOME (all_thm,_,_,_) => 
  61.113 @@ -854,7 +854,7 @@
  61.114  local
  61.115  
  61.116  fun get_fields extfields T = 
  61.117 -     foldl (fn (xs,(eN,_))=>xs@(Symtab.lookup_multi (extfields,eN)))
  61.118 +     Library.foldl (fn (xs,(eN,_))=>xs@(Symtab.lookup_multi (extfields,eN)))
  61.119               ([],(dest_recTs T));
  61.120  in
  61.121  (* record_simproc *)
  61.122 @@ -974,10 +974,10 @@
  61.123                * updates again, the optimised term is constructed.
  61.124                *)
  61.125               fun mk_updterm upds already (t as ((upd as Const (u,uT)) $ k $ r)) =
  61.126 -		 if is_some (Symtab.lookup (upds,u))
  61.127 +		 if isSome (Symtab.lookup (upds,u))
  61.128  		 then let 
  61.129  			 fun rest already = mk_updterm upds already
  61.130 -		      in if is_some (Symtab.lookup (already,u)) 
  61.131 +		      in if isSome (Symtab.lookup (already,u)) 
  61.132  			 then (case (rest already r) of
  61.133  				 Init ((sprout,skel),vars) => 
  61.134                                   let
  61.135 @@ -1146,8 +1146,8 @@
  61.136            (s = "all" orelse s = "All" orelse s = "Ex") andalso is_recT T 
  61.137          | _ => false);
  61.138  
  61.139 -    val goal = Library.nth_elem (i - 1, Thm.prems_of st);
  61.140 -    val frees = filter (is_recT o type_of) (term_frees goal);
  61.141 +    val goal = List.nth (Thm.prems_of st, i - 1);
  61.142 +    val frees = List.filter (is_recT o type_of) (term_frees goal);
  61.143  
  61.144      fun mk_split_free_tac free induct_thm i = 
  61.145  	let val cfree = cterm_of sg free;
  61.146 @@ -1172,13 +1172,13 @@
  61.147                     end)
  61.148       | split_free_tac _ _ _ = NONE;
  61.149  
  61.150 -    val split_frees_tacs = mapfilter (split_free_tac P i) frees;
  61.151 +    val split_frees_tacs = List.mapPartial (split_free_tac P i) frees;
  61.152     
  61.153      val simprocs = if has_rec goal then [record_split_simproc P] else [];
  61.154     
  61.155    in st |> (EVERY split_frees_tacs) 
  61.156             THEN (Simplifier.full_simp_tac (simpset addsimps thms addsimprocs simprocs) i)
  61.157 -  end handle Library.LIST _ => Seq.empty;
  61.158 +  end handle Empty => Seq.empty;
  61.159  end;
  61.160  
  61.161  
  61.162 @@ -1193,7 +1193,7 @@
  61.163            (s = "all" orelse s = "All") andalso is_recT T 
  61.164          | _ => false);
  61.165   
  61.166 -    val goal = Library.nth_elem (i - 1, Thm.prems_of st);   
  61.167 +    val goal = List.nth (Thm.prems_of st, i - 1);   
  61.168  
  61.169      fun is_all t =
  61.170        (case t of (Const (quantifier, _)$_) =>
  61.171 @@ -1204,7 +1204,7 @@
  61.172       then Simplifier.full_simp_tac 
  61.173             (HOL_basic_ss addsimprocs [record_split_simproc is_all]) i st 
  61.174       else Seq.empty
  61.175 -  end handle Library.LIST _ => Seq.empty;
  61.176 +  end handle Subscript => Seq.empty;
  61.177  
  61.178  (* wrapper *)
  61.179  
  61.180 @@ -1251,14 +1251,14 @@
  61.181  fun try_param_tac s rule i st =
  61.182    let
  61.183      val cert = cterm_of (Thm.sign_of_thm st);
  61.184 -    val g = nth_elem (i - 1, prems_of st);
  61.185 +    val g = List.nth (prems_of st, i - 1);
  61.186      val params = Logic.strip_params g;
  61.187      val concl = HOLogic.dest_Trueprop (Logic.strip_assums_concl g);
  61.188      val rule' = Thm.lift_rule (st, i) rule;
  61.189      val (P, ys) = strip_comb (HOLogic.dest_Trueprop
  61.190        (Logic.strip_assums_concl (prop_of rule')));
  61.191      (* ca indicates if rule is a case analysis or induction rule *)
  61.192 -    val (x, ca) = (case rev (drop (length params, ys)) of
  61.193 +    val (x, ca) = (case rev (Library.drop (length params, ys)) of
  61.194          [] => (head_of (fst (HOLogic.dest_eq (HOLogic.dest_Trueprop
  61.195            (hd (rev (Logic.strip_assums_hyp (hd (prems_of rule')))))))), true)
  61.196        | [x] => (head_of x, false));
  61.197 @@ -1278,13 +1278,13 @@
  61.198  fun ex_inst_tac i st =
  61.199    let
  61.200      val sg = sign_of_thm st;
  61.201 -    val g = nth_elem (i - 1, prems_of st);
  61.202 +    val g = List.nth (prems_of st, i - 1);
  61.203      val params = Logic.strip_params g;
  61.204      val exI' = Thm.lift_rule (st, i) exI;
  61.205      val (_$(_$x)) = Logic.strip_assums_concl (hd (prems_of exI'));
  61.206      val cx = cterm_of sg (fst (strip_comb x));
  61.207  
  61.208 -  in Seq.single (foldl (fn (st,v) => 
  61.209 +  in Seq.single (Library.foldl (fn (st,v) => 
  61.210          Seq.hd 
  61.211          (compose_tac (false, cterm_instantiate 
  61.212                                  [(cx,cterm_of sg (list_abs (params,Bound v)))] exI',1) 
  61.213 @@ -1307,7 +1307,7 @@
  61.214  
  61.215  fun mixit convs refls = 
  61.216    let fun f ((res,lhs,rhs),refl) = ((refl,List.revAppend (lhs,refl::tl rhs))::res,hd rhs::lhs,tl rhs);
  61.217 -  in #1 (foldl f (([],[],convs),refls)) end;
  61.218 +  in #1 (Library.foldl f (([],[],convs),refls)) end;
  61.219  
  61.220  fun extension_definition full name fields names alphas zeta moreT more vars thy = 
  61.221    let  
  61.222 @@ -1332,7 +1332,7 @@
  61.223      val ext_decl = (mk_extC (name,extT) fields_moreTs);
  61.224      (*     
  61.225      val ext_spec = Const ext_decl :== 
  61.226 -         (foldr (uncurry lambda) 
  61.227 +         (Library.foldr (uncurry lambda) 
  61.228              (vars@[more],(mk_Abs name repT extT $ (foldr1 HOLogic.mk_prod (vars@[more]))))) 
  61.229      *) 
  61.230      val ext_spec = list_comb (Const ext_decl,vars@[more]) :== 
  61.231 @@ -1484,7 +1484,7 @@
  61.232           (* freezeT just for performance, to adjust the maxidx, so that nodup_vars will not 
  61.233                  be called during combination *)
  61.234          fun mkthm (udef,(fld_refl,thms)) =
  61.235 -          let val bdyeq = foldl (uncurry Thm.combination) (constr_refl,thms);
  61.236 +          let val bdyeq = Library.foldl (uncurry Thm.combination) (constr_refl,thms);
  61.237                 (* (|N=N (|N=N,M=M,K=K,more=more|)
  61.238                      M=M (|N=N,M=M,K=K,more=more|)
  61.239                      K=K'
  61.240 @@ -1537,7 +1537,7 @@
  61.241     
  61.242  fun chunks []      []   = []
  61.243    | chunks []      xs   = [xs]
  61.244 -  | chunks (l::ls) xs  = take (l,xs)::chunks ls (drop (l,xs));
  61.245 +  | chunks (l::ls) xs  = Library.take (l,xs)::chunks ls (Library.drop (l,xs));
  61.246   
  61.247  fun chop_last [] = error "last: list should not be empty"
  61.248    | chop_last [x] = ([],x)
  61.249 @@ -1551,7 +1551,7 @@
  61.250   * of parent extensions, starting with the root of the record hierarchy 
  61.251  *) 
  61.252  fun mk_recordT extT parent_exts = 
  61.253 -    foldr (fn ((parent,Ts),T) => Type (parent, subst_last T Ts)) (parent_exts,extT);
  61.254 +    Library.foldr (fn ((parent,Ts),T) => Type (parent, subst_last T Ts)) (parent_exts,extT);
  61.255  
  61.256  
  61.257  
  61.258 @@ -1591,7 +1591,7 @@
  61.259  
  61.260      val (bfields, field_syntax) = split_list (map (fn (x, T, mx) => ((x, T), mx)) raw_fields);
  61.261  
  61.262 -    val parent_fields = flat (map #fields parents);
  61.263 +    val parent_fields = List.concat (map #fields parents);
  61.264      val parent_chunks = map (length o #fields) parents;
  61.265      val parent_names = map fst parent_fields;
  61.266      val parent_types = map snd parent_fields;
  61.267 @@ -1605,7 +1605,7 @@
  61.268      val names = map fst fields;
  61.269      val extN = full bname;
  61.270      val types = map snd fields;
  61.271 -    val alphas_fields = foldr add_typ_tfree_names (types,[]);
  61.272 +    val alphas_fields = Library.foldr add_typ_tfree_names (types,[]);
  61.273      val alphas_ext = alphas inter alphas_fields; 
  61.274      val len = length fields;
  61.275      val variants = variantlist (map fst bfields, moreN::rN::rN ^ "'"::wN::parent_variants);
  61.276 @@ -1647,7 +1647,7 @@
  61.277      val extension = let val (n,Ts) = extension_scheme in (n,subst_last HOLogic.unitT Ts) end; 
  61.278      val extension_names = 
  61.279           (map ((unsuffix ext_typeN) o fst o #extension) parents) @ [extN];
  61.280 -    val extension_id = foldl (op ^) ("",extension_names);
  61.281 +    val extension_id = Library.foldl (op ^) ("",extension_names);
  61.282  
  61.283   
  61.284      fun rec_schemeT n = mk_recordT extT (map #extension (prune n parents));
  61.285 @@ -1663,7 +1663,7 @@
  61.286        let val (args',more) = chop_last args;
  61.287  	  fun mk_ext' (((name,T),args),more) = mk_ext (name,T) (args@[more]);
  61.288            fun build Ts = 
  61.289 -           foldr mk_ext' (prune n (extension_names ~~ Ts ~~ (chunks parent_chunks args')),more) 
  61.290 +           Library.foldr mk_ext' (prune n (extension_names ~~ Ts ~~ (chunks parent_chunks args')),more) 
  61.291        in 
  61.292          if more = HOLogic.unit 
  61.293          then build (map recT (0 upto parent_len)) 
  61.294 @@ -1681,7 +1681,7 @@
  61.295  
  61.296      (* prepare print translation functions *)
  61.297      val field_tr's =
  61.298 -      print_translation (distinct (flat (map NameSpace.accesses' (full_moreN :: names))));
  61.299 +      print_translation (distinct (List.concat (map NameSpace.accesses' (full_moreN :: names))));
  61.300  
  61.301      val adv_ext_tr's =
  61.302      let
  61.303 @@ -1822,13 +1822,13 @@
  61.304        end; 
  61.305  
  61.306      val split_object_prop =
  61.307 -      let fun ALL vs t = foldr (fn ((v,T),t) => HOLogic.mk_all (v,T,t)) (vs,t)
  61.308 +      let fun ALL vs t = Library.foldr (fn ((v,T),t) => HOLogic.mk_all (v,T,t)) (vs,t)
  61.309        in (ALL [dest_Free r0] (P $ r0)) === (ALL (map dest_Free all_vars_more) (P $ r_rec0))
  61.310        end;
  61.311  
  61.312  
  61.313      val split_ex_prop =
  61.314 -      let fun EX vs t = foldr (fn ((v,T),t) => HOLogic.mk_exists (v,T,t)) (vs,t)
  61.315 +      let fun EX vs t = Library.foldr (fn ((v,T),t) => HOLogic.mk_exists (v,T,t)) (vs,t)
  61.316        in (EX [dest_Free r0] (P $ r0)) === (EX (map dest_Free all_vars_more) (P $ r_rec0))
  61.317        end;
  61.318  
  61.319 @@ -2041,14 +2041,14 @@
  61.320  
  61.321      fun prep_inst T = snd (cert_typ sign ([], T));
  61.322  
  61.323 -    val parent = apsome (apfst (map prep_inst) o prep_raw_parent sign) raw_parent
  61.324 +    val parent = Option.map (apfst (map prep_inst) o prep_raw_parent sign) raw_parent
  61.325        handle ERROR => error ("The error(s) above in parent record specification");
  61.326      val parents = add_parents thy parent [];
  61.327  
  61.328      val init_env =
  61.329        (case parent of
  61.330          NONE => []
  61.331 -      | SOME (types, _) => foldr Term.add_typ_tfrees (types, []));
  61.332 +      | SOME (types, _) => Library.foldr Term.add_typ_tfrees (types, []));
  61.333  
  61.334  
  61.335      (* fields *)
  61.336 @@ -2065,7 +2065,7 @@
  61.337      (* args *)
  61.338  
  61.339      val defaultS = Sign.defaultS sign;
  61.340 -    val args = map (fn x => (x, if_none (assoc (envir, x)) defaultS)) params;
  61.341 +    val args = map (fn x => (x, getOpt (assoc (envir, x), defaultS))) params;
  61.342  
  61.343  
  61.344      (* errors *)
    62.1 --- a/src/HOL/Tools/refute.ML	Thu Mar 03 09:22:35 2005 +0100
    62.2 +++ b/src/HOL/Tools/refute.ML	Thu Mar 03 12:43:01 2005 +0100
    62.3 @@ -93,7 +93,7 @@
    62.4  	fun tree_foldl f =
    62.5  	let
    62.6  		fun itl (e, Leaf x)  = f(e,x)
    62.7 -		  | itl (e, Node xs) = foldl (tree_foldl f) (e,xs)
    62.8 +		  | itl (e, Node xs) = Library.foldl (tree_foldl f) (e,xs)
    62.9  	in
   62.10  		itl
   62.11  	end;
   62.12 @@ -192,7 +192,7 @@
   62.13  			 parameters = Symtab.merge (op=) (pa1, pa2)};
   62.14  		fun print sg {interpreters, printers, parameters} =
   62.15  			Pretty.writeln (Pretty.chunks
   62.16 -				[Pretty.strs ("default parameters:" :: flat (map (fn (name,value) => [name, "=", value]) (Symtab.dest parameters))),
   62.17 +				[Pretty.strs ("default parameters:" :: List.concat (map (fn (name,value) => [name, "=", value]) (Symtab.dest parameters))),
   62.18  				 Pretty.strs ("interpreters:" :: map fst interpreters),
   62.19  				 Pretty.strs ("printers:" :: map fst printers)]);
   62.20  	end;
   62.21 @@ -250,7 +250,7 @@
   62.22  			if null terms then
   62.23  				"empty interpretation (no free variables in term)\n"
   62.24  			else
   62.25 -				space_implode "\n" (mapfilter (fn (t,intr) =>
   62.26 +				space_implode "\n" (List.mapPartial (fn (t,intr) =>
   62.27  					(* print constants only if 'show_consts' is true *)
   62.28  					if (!show_consts) orelse not (is_Const t) then
   62.29  						SOME (Sign.string_of_term (sign_of thy) t ^ ": " ^ Sign.string_of_term (sign_of thy) (print thy model t intr assignment))
   62.30 @@ -359,9 +359,9 @@
   62.31  		(* TODO: it is currently not possible to specify a size for a type     *)
   62.32  		(*       whose name is one of the other parameters (e.g. 'maxvars')    *)
   62.33  		(* (string * int) list *)
   62.34 -		val sizes     = mapfilter
   62.35 +		val sizes     = List.mapPartial
   62.36  			(fn (name,value) => (case Int.fromString value of SOME i => SOME (name, i) | NONE => NONE))
   62.37 -			(filter (fn (name,_) => name<>"minsize" andalso name<>"maxsize" andalso name<>"maxvars" andalso name<>"maxtime" andalso name<>"satsolver")
   62.38 +			(List.filter (fn (name,_) => name<>"minsize" andalso name<>"maxsize" andalso name<>"maxvars" andalso name<>"maxtime" andalso name<>"satsolver")
   62.39  				allparams)
   62.40  	in
   62.41  		{sizes=sizes, minsize=minsize, maxsize=maxsize, maxvars=maxvars, maxtime=maxtime, satsolver=satsolver}
   62.42 @@ -382,12 +382,12 @@
   62.43  
   62.44  	fun typ_of_dtyp descr typ_assoc (DatatypeAux.DtTFree a) =
   62.45  		(* replace a 'DtTFree' variable by the associated type *)
   62.46 -		(the o assoc) (typ_assoc, DatatypeAux.DtTFree a)
   62.47 +		(valOf o assoc) (typ_assoc, DatatypeAux.DtTFree a)
   62.48  	  | typ_of_dtyp descr typ_assoc (DatatypeAux.DtType (s, ds)) =
   62.49  		Type (s, map (typ_of_dtyp descr typ_assoc) ds)
   62.50  	  | typ_of_dtyp descr typ_assoc (DatatypeAux.DtRec i) =
   62.51  		let
   62.52 -			val (s, ds, _) = (the o assoc) (descr, i)
   62.53 +			val (s, ds, _) = (valOf o assoc) (descr, i)
   62.54  		in
   62.55  			Type (s, map (typ_of_dtyp descr typ_assoc) ds)
   62.56  		end;
   62.57 @@ -419,7 +419,7 @@
   62.58  	let
   62.59  		val _ = immediate_output "Adding axioms..."
   62.60  		(* (string * Term.term) list *)
   62.61 -		val axioms = flat (map (Symtab.dest o #axioms o Theory.rep_theory) (thy :: Theory.ancestors_of thy))
   62.62 +		val axioms = List.concat (map (Symtab.dest o #axioms o Theory.rep_theory) (thy :: Theory.ancestors_of thy))
   62.63  		(* string list *)
   62.64  		val rec_names = Symtab.foldl (fn (acc, (_, info)) =>
   62.65  			#rec_names info @ acc) ([], DatatypePackage.get_datatypes thy)
   62.66 @@ -478,7 +478,7 @@
   62.67  					let
   62.68  						(* obtain the axioms generated by the "axclass" command *)
   62.69  						(* (string * Term.term) list *)
   62.70 -						val class_axioms             = filter (fn (s, _) => String.isPrefix (class ^ ".axioms_") s) axioms
   62.71 +						val class_axioms             = List.filter (fn (s, _) => String.isPrefix (class ^ ".axioms_") s) axioms
   62.72  						(* replace the one schematic type variable in each axiom by the actual type 'T' *)
   62.73  						(* (string * Term.term) list *)
   62.74  						val monomorphic_class_axioms = map (fn (axname, ax) =>
   62.75 @@ -498,7 +498,7 @@
   62.76  								collect_term_axioms (ax :: axs, ax)
   62.77  							)
   62.78  					in
   62.79 -						foldl collect_axiom (axs, monomorphic_class_axioms)
   62.80 +						Library.foldl collect_axiom (axs, monomorphic_class_axioms)
   62.81  					end
   62.82  				(* string list *)
   62.83  				val sort = (case T of
   62.84 @@ -509,7 +509,7 @@
   62.85  				(* string list *)
   62.86  				val superclasses = Graph.all_succs ((#classes o Type.rep_tsig o Sign.tsig_of o sign_of) thy) sort
   62.87  			in
   62.88 -				foldl collect_class_axioms (axs, superclasses)
   62.89 +				Library.foldl collect_class_axioms (axs, superclasses)
   62.90  			end
   62.91  		(* Term.term list * Term.typ -> Term.term list *)
   62.92  		and collect_type_axioms (axs, T) =
   62.93 @@ -557,20 +557,20 @@
   62.94  					case DatatypePackage.datatype_info thy s of
   62.95  					  SOME info =>  (* inductive datatype *)
   62.96  							(* only collect relevant type axioms for the argument types *)
   62.97 -							foldl collect_type_axioms (axs, Ts)
   62.98 +							Library.foldl collect_type_axioms (axs, Ts)
   62.99  					| NONE =>
  62.100  						(case get_typedefn axioms of
  62.101  						  SOME (axname, ax) => 
  62.102  							if mem_term (ax, axs) then
  62.103  								(* only collect relevant type axioms for the argument types *)
  62.104 -								foldl collect_type_axioms (axs, Ts)
  62.105 +								Library.foldl collect_type_axioms (axs, Ts)
  62.106  							else
  62.107  								(immediate_output (" " ^ axname);
  62.108  								collect_term_axioms (ax :: axs, ax))
  62.109  						| NONE =>
  62.110  							(* unspecified type, perhaps introduced with 'typedecl' *)
  62.111  							(* at least collect relevant type axioms for the argument types *)
  62.112 -							foldl collect_type_axioms (axs, Ts))
  62.113 +							Library.foldl collect_type_axioms (axs, Ts))
  62.114  				end
  62.115  			| TFree _                => collect_sort_axioms (axs, T)  (* axiomatic type classes *)
  62.116  			| TVar _                 => collect_sort_axioms (axs, T)  (* axiomatic type classes *)
  62.117 @@ -590,7 +590,7 @@
  62.118  			| Const ("arbitrary", T)          => collect_type_axioms (axs, T)
  62.119  			| Const ("The", T)                =>
  62.120  				let
  62.121 -					val ax = specialize_type (("The", T), (the o assoc) (axioms, "HOL.the_eq_trivial"))
  62.122 +					val ax = specialize_type (("The", T), (valOf o assoc) (axioms, "HOL.the_eq_trivial"))
  62.123  				in
  62.124  					if mem_term (ax, axs) then
  62.125  						collect_type_axioms (axs, T)
  62.126 @@ -600,7 +600,7 @@
  62.127  				end
  62.128  			| Const ("Hilbert_Choice.Eps", T) =>
  62.129  				let
  62.130 -					val ax = specialize_type (("Hilbert_Choice.Eps", T), (the o assoc) (axioms, "Hilbert_Choice.someI"))
  62.131 +					val ax = specialize_type (("Hilbert_Choice.Eps", T), (valOf o assoc) (axioms, "Hilbert_Choice.someI"))
  62.132  				in
  62.133  					if mem_term (ax, axs) then
  62.134  						collect_type_axioms (axs, T)
  62.135 @@ -686,7 +686,7 @@
  62.136  							val inclass = Logic.mk_inclass (TVar (("'a", 0), [class]), class)
  62.137  							(* Term.term option *)
  62.138  							val ofclass_ax = (SOME (specialize_type ((s, T), inclass)) handle Type.TYPE_MATCH => NONE)
  62.139 -							val intro_ax   = (apsome (fn t => specialize_type ((s, T), t)) (assoc (axioms, class ^ ".intro")) handle Type.TYPE_MATCH => NONE)
  62.140 +							val intro_ax   = (Option.map (fn t => specialize_type ((s, T), t)) (assoc (axioms, class ^ ".intro")) handle Type.TYPE_MATCH => NONE)
  62.141  							val axs'       = (case ofclass_ax of NONE => axs | SOME ax => if mem_term (ax, axs) then
  62.142  									(* collect relevant type axioms *)
  62.143  									collect_type_axioms (axs, T)
  62.144 @@ -734,7 +734,7 @@
  62.145  			(* (Term.indexname * Term.typ) list *)
  62.146  			val vars = sort_wrt (fst o fst) (map dest_Var (term_vars t))
  62.147  		in
  62.148 -			foldl
  62.149 +			Library.foldl
  62.150  				(fn (t', ((x, i), T)) => (Term.all T) $ Abs (x, T, abstract_over (Var((x, i), T), t')))
  62.151  				(t, vars)
  62.152  		end
  62.153 @@ -772,7 +772,7 @@
  62.154  						let
  62.155  							val index               = #index info
  62.156  							val descr               = #descr info
  62.157 -							val (_, dtyps, constrs) = (the o assoc) (descr, index)
  62.158 +							val (_, dtyps, constrs) = (valOf o assoc) (descr, index)
  62.159  							val typ_assoc           = dtyps ~~ Ts
  62.160  							(* sanity check: every element in 'dtyps' must be a 'DtTFree' *)
  62.161  							val _ = (if Library.exists (fn d =>
  62.162 @@ -787,14 +787,14 @@
  62.163  								else
  62.164  									acc)
  62.165  							(* collect argument types *)
  62.166 -							val acc_args = foldr collect_types (Ts, acc')
  62.167 +							val acc_args = Library.foldr collect_types (Ts, acc')
  62.168  							(* collect constructor types *)
  62.169 -							val acc_constrs = foldr collect_types (flat (map (fn (_, ds) => map (typ_of_dtyp descr typ_assoc) ds) constrs), acc_args)
  62.170 +							val acc_constrs = Library.foldr collect_types (List.concat (map (fn (_, ds) => map (typ_of_dtyp descr typ_assoc) ds) constrs), acc_args)
  62.171  						in
  62.172  							acc_constrs
  62.173  						end
  62.174  					| NONE =>  (* not an inductive datatype, e.g. defined via "typedef" or "typedecl" *)
  62.175 -						T ins (foldr collect_types (Ts, acc)))
  62.176 +						T ins (Library.foldr collect_types (Ts, acc)))
  62.177  				| TFree _                => T ins acc
  62.178  				| TVar _                 => T ins acc)
  62.179  	in
  62.180 @@ -853,9 +853,9 @@
  62.181  				NONE
  62.182  		  | make_first max len sum =
  62.183  			if sum<=max orelse max<0 then
  62.184 -				apsome (fn xs' => sum :: xs') (make_first max (len-1) 0)
  62.185 +				Option.map (fn xs' => sum :: xs') (make_first max (len-1) 0)
  62.186  			else
  62.187 -				apsome (fn xs' => max :: xs') (make_first max (len-1) (sum-max))
  62.188 +				Option.map (fn xs' => max :: xs') (make_first max (len-1) (sum-max))
  62.189  		(* enumerates all int lists with a fixed length, where 0<=x<='max' for *)
  62.190  		(* all list elements x (unless 'max'<0)                                *)
  62.191  		(* int -> int -> int -> int list -> int list option *)
  62.192 @@ -867,12 +867,12 @@
  62.193  		  | next max len sum (x1::x2::xs) =
  62.194  			if x1>0 andalso (x2<max orelse max<0) then
  62.195  				(* we can shift *)
  62.196 -				SOME (the (make_first max (len+1) (sum+x1-1)) @ (x2+1) :: xs)
  62.197 +				SOME (valOf (make_first max (len+1) (sum+x1-1)) @ (x2+1) :: xs)
  62.198  			else
  62.199  				(* continue search *)
  62.200  				next max (len+1) (sum+x1) (x2::xs)
  62.201  		(* only consider those types for which the size is not fixed *)
  62.202 -		val mutables = filter (fn (T, _) => assoc (sizes, string_of_typ T) = NONE) xs
  62.203 +		val mutables = List.filter (fn (T, _) => assoc (sizes, string_of_typ T) = NONE) xs
  62.204  		(* subtract 'minsize' from every size (will be added again at the end) *)
  62.205  		val diffs = map (fn (_, n) => n-minsize) mutables
  62.206  	in
  62.207 @@ -931,7 +931,7 @@
  62.208  			(* Term.term list *)
  62.209  			val axioms = collect_axioms thy t
  62.210  			(* Term.typ list *)
  62.211 -			val types  = foldl (fn (acc, t') => acc union (ground_types thy t')) ([], t :: axioms)
  62.212 +			val types  = Library.foldl (fn (acc, t') => acc union (ground_types thy t')) ([], t :: axioms)
  62.213  			val _      = writeln ("Ground types: "
  62.214  				^ (if null types then "none."
  62.215  				   else commas (map (Sign.string_of_typ (sign_of thy)) types)))
  62.216 @@ -945,7 +945,7 @@
  62.217  						let
  62.218  							val index           = #index info
  62.219  							val descr           = #descr info
  62.220 -							val (_, _, constrs) = (the o assoc) (descr, index)
  62.221 +							val (_, _, constrs) = (valOf o assoc) (descr, index)
  62.222  						in
  62.223  							(* recursive datatype? *)
  62.224  							Library.exists (fn (_, ds) => Library.exists DatatypeAux.is_rec_type ds) constrs
  62.225 @@ -1053,7 +1053,7 @@
  62.226  		(* (Term.indexname * Term.typ) list *)
  62.227  		val vars = sort_wrt (fst o fst) (map dest_Var (term_vars t))
  62.228  		(* Term.term *)
  62.229 -		val ex_closure = foldl
  62.230 +		val ex_closure = Library.foldl
  62.231  			(fn (t', ((x,i),T)) => (HOLogic.exists_const T) $ Abs (x, T, abstract_over (Var((x,i),T), t')))
  62.232  			(t, vars)
  62.233  		(* If 't' is of type 'propT' (rather than 'boolT'), applying  *)
  62.234 @@ -1075,7 +1075,7 @@
  62.235  	(* theory -> (string * string) list -> Thm.thm -> int -> unit *)
  62.236  
  62.237  	fun refute_subgoal thy params thm subgoal =
  62.238 -		refute_term thy params (nth_elem (subgoal, prems_of thm));
  62.239 +		refute_term thy params (List.nth (prems_of thm, subgoal));
  62.240  
  62.241  
  62.242  (* ------------------------------------------------------------------------- *)
  62.243 @@ -1116,7 +1116,7 @@
  62.244  			map (fn x => [x]) xs
  62.245  		  | pick_all n xs =
  62.246  			let val rec_pick = pick_all (n-1) xs in
  62.247 -				foldl (fn (acc,x) => (cons_list x rec_pick) @ acc) ([],xs)
  62.248 +				Library.foldl (fn (acc,x) => (cons_list x rec_pick) @ acc) ([],xs)
  62.249  			end
  62.250  	in
  62.251  		case intr of
  62.252 @@ -1269,7 +1269,7 @@
  62.253  			map (fn x => [x]) xs
  62.254  		  | pick_all (xs::xss) =
  62.255  			let val rec_pick = pick_all xss in
  62.256 -				foldl (fn (acc,x) => (cons_list x rec_pick) @ acc) ([],xs)
  62.257 +				Library.foldl (fn (acc,x) => (cons_list x rec_pick) @ acc) ([],xs)
  62.258  			end
  62.259  		  | pick_all _ =
  62.260  			raise REFUTE ("interpretation_apply", "empty list (in pick_all)")
  62.261 @@ -1296,8 +1296,8 @@
  62.262  	let
  62.263  		val Ts = binder_types (fastype_of t)
  62.264  	in
  62.265 -		foldr (fn (T, t) => Abs ("<eta_expand>", T, t))
  62.266 -			(take (i, Ts), list_comb (t, map Bound (i-1 downto 0)))
  62.267 +		Library.foldr (fn (T, t) => Abs ("<eta_expand>", T, t))
  62.268 +			(Library.take (i, Ts), list_comb (t, map Bound (i-1 downto 0)))
  62.269  	end;
  62.270  
  62.271  (* ------------------------------------------------------------------------- *)
  62.272 @@ -1306,7 +1306,7 @@
  62.273  
  62.274  	(* int list -> int *)
  62.275  
  62.276 -	fun sum xs = foldl op+ (0, xs);
  62.277 +	fun sum xs = Library.foldl op+ (0, xs);
  62.278  
  62.279  (* ------------------------------------------------------------------------- *)
  62.280  (* product: returns the product of a list 'xs' of integers                   *)
  62.281 @@ -1314,7 +1314,7 @@
  62.282  
  62.283  	(* int list -> int *)
  62.284  
  62.285 -	fun product xs = foldl op* (1, xs);
  62.286 +	fun product xs = Library.foldl op* (1, xs);
  62.287  
  62.288  (* ------------------------------------------------------------------------- *)
  62.289  (* size_of_dtyp: the size of (an initial fragment of) an inductive data type *)
  62.290 @@ -1354,7 +1354,7 @@
  62.291  			(* unit -> (interpretation * model * arguments) option *)
  62.292  			fun interpret_groundtype () =
  62.293  			let
  62.294 -				val size = (if T = Term.propT then 2 else (the o assoc) (typs, T))                    (* the model MUST specify a size for ground types *)
  62.295 +				val size = (if T = Term.propT then 2 else (valOf o assoc) (typs, T))                    (* the model MUST specify a size for ground types *)
  62.296  				val next = next_idx+size
  62.297  				val _    = (if next-1>maxvars andalso maxvars>0 then raise MAXVARS_EXCEEDED else ())  (* check if 'maxvars' is large enough *)
  62.298  				(* prop_formula list *)
  62.299 @@ -1416,7 +1416,7 @@
  62.300  			| Var (_, T)       =>
  62.301  				interpret_groundterm T
  62.302  			| Bound i          =>
  62.303 -				SOME (nth_elem (i, #bounds args), model, args)
  62.304 +				SOME (List.nth (#bounds args, i), model, args)
  62.305  			| Abs (x, T, body) =>
  62.306  				let
  62.307  					(* create all constants of type 'T' *)
  62.308 @@ -1656,7 +1656,7 @@
  62.309  						let
  62.310  							val index               = #index info
  62.311  							val descr               = #descr info
  62.312 -							val (_, dtyps, constrs) = (the o assoc) (descr, index)
  62.313 +							val (_, dtyps, constrs) = (valOf o assoc) (descr, index)
  62.314  							val typ_assoc           = dtyps ~~ Ts
  62.315  							(* sanity check: every element in 'dtyps' must be a 'DtTFree' *)
  62.316  							val _ = (if Library.exists (fn d =>
  62.317 @@ -1723,7 +1723,7 @@
  62.318  						let
  62.319  							val index               = #index info
  62.320  							val descr               = #descr info
  62.321 -							val (_, dtyps, constrs) = (the o assoc) (descr, index)
  62.322 +							val (_, dtyps, constrs) = (valOf o assoc) (descr, index)
  62.323  							val typ_assoc           = dtyps ~~ Ts'
  62.324  							(* sanity check: every element in 'dtyps' must be a 'DtTFree' *)
  62.325  							val _ = (if Library.exists (fn d =>
  62.326 @@ -1846,7 +1846,7 @@
  62.327  									(* after it generate further elements                                    *)
  62.328  									val offset = size_of_dtyp thy typs' descr typ_assoc constrs1 +
  62.329  										(if is_rec_constr ctypes then
  62.330 -											size_of_dtyp thy typs' descr typ_assoc (filter (not o is_rec_constr o snd) cs)
  62.331 +											size_of_dtyp thy typs' descr typ_assoc (List.filter (not o is_rec_constr o snd) cs)
  62.332  										else
  62.333  											0)
  62.334  								in
  62.335 @@ -1904,7 +1904,7 @@
  62.336  						let
  62.337  							val index               = #index info
  62.338  							val descr               = #descr info
  62.339 -							val (_, dtyps, constrs) = (the o assoc) (descr, index)
  62.340 +							val (_, dtyps, constrs) = (valOf o assoc) (descr, index)
  62.341  							(* the total number of constructors, including those of different    *)
  62.342  							(* (mutually recursive) datatypes within the same descriptor 'descr' *)
  62.343  							val constrs_count = sum (map (fn (_, (_, _, cs)) => length cs) descr)
  62.344 @@ -1931,7 +1931,7 @@
  62.345  										end) ((model, args), params)
  62.346  									val (typs, terms) = model'
  62.347  									(* the type of a recursion operator: [T1, ..., Tn, IDT] ---> Tresult *)
  62.348 -									val IDT       = nth_elem (constrs_count, binder_types T)
  62.349 +									val IDT       = List.nth (binder_types T, constrs_count)
  62.350  									val typ_assoc = dtyps ~~ (snd o dest_Type) IDT
  62.351  									(* interpret each constructor of the datatype *)
  62.352  									(* TODO: we probably need to interpret every constructor in the descriptor, *)
  62.353 @@ -1993,13 +1993,13 @@
  62.354  												  | select_subtree (Leaf _, _) =
  62.355  													raise REFUTE ("IDT_recursion_interpreter", "interpretation for parameter is a leaf; cannot select a subtree")
  62.356  												  | select_subtree (Node tr, x::xs) =
  62.357 -													select_subtree (nth_elem (x, tr), xs)
  62.358 +													select_subtree (List.nth (tr, x), xs)
  62.359  												(* select the correct subtree of the parameter corresponding to constructor 'c' *)
  62.360 -												val p_intr = select_subtree (nth_elem (c, p_intrs), args)
  62.361 +												val p_intr = select_subtree (List.nth (p_intrs, c), args)
  62.362  												(* find the indices of recursive arguments *)
  62.363 -												val rec_args = map snd (filter (DatatypeAux.is_rec_type o fst) ((snd (nth_elem (c, constrs))) ~~ args))
  62.364 +												val rec_args = map snd (List.filter (DatatypeAux.is_rec_type o fst) ((snd (List.nth (constrs, c))) ~~ args))
  62.365  												(* apply 'p_intr' to recursively computed results *)
  62.366 -												val rec_p_intr = foldl (fn (i, n) => interpretation_apply (i, Array.sub (INTRS, n))) (p_intr, rec_args)
  62.367 +												val rec_p_intr = Library.foldl (fn (i, n) => interpretation_apply (i, Array.sub (INTRS, n))) (p_intr, rec_args)
  62.368  												(* update 'INTRS' *)
  62.369  												val _ = Array.update (INTRS, elem, rec_p_intr)
  62.370  											in
  62.371 @@ -2036,7 +2036,7 @@
  62.372  				val constants     = make_constants i_set
  62.373  				(* interpretation -> int *)
  62.374  				fun number_of_elements (Node xs) =
  62.375 -					foldl (fn (n, x) =>
  62.376 +					Library.foldl (fn (n, x) =>
  62.377  						if x=TT then
  62.378  							n+1
  62.379  						else if x=FF then
  62.380 @@ -2214,7 +2214,7 @@
  62.381  					val HOLogic_empty_set = Const ("{}", HOLogic_setT)
  62.382  					val HOLogic_insert    = Const ("insert", HOLogic_prodT --> HOLogic_setT --> HOLogic_setT)
  62.383  				in
  62.384 -					SOME (foldr (fn (pair, acc) => HOLogic_insert $ pair $ acc) (pairs, HOLogic_empty_set))
  62.385 +					SOME (Library.foldr (fn (pair, acc) => HOLogic_insert $ pair $ acc) (pairs, HOLogic_empty_set))
  62.386  				end
  62.387  			| Type ("prop", [])      =>
  62.388  				(case index_from_interpretation intr of
  62.389 @@ -2259,7 +2259,7 @@
  62.390  					  Node xs => xs
  62.391  					| _       => raise REFUTE ("set_printer", "interpretation for set type is a leaf"))
  62.392  				(* Term.term list *)
  62.393 -				val elements = mapfilter (fn (arg, result) =>
  62.394 +				val elements = List.mapPartial (fn (arg, result) =>
  62.395  					case result of
  62.396  					  Leaf [fmTrue, fmFalse] =>
  62.397  						if PropLogic.eval assignment fmTrue then
  62.398 @@ -2275,7 +2275,7 @@
  62.399  				val HOLogic_empty_set = Const ("{}", HOLogic_setT)
  62.400  				val HOLogic_insert    = Const ("insert", T --> HOLogic_setT --> HOLogic_setT)
  62.401  			in
  62.402 -				SOME (foldl (fn (acc, elem) => HOLogic_insert $ elem $ acc) (HOLogic_empty_set, elements))
  62.403 +				SOME (Library.foldl (fn (acc, elem) => HOLogic_insert $ elem $ acc) (HOLogic_empty_set, elements))
  62.404  			end
  62.405  		| _ =>
  62.406  			NONE
  62.407 @@ -2299,7 +2299,7 @@
  62.408  					val (typs, _)           = model
  62.409  					val index               = #index info
  62.410  					val descr               = #descr info
  62.411 -					val (_, dtyps, constrs) = (the o assoc) (descr, index)
  62.412 +					val (_, dtyps, constrs) = (valOf o assoc) (descr, index)
  62.413  					val typ_assoc           = dtyps ~~ Ts
  62.414  					(* sanity check: every element in 'dtyps' must be a 'DtTFree' *)
  62.415  					val _ = (if Library.exists (fn d =>
  62.416 @@ -2345,7 +2345,7 @@
  62.417  										search (xs, 0)
  62.418  									end
  62.419  							in
  62.420 -								apsome (fn args => (cTerm, cargs, args)) (get_args iC)
  62.421 +								Option.map (fn args => (cTerm, cargs, args)) (get_args iC)
  62.422  							end
  62.423  						(* Term.term * DatatypeAux.dtyp list * int list *)
  62.424  						val (cTerm, cargs, args) = (case get_first get_constr_args constrs of
  62.425 @@ -2359,10 +2359,10 @@
  62.426  									(* list, so there might be a more efficient implementation that does    *)
  62.427  									(* not generate all constants                                           *)
  62.428  							in
  62.429 -								print thy (typs, []) (Free ("dummy", dT)) (nth_elem (n, consts)) assignment
  62.430 +								print thy (typs, []) (Free ("dummy", dT)) (List.nth (consts, n)) assignment
  62.431  							end) (cargs ~~ args)
  62.432  					in
  62.433 -						SOME (foldl op$ (cTerm, argsTerms))
  62.434 +						SOME (Library.foldl op$ (cTerm, argsTerms))
  62.435  					end
  62.436  				end
  62.437  			| NONE =>  (* not an inductive datatype *)
    63.1 --- a/src/HOL/Tools/refute_isar.ML	Thu Mar 03 09:22:35 2005 +0100
    63.2 +++ b/src/HOL/Tools/refute_isar.ML	Thu Mar 03 12:43:01 2005 +0100
    63.3 @@ -48,7 +48,7 @@
    63.4  					val thy              = (Toplevel.theory_of state)
    63.5  					val thm              = ((snd o snd) (Proof.get_goal (Toplevel.proof_of state)))
    63.6  				in
    63.7 -					Refute.refute_subgoal thy (if_none parms []) thm ((if_none subgoal 1)-1)
    63.8 +					Refute.refute_subgoal thy (getOpt (parms, [])) thm ((getOpt (subgoal, 1))-1)
    63.9  				end)
   63.10  			);
   63.11  
   63.12 @@ -79,7 +79,7 @@
   63.13  		in
   63.14  			Toplevel.theory (fn thy =>
   63.15  				let
   63.16 -					val thy'               = add_params (thy, (if_none args []))
   63.17 +					val thy'               = add_params (thy, (getOpt (args, [])))
   63.18  					val new_default_params = Refute.get_default_params thy'
   63.19  					val output             = if new_default_params=[] then "none" else (space_implode "\n" (map (fn (name,value) => name ^ "=" ^ value) new_default_params))
   63.20  				in
    64.1 --- a/src/HOL/Tools/rewrite_hol_proof.ML	Thu Mar 03 09:22:35 2005 +0100
    64.2 +++ b/src/HOL/Tools/rewrite_hol_proof.ML	Thu Mar 03 12:43:01 2005 +0100
    64.3 @@ -311,15 +311,15 @@
    64.4  fun mk_AbsP P t = AbsP ("H", P, t);
    64.5  
    64.6  fun elim_cong Ts (PThm (("HOL.iffD1", _), _, _, _) % _ % _ %% prf1 %% prf2) =
    64.7 -      apsome (make_subst Ts prf2 []) (strip_cong [] prf1)
    64.8 +      Option.map (make_subst Ts prf2 []) (strip_cong [] prf1)
    64.9    | elim_cong Ts (PThm (("HOL.iffD1", _), _, _, _) % P % _ %% prf) =
   64.10 -      apsome (mk_AbsP P o make_subst Ts (PBound 0) [])
   64.11 +      Option.map (mk_AbsP P o make_subst Ts (PBound 0) [])
   64.12          (strip_cong [] (incr_pboundvars 1 0 prf))
   64.13    | elim_cong Ts (PThm (("HOL.iffD2", _), _, _, _) % _ % _ %% prf1 %% prf2) =
   64.14 -      apsome (make_subst Ts prf2 [] o
   64.15 +      Option.map (make_subst Ts prf2 [] o
   64.16          apsnd (map (make_sym Ts))) (strip_cong [] prf1)
   64.17    | elim_cong Ts (PThm (("HOL.iffD2", _), _, _, _) % _ % P %% prf) =
   64.18 -      apsome (mk_AbsP P o make_subst Ts (PBound 0) [] o
   64.19 +      Option.map (mk_AbsP P o make_subst Ts (PBound 0) [] o
   64.20          apsnd (map (make_sym Ts))) (strip_cong [] (incr_pboundvars 1 0 prf))
   64.21    | elim_cong _ _ = NONE;
   64.22  
    65.1 --- a/src/HOL/Tools/sat_solver.ML	Thu Mar 03 09:22:35 2005 +0100
    65.2 +++ b/src/HOL/Tools/sat_solver.ML	Thu Mar 03 12:43:01 2005 +0100
    65.3 @@ -193,7 +193,7 @@
    65.4  			NONE
    65.5  		(* string -> int list *)
    65.6  		fun int_list_from_string s =
    65.7 -			mapfilter (option o Int.fromString) (space_explode " " s)
    65.8 +			List.mapPartial (option o Int.fromString) (space_explode " " s)
    65.9  		(* int list -> assignment *)
   65.10  		fun assignment_from_list [] i =
   65.11  			NONE  (* the SAT solver didn't provide a value for this variable *)
   65.12 @@ -232,7 +232,7 @@
   65.13  			else
   65.14  				parse_lines lines
   65.15  	in
   65.16 -		(parse_lines o (filter (fn l => l <> "")) o split_lines o File.read) path
   65.17 +		(parse_lines o (List.filter (fn l => l <> "")) o split_lines o File.read) path
   65.18  	end;
   65.19  
   65.20  (* ------------------------------------------------------------------------- *)
   65.21 @@ -310,10 +310,10 @@
   65.22  		o (map (map literal_from_int))
   65.23  		o clauses
   65.24  		o (map int_from_string)
   65.25 -		o flat
   65.26 +		o List.concat
   65.27  		o (map (String.fields (fn c => c mem [#" ", #"\t", #"\n"])))
   65.28  		o filter_preamble
   65.29 -		o (filter (fn l => l <> ""))
   65.30 +		o (List.filter (fn l => l <> ""))
   65.31  		o split_lines
   65.32  		o File.read)
   65.33  			path
   65.34 @@ -343,7 +343,7 @@
   65.35  	(* string -> solver *)
   65.36  
   65.37  	fun invoke_solver name =
   65.38 -		(the o assoc) (!solvers, name);
   65.39 +		(valOf o assoc) (!solvers, name);
   65.40  
   65.41  end;  (* SatSolver *)
   65.42  
   65.43 @@ -458,7 +458,7 @@
   65.44  				| False => NONE
   65.45  				| _     =>
   65.46  					let
   65.47 -						val x = the (fresh_var xs')  (* a fresh variable must exist since 'fm' did not evaluate to 'True'/'False' *)
   65.48 +						val x = valOf (fresh_var xs')  (* a fresh variable must exist since 'fm' did not evaluate to 'True'/'False' *)
   65.49  					in
   65.50  						case dpll (x::xs') fm' of  (* passing fm' rather than fm should save some simplification work *)
   65.51  						  SOME xs'' => SOME xs''
    66.1 --- a/src/HOL/Tools/specification_package.ML	Thu Mar 03 09:22:35 2005 +0100
    66.2 +++ b/src/HOL/Tools/specification_package.ML	Thu Mar 03 12:43:01 2005 +0100
    66.3 @@ -141,7 +141,7 @@
    66.4  		val tsig = Sign.tsig_of (sign_of thy)
    66.5  		val _ = assert (forall (fn v => Type.of_sort tsig (type_of v,HOLogic.typeS)) frees)
    66.6  			       "Specificaton: Only free variables of sort 'type' allowed"
    66.7 -		val prop_closed = foldr (fn ((vname,T),prop) => HOLogic.mk_all (vname,T,prop)) (map dest_Free frees,prop)
    66.8 +		val prop_closed = Library.foldr (fn ((vname,T),prop) => HOLogic.mk_all (vname,T,prop)) (map dest_Free frees,prop)
    66.9  	    in
   66.10  		(prop_closed,frees)
   66.11  	    end
   66.12 @@ -164,7 +164,7 @@
   66.13  		val c' = fst (Type.varify (c,[]))
   66.14  		val (cname,ctyp) = dest_Const c'
   66.15  	    in
   66.16 -		case filter (fn t => let val (name,typ) = dest_Const t
   66.17 +		case List.filter (fn t => let val (name,typ) = dest_Const t
   66.18  				     in name = cname andalso typ_equiv typ ctyp
   66.19  				     end) thawed_prop_consts of
   66.20  		    [] => error ("Specification: No suitable instances of constant \"" ^ (Sign.string_of_term sg c) ^ "\" found")
   66.21 @@ -182,7 +182,7 @@
   66.22  	    in
   66.23  		HOLogic.exists_const T $ Abs(vname,T,Term.abstract_over (c,prop))
   66.24  	    end
   66.25 -	val ex_prop = foldr mk_exist (proc_consts,prop)
   66.26 +	val ex_prop = Library.foldr mk_exist (proc_consts,prop)
   66.27  	val cnames = map (fst o dest_Const) proc_consts
   66.28  	fun post_process (arg as (thy,thm)) =
   66.29  	    let
   66.30 @@ -194,7 +194,7 @@
   66.31  		    in
   66.32  			thm RS spec'
   66.33  		    end
   66.34 -		fun remove_alls frees thm = foldl (inst_all (sign_of_thm thm)) (thm,frees)
   66.35 +		fun remove_alls frees thm = Library.foldl (inst_all (sign_of_thm thm)) (thm,frees)
   66.36  		fun process_single ((name,atts),rew_imp,frees) args =
   66.37  		    let
   66.38  			fun undo_imps thm =
    67.1 --- a/src/HOL/Tools/split_rule.ML	Thu Mar 03 09:22:35 2005 +0100
    67.2 +++ b/src/HOL/Tools/split_rule.ML	Thu Mar 03 12:43:01 2005 +0100
    67.3 @@ -66,7 +66,7 @@
    67.4  (* complete splitting of partially splitted rules *)
    67.5  
    67.6  fun ap_split' (T::Ts) U u = Abs ("v", T, ap_split' Ts U
    67.7 -      (ap_split T (flat (map HOLogic.prodT_factors Ts) ---> U)
    67.8 +      (ap_split T (List.concat (map HOLogic.prodT_factors Ts) ---> U)
    67.9          (incr_boundvars 1 u) $ Bound 0))
   67.10    | ap_split' _ _ u = u;
   67.11  
   67.12 @@ -74,9 +74,9 @@
   67.13        let
   67.14          val cterm = Thm.cterm_of (#sign (Thm.rep_thm rl))
   67.15          val (Us', U') = strip_type T;
   67.16 -        val Us = take (length ts, Us');
   67.17 -        val U = drop (length ts, Us') ---> U';
   67.18 -        val T' = flat (map HOLogic.prodT_factors Us) ---> U;
   67.19 +        val Us = Library.take (length ts, Us');
   67.20 +        val U = Library.drop (length ts, Us') ---> U';
   67.21 +        val T' = List.concat (map HOLogic.prodT_factors Us) ---> U;
   67.22          fun mk_tuple ((xs, insts), v as Var ((a, _), T)) =
   67.23                let
   67.24                  val Ts = HOLogic.prodT_factors T;
   67.25 @@ -87,7 +87,7 @@
   67.26            | mk_tuple (x, _) = x;
   67.27          val newt = ap_split' Us U (Var (v, T'));
   67.28          val cterm = Thm.cterm_of (#sign (Thm.rep_thm rl));
   67.29 -        val (vs', insts) = foldl mk_tuple ((vs, []), ts);
   67.30 +        val (vs', insts) = Library.foldl mk_tuple ((vs, []), ts);
   67.31        in
   67.32          (instantiate ([], [(cterm t, cterm newt)] @ insts) rl, vs')
   67.33        end
   67.34 @@ -96,19 +96,19 @@
   67.35  fun collect_vars (vs, Abs (_, _, t)) = collect_vars (vs, t)
   67.36    | collect_vars (vs, t) = (case strip_comb t of
   67.37          (v as Var _, ts) => (v, ts)::vs
   67.38 -      | (t, ts) => foldl collect_vars (vs, ts));
   67.39 +      | (t, ts) => Library.foldl collect_vars (vs, ts));
   67.40  
   67.41  
   67.42  val split_rule_var = Drule.standard o remove_internal_split o split_rule_var';
   67.43  
   67.44  (*curries ALL function variables occurring in a rule's conclusion*)
   67.45  fun split_rule rl =
   67.46 -  foldr split_rule_var' (Term.term_vars (concl_of rl), rl)
   67.47 +  Library.foldr split_rule_var' (Term.term_vars (concl_of rl), rl)
   67.48    |> remove_internal_split
   67.49    |> Drule.standard;
   67.50  
   67.51  fun complete_split_rule rl =
   67.52 -  fst (foldr complete_split_rule_var
   67.53 +  fst (Library.foldr complete_split_rule_var
   67.54      (collect_vars ([], concl_of rl),
   67.55        (rl, map (fst o fst o dest_Var) (Term.term_vars (#prop (Thm.rep_thm rl))))))
   67.56    |> remove_internal_split
   67.57 @@ -121,7 +121,7 @@
   67.58  fun split_rule_goal xss rl =
   67.59    let
   67.60      fun one_split i (th, s) = Tactic.rule_by_tactic (pair_tac s i) th;
   67.61 -    fun one_goal (xs, i) th = foldl (one_split i) (th, xs);
   67.62 +    fun one_goal (xs, i) th = Library.foldl (one_split i) (th, xs);
   67.63    in
   67.64      Drule.standard (Simplifier.full_simplify split_rule_ss (Library.foldln one_goal xss rl))
   67.65      |> RuleCases.save rl
    68.1 --- a/src/HOL/Tools/typedef_package.ML	Thu Mar 03 09:22:35 2005 +0100
    68.2 +++ b/src/HOL/Tools/typedef_package.ML	Thu Mar 03 12:43:01 2005 +0100
    68.3 @@ -104,9 +104,9 @@
    68.4      val thms = PureThy.get_thmss thy (map (rpair NONE) witn_names) @ witn_thms;
    68.5      val tac =
    68.6        witn1_tac THEN
    68.7 -      TRY (rewrite_goals_tac (filter is_def thms)) THEN
    68.8 +      TRY (rewrite_goals_tac (List.filter is_def thms)) THEN
    68.9        TRY (REPEAT_FIRST (resolve_tac (filter_out is_def thms))) THEN
   68.10 -      if_none witn2_tac (TRY (ALLGOALS (CLASET' blast_tac)));
   68.11 +      getOpt (witn2_tac, TRY (ALLGOALS (CLASET' blast_tac)));
   68.12    in
   68.13      message ("Proving non-emptiness of set " ^ quote (string_of_cterm cset) ^ " ...");
   68.14      Tactic.prove (Theory.sign_of thy) [] [] goal (K tac)
   68.15 @@ -144,12 +144,12 @@
   68.16      val goal_pat = mk_nonempty (Var (vname, setT));
   68.17  
   68.18      (*lhs*)
   68.19 -    val lhs_tfrees = map (fn v => (v, if_none (assoc (rhs_tfrees, v)) HOLogic.typeS)) vs;
   68.20 +    val lhs_tfrees = map (fn v => (v, getOpt (assoc (rhs_tfrees, v), HOLogic.typeS))) vs;
   68.21      val tname = Syntax.type_name t mx;
   68.22      val full_tname = full tname;
   68.23      val newT = Type (full_tname, map TFree lhs_tfrees);
   68.24  
   68.25 -    val (Rep_name, Abs_name) = if_none opt_morphs ("Rep_" ^ name, "Abs_" ^ name);
   68.26 +    val (Rep_name, Abs_name) = getOpt (opt_morphs, ("Rep_" ^ name, "Abs_" ^ name));
   68.27      val setC = Const (full_name, setT);
   68.28      val RepC = Const (full Rep_name, newT --> oldT);
   68.29      val AbsC = Const (full Abs_name, oldT --> newT);
   68.30 @@ -251,7 +251,7 @@
   68.31  
   68.32  fun sane_typedef prep_term def opt_name typ set opt_morphs tac =
   68.33    gen_typedef prep_term def
   68.34 -    (if_none opt_name (#1 typ)) typ set opt_morphs all_tac [] [] (SOME tac);
   68.35 +    (getOpt (opt_name, #1 typ)) typ set opt_morphs all_tac [] [] (SOME tac);
   68.36  
   68.37  fun add_typedef_x name typ set names thms tac =
   68.38    #1 o gen_typedef read_term true name typ set NONE (Tactic.rtac exI 1) names thms tac;
   68.39 @@ -287,8 +287,8 @@
   68.40        in SOME (gr'', Codegen.mk_app brack (Pretty.str id) ps) end;
   68.41      fun get_name (Type (tname, _)) = tname
   68.42        | get_name _ = "";
   68.43 -    fun lookup f T = if_none (apsome f (Symtab.lookup
   68.44 -      (TypedefData.get thy, get_name T))) ""
   68.45 +    fun lookup f T = getOpt (Option.map f (Symtab.lookup
   68.46 +      (TypedefData.get thy, get_name T)), "")
   68.47    in
   68.48      (case strip_comb t of
   68.49         (Const (s, Type ("fun", [T, U])), ts) =>
   68.50 @@ -310,7 +310,7 @@
   68.51        (case Symtab.lookup (TypedefData.get thy, s) of
   68.52           NONE => NONE
   68.53         | SOME (newT as Type (tname, Us), oldT, Abs_name, Rep_name) =>
   68.54 -           if is_some (Codegen.get_assoc_type thy tname) then NONE else
   68.55 +           if isSome (Codegen.get_assoc_type thy tname) then NONE else
   68.56             let
   68.57               val sg = sign_of thy;
   68.58               val Abs_id = Codegen.mk_const_id sg Abs_name;
   68.59 @@ -382,7 +382,7 @@
   68.60      Scan.option (P.$$$ "morphisms" |-- P.!!! (P.name -- P.name));
   68.61  
   68.62  fun mk_typedef_proof ((((((def, opt_name), (vs, t)), mx), A), morphs)) =
   68.63 -  typedef_proof ((def, if_none opt_name (Syntax.type_name t mx)), (t, vs, mx), A, morphs);
   68.64 +  typedef_proof ((def, getOpt (opt_name, Syntax.type_name t mx)), (t, vs, mx), A, morphs);
   68.65  
   68.66  val typedefP =
   68.67    OuterSyntax.command "typedef" "HOL type definition (requires non-emptiness proof)" K.thy_goal
    69.1 --- a/src/HOL/arith_data.ML	Thu Mar 03 09:22:35 2005 +0100
    69.2 +++ b/src/HOL/arith_data.ML	Thu Mar 03 12:43:01 2005 +0100
    69.3 @@ -25,7 +25,7 @@
    69.4  
    69.5  (*normal form of sums: Suc (... (Suc (a + (b + ...))))*)
    69.6  fun mk_norm_sum ts =
    69.7 -  let val (ones, sums) = partition (equal one) ts in
    69.8 +  let val (ones, sums) = List.partition (equal one) ts in
    69.9      funpow (length ones) HOLogic.mk_Suc (mk_sum sums)
   69.10    end;
   69.11  
    70.1 --- a/src/HOL/cladata.ML	Thu Mar 03 09:22:35 2005 +0100
    70.2 +++ b/src/HOL/cladata.ML	Thu Mar 03 12:43:01 2005 +0100
    70.3 @@ -33,7 +33,7 @@
    70.4  (*prevent substitution on bool*)
    70.5  fun hyp_subst_tac' i thm = if i <= Thm.nprems_of thm andalso
    70.6    Term.exists_Const (fn ("op =", Type (_, [T, _])) => T <> Type ("bool", []) | _ => false)
    70.7 -    (Library.nth_elem (i - 1, Thm.prems_of thm)) then hyp_subst_tac i thm else no_tac thm;
    70.8 +    (List.nth (Thm.prems_of thm, i - 1)) then hyp_subst_tac i thm else no_tac thm;
    70.9  
   70.10  
   70.11  
    71.1 --- a/src/HOL/eqrule_HOL_data.ML	Thu Mar 03 09:22:35 2005 +0100
    71.2 +++ b/src/HOL/eqrule_HOL_data.ML	Thu Mar 03 12:43:01 2005 +0100
    71.3 @@ -45,14 +45,14 @@
    71.4               (case Term.head_of p of
    71.5                  Const(a,_) =>
    71.6                    (case Library.assoc(pairs,a) of
    71.7 -                     SOME(rls) => flat (map atoms ([th] RL rls))
    71.8 +                     SOME(rls) => List.concat (map atoms ([th] RL rls))
    71.9                     | NONE => [th])
   71.10                | _ => [th])
   71.11           | _ => [th])
   71.12    in atoms end;
   71.13  
   71.14  val prep_meta_eq = 
   71.15 -    (mapfilter  
   71.16 +    (List.mapPartial  
   71.17         mk_eq
   71.18         o (mk_atomize tranformation_pairs)
   71.19         o Drule.gen_all 
    72.1 --- a/src/HOL/ex/svc_funcs.ML	Thu Mar 03 09:22:35 2005 +0100
    72.2 +++ b/src/HOL/ex/svc_funcs.ML	Thu Mar 03 12:43:01 2005 +0100
    72.3 @@ -44,11 +44,11 @@
    72.4  
    72.5   fun toString t =
    72.6       let fun ue (Buildin(s, l)) = 
    72.7 -	     "(" ^ s ^ (foldl (fn (a, b) => a ^ " " ^ (ue b)) ("", l)) ^ ") "
    72.8 +	     "(" ^ s ^ (Library.foldl (fn (a, b) => a ^ " " ^ (ue b)) ("", l)) ^ ") "
    72.9  	   | ue (Interp(s, l)) = 
   72.10 -	     "{" ^ s ^ (foldl (fn (a, b) => a ^ " " ^ (ue b)) ("", l)) ^ "} "
   72.11 +	     "{" ^ s ^ (Library.foldl (fn (a, b) => a ^ " " ^ (ue b)) ("", l)) ^ "} "
   72.12  	   | ue (UnInterp(s, l)) = 
   72.13 -	     "(" ^ s ^ (foldl (fn (a, b) => a ^ " " ^ (ue b)) ("", l)) ^ ") "
   72.14 +	     "(" ^ s ^ (Library.foldl (fn (a, b) => a ^ " " ^ (ue b)) ("", l)) ^ ") "
   72.15  	   | ue (FalseExpr) = "FALSE "
   72.16  	   | ue (TrueExpr)  = "TRUE "
   72.17  	   | ue (Int i)     = (signedInt i) ^ " "
   72.18 @@ -243,7 +243,7 @@
   72.19  
   72.20        val body_e = mt pos body  (*evaluate now to assign into !nat_vars*)
   72.21    in 
   72.22 -     foldr add_nat_var (!nat_vars, body_e) 
   72.23 +     Library.foldr add_nat_var (!nat_vars, body_e) 
   72.24    end;
   72.25  
   72.26  
    73.1 --- a/src/HOL/hologic.ML	Thu Mar 03 09:22:35 2005 +0100
    73.2 +++ b/src/HOL/hologic.ML	Thu Mar 03 12:43:01 2005 +0100
    73.3 @@ -148,7 +148,7 @@
    73.4  
    73.5  fun all_const T = Const ("All", [T --> boolT] ---> boolT);
    73.6  fun mk_all (x, T, P) = all_const T $ absfree (x, T, P);
    73.7 -val list_all = foldr (fn ((x, T), P) => all_const T $ Abs (x, T, P));
    73.8 +val list_all = Library.foldr (fn ((x, T), P) => all_const T $ Abs (x, T, P));
    73.9  
   73.10  fun exists_const T = Const ("Ex", [T --> boolT] ---> boolT);
   73.11  fun mk_exists (x, T, P) = exists_const T $ absfree (x, T, P);
   73.12 @@ -237,7 +237,7 @@
   73.13  (*Makes a nested tuple from a list, following the product type structure*)
   73.14  fun mk_tuple (Type ("*", [T1, T2])) tms = 
   73.15          mk_prod (mk_tuple T1 tms, 
   73.16 -                 mk_tuple T2 (drop (length (prodT_factors T1), tms)))
   73.17 +                 mk_tuple T2 (Library.drop (length (prodT_factors T1), tms)))
   73.18    | mk_tuple T (t::_) = t;
   73.19  
   73.20  
   73.21 @@ -246,13 +246,13 @@
   73.22  
   73.23  local  (*currently unused*)
   73.24  
   73.25 -fun mk_tupleT Ts = foldr mk_prodT (Ts, unitT);
   73.26 +fun mk_tupleT Ts = Library.foldr mk_prodT (Ts, unitT);
   73.27  
   73.28  fun dest_tupleT (Type ("Product_Type.unit", [])) = []
   73.29    | dest_tupleT (Type ("*", [T, U])) = T :: dest_tupleT U
   73.30    | dest_tupleT T = raise TYPE ("dest_tupleT", [T], []);
   73.31  
   73.32 -fun mk_tuple ts = foldr mk_prod (ts, unit);
   73.33 +fun mk_tuple ts = Library.foldr mk_prod (ts, unit);
   73.34  
   73.35  fun dest_tuple (Const ("Product_Type.Unity", _)) = []
   73.36    | dest_tuple (Const ("Pair", _) $ t $ u) = t :: dest_tuple u
    74.1 --- a/src/HOL/simpdata.ML	Thu Mar 03 09:22:35 2005 +0100
    74.2 +++ b/src/HOL/simpdata.ML	Thu Mar 03 12:43:01 2005 +0100
    74.3 @@ -253,14 +253,14 @@
    74.4               (case head_of p of
    74.5                  Const(a,_) =>
    74.6                    (case assoc(pairs,a) of
    74.7 -                     SOME(rls) => flat (map atoms ([th] RL rls))
    74.8 +                     SOME(rls) => List.concat (map atoms ([th] RL rls))
    74.9                     | NONE => [th])
   74.10                | _ => [th])
   74.11           | _ => [th])
   74.12    in atoms end;
   74.13  
   74.14  fun mksimps pairs =
   74.15 -  (mapfilter (try mk_eq) o mk_atomize pairs o gen_all);
   74.16 +  (List.mapPartial (try mk_eq) o mk_atomize pairs o gen_all);
   74.17  
   74.18  fun unsafe_solver_tac prems =
   74.19    FIRST'[resolve_tac(reflexive_thm::TrueI::refl::prems), atac, etac FalseE];
    75.1 --- a/src/HOL/thy_syntax.ML	Thu Mar 03 09:22:35 2005 +0100
    75.2 +++ b/src/HOL/thy_syntax.ML	Thu Mar 03 12:43:01 2005 +0100
    75.3 @@ -14,7 +14,7 @@
    75.4  
    75.5  fun mk_typedef_decl (((((opt_name, vs), t), mx), rhs), wt) =
    75.6    let
    75.7 -    val name' = if_none opt_name t;
    75.8 +    val name' = getOpt (opt_name,t);
    75.9      val name = unenclose name';
   75.10    in
   75.11      (cat_lines [name', mk_triple (t, mk_list vs, mx), rhs, wt],
   75.12 @@ -101,11 +101,11 @@
   75.13            fun mk_dt_struct (s, (id, i)) =
   75.14              s ^ "structure " ^ id ^ " =\n\
   75.15              \struct\n\
   75.16 -            \  val distinct = nth_elem (" ^ i ^ ", distinct);\n\
   75.17 -            \  val inject = nth_elem (" ^ i ^ ", inject);\n\
   75.18 -            \  val exhaust = nth_elem (" ^ i ^ ", exhaustion);\n\
   75.19 -            \  val cases = nth_elem (" ^ i ^ ", case_thms);\n\
   75.20 -            \  val (split, split_asm) = nth_elem (" ^ i ^ ", split_thms);\n" ^
   75.21 +            \  val distinct = List.nth (distinct, " ^ i ^ ");\n\
   75.22 +            \  val inject = List.nth (inject, " ^ i ^ ");\n\
   75.23 +            \  val exhaust = List.nth (exhaustion, " ^ i ^ ");\n\
   75.24 +            \  val cases = List.nth (case_thms, " ^ i ^ ");\n\
   75.25 +            \  val (split, split_asm) = List.nth (split_thms, " ^ i ^ ");\n" ^
   75.26                (if length names = 1 then
   75.27                   "  val induct = induction;\n\
   75.28                   \  val recs = rec_thms;\n\
   75.29 @@ -114,7 +114,7 @@
   75.30                 else "") ^
   75.31              "end;\n";
   75.32  
   75.33 -          val structs = foldl mk_dt_struct
   75.34 +          val structs = Library.foldl mk_dt_struct
   75.35              ("", (names ~~ (map string_of_int (0 upto length names - 1))));
   75.36  
   75.37          in
   75.38 @@ -131,7 +131,7 @@
   75.39    fun mk_dt_string dts =
   75.40      let
   75.41        val names = map (fn ((((alt_name, _), name), _), _) =>
   75.42 -        unenclose (if_none alt_name name)) dts;
   75.43 +        unenclose (getOpt (alt_name,name))) dts;
   75.44  
   75.45        val add_datatype_args = brackets (commas (map Library.quote names)) ^ " " ^
   75.46          brackets (commas (map (fn ((((_, vs), name), mx), cs) =>
    76.1 --- a/src/HOLCF/IOA/Modelcheck/MuIOAOracle.ML	Thu Mar 03 09:22:35 2005 +0100
    76.2 +++ b/src/HOLCF/IOA/Modelcheck/MuIOAOracle.ML	Thu Mar 03 12:43:01 2005 +0100
    76.3 @@ -2,7 +2,7 @@
    76.4  (* call_sim_tac invokes oracle "Sim" *)
    76.5  fun call_sim_tac thm_list i state = 
    76.6  let val sign = #sign (rep_thm state);
    76.7 -        val (subgoal::_) = drop(i-1,prems_of state);
    76.8 +        val (subgoal::_) = Library.drop(i-1,prems_of state);
    76.9          val OraAss = invoke_oracle MuIOAOracle.thy "Sim" (sign,SimOracleExn (subgoal,thm_list));
   76.10  in
   76.11  (cut_facts_tac [OraAss] i) state
   76.12 @@ -13,7 +13,7 @@
   76.13  fun is_sim_tac thm_list i state =
   76.14  let val sign = #sign (rep_thm state);
   76.15  in
   76.16 -case drop(i-1,prems_of state) of
   76.17 +case Library.drop(i-1,prems_of state) of
   76.18          [] => PureGeneral.Seq.empty |
   76.19          subgoal::_ => EVERY[REPEAT(etac thin_rl i),
   76.20                          simp_tac (simpset() addsimps [ioa_implements_def]) i,
    77.1 --- a/src/HOLCF/IOA/meta_theory/Sequence.ML	Thu Mar 03 09:22:35 2005 +0100
    77.2 +++ b/src/HOLCF/IOA/meta_theory/Sequence.ML	Thu Mar 03 12:43:01 2005 +0100
    77.3 @@ -1012,7 +1012,7 @@
    77.4  fun all_frees_tac x i thm =
    77.5    let
    77.6      val tsig = Sign.tsig_of (Thm.sign_of_thm thm);
    77.7 -    val frees = add_frees tsig (nth_elem (i - 1, prems_of thm), [x]);
    77.8 +    val frees = add_frees tsig (List.nth (prems_of thm, i - 1), [x]);
    77.9      val frees' = sort (op >) (frees \ x) @ [x];
   77.10    in
   77.11      foldl (qnt_tac i) (all_tac, frees') thm
    78.1 --- a/src/HOLCF/adm.ML	Thu Mar 03 09:22:35 2005 +0100
    78.2 +++ b/src/HOLCF/adm.ML	Thu Mar 03 12:43:01 2005 +0100
    78.3 @@ -40,7 +40,7 @@
    78.4        if i = lev then [[(Bound 0, path)]]
    78.5        else []
    78.6    | find_subterms (t as (Abs (_, _, t2))) lev path =
    78.7 -      if filter (fn x => x<=lev)
    78.8 +      if List.filter (fn x => x<=lev)
    78.9             (add_loose_bnos (t, 0, [])) = [lev] then
   78.10          [(incr_bv (~lev, 0, t), path)]::
   78.11          (find_subterms t2 (lev+1) (0::path))
   78.12 @@ -52,7 +52,7 @@
   78.13              | combine (x::xs) ys =
   78.14                  (map (fn z => x @ z) ys) @ (combine xs ys)
   78.15        in
   78.16 -        (if filter (fn x => x<=lev)
   78.17 +        (if List.filter (fn x => x<=lev)
   78.18                (add_loose_bnos (t, 0, [])) = [lev] then
   78.19             [[(incr_bv (~lev, 0, t), path)]]
   78.20           else []) @
   78.21 @@ -116,7 +116,7 @@
   78.22        val tsig = Sign.tsig_of sign;
   78.23        val parTs = map snd (rev params);
   78.24        val rule = lift_rule (state, i) adm_subst;
   78.25 -      val types = the o (fst (types_sorts rule));
   78.26 +      val types = valOf o (fst (types_sorts rule));
   78.27        val tT = types ("t", j);
   78.28        val PT = types ("P", j);
   78.29        fun mk_abs [] t = t
   78.30 @@ -135,7 +135,7 @@
   78.31  
   78.32  (*** extract subgoal i from proof state ***)
   78.33  
   78.34 -fun nth_subgoal i thm = nth_elem (i-1, prems_of thm);
   78.35 +fun nth_subgoal i thm = List.nth (prems_of thm, i-1);
   78.36  
   78.37  
   78.38  (*** the admissibility tactic ***)
   78.39 @@ -155,9 +155,9 @@
   78.40            val prems = Logic.strip_assums_hyp goali;
   78.41            val params = Logic.strip_params goali;
   78.42            val ts = find_subterms t 0 [];
   78.43 -          val ts' = filter eq_terms ts;
   78.44 -          val ts'' = filter (is_chfin sign T params) ts';
   78.45 -          val thms = foldl (prove_cont tac sign s T prems params) ([], ts'');
   78.46 +          val ts' = List.filter eq_terms ts;
   78.47 +          val ts'' = List.filter (is_chfin sign T params) ts';
   78.48 +          val thms = Library.foldl (prove_cont tac sign s T prems params) ([], ts'');
   78.49          in
   78.50            (case thms of
   78.51              ((ts as ((t', _)::_), cont_thm)::_) =>
    79.1 --- a/src/HOLCF/cont_consts.ML	Thu Mar 03 09:22:35 2005 +0100
    79.2 +++ b/src/HOLCF/cont_consts.ML	Thu Mar 03 12:43:01 2005 +0100
    79.3 @@ -43,7 +43,7 @@
    79.4    val vnames = argnames (ord "A") n;
    79.5    val extra_parse_rule = Syntax.ParseRule (Constant name2, Constant name1);
    79.6    in [Syntax.ParsePrintRule (Syntax.mk_appl (Constant name2) (map Variable vnames),
    79.7 -                          foldl (fn (t,arg) => (Syntax.mk_appl (Constant "Rep_CFun")
    79.8 +                          Library.foldl (fn (t,arg) => (Syntax.mk_appl (Constant "Rep_CFun")
    79.9                                                  [t,Variable arg]))
   79.10                            (Constant name1,vnames))]
   79.11       @(case mx of InfixName _ => [extra_parse_rule]
   79.12 @@ -94,7 +94,7 @@
   79.13      |> Theory.add_consts_i normal_decls
   79.14      |> Theory.add_consts_i (map first transformed_decls)
   79.15      |> Theory.add_syntax_i (map second transformed_decls)
   79.16 -    |> Theory.add_trrules_i (flat (map third transformed_decls))
   79.17 +    |> Theory.add_trrules_i (List.concat (map third transformed_decls))
   79.18    end;
   79.19  
   79.20  val add_consts = gen_add_consts Thm.read_ctyp;
    80.1 --- a/src/HOLCF/domain/axioms.ML	Thu Mar 03 09:22:35 2005 +0100
    80.2 +++ b/src/HOLCF/domain/axioms.ML	Thu Mar 03 12:43:01 2005 +0100
    80.3 @@ -31,7 +31,7 @@
    80.4   val rep_iso_ax = ("rep_iso" ,mk_trp(dc_abs`(dc_rep`%x_name')=== %:x_name'));
    80.5  
    80.6    val when_def = ("when_def",%%:(dname^"_when") == 
    80.7 -     foldr (uncurry /\ ) (when_funs cons, /\x_name'((when_body cons (fn (x,y) =>
    80.8 +     Library.foldr (uncurry /\ ) (when_funs cons, /\x_name'((when_body cons (fn (x,y) =>
    80.9  				Bound(1+length cons+x-y)))`(dc_rep`Bound 0))));
   80.10  
   80.11    fun con_def outer recu m n (_,args) = let
   80.12 @@ -43,10 +43,10 @@
   80.13       fun inj y 1 _ = y
   80.14       |   inj y _ 0 = %%:"sinl"`y
   80.15       |   inj y i j = %%:"sinr"`(inj y (i-1) (j-1));
   80.16 -  in foldr /\# (args, outer (inj (parms args) m n)) end;
   80.17 +  in Library.foldr /\# (args, outer (inj (parms args) m n)) end;
   80.18  
   80.19    val copy_def = ("copy_def", %%:(dname^"_copy") == /\"f" (dc_abs oo 
   80.20 -	foldl (op `) (%%:(dname^"_when") , 
   80.21 +	Library.foldl (op `) (%%:(dname^"_when") , 
   80.22  	              mapn (con_def Id true (length cons)) 0 cons)));
   80.23  
   80.24  (* -- definitions concerning the constructors, discriminators and selectors - *)
   80.25 @@ -57,7 +57,7 @@
   80.26    val dis_defs = let
   80.27  	fun ddef (con,_) = (dis_name con ^"_def",%%:(dis_name con) == 
   80.28  		 mk_cRep_CFun(%%:(dname^"_when"),map 
   80.29 -			(fn (con',args) => (foldr /\#
   80.30 +			(fn (con',args) => (Library.foldr /\#
   80.31  			   (args,if con'=con then %%:"TT" else %%:"FF"))) cons))
   80.32  	in map ddef cons end;
   80.33  
   80.34 @@ -65,8 +65,8 @@
   80.35  	fun sdef con n arg = (sel_of arg^"_def",%%:(sel_of arg) == 
   80.36  		 mk_cRep_CFun(%%:(dname^"_when"),map 
   80.37  			(fn (con',args) => if con'<>con then %%:"UU" else
   80.38 -			 foldr /\# (args,Bound (length args - n))) cons));
   80.39 -	in flat(map (fn (con,args) => mapn (sdef con) 1 args) cons) end;
   80.40 +			 Library.foldr /\# (args,Bound (length args - n))) cons));
   80.41 +	in List.concat(map (fn (con,args) => mapn (sdef con) 1 args) cons) end;
   80.42  
   80.43  
   80.44  (* ----- axiom and definitions concerning induction ------------------------- *)
   80.45 @@ -100,7 +100,7 @@
   80.46      let
   80.47        fun one_con (con,args) = let
   80.48  	val nonrec_args = filter_out is_rec args;
   80.49 -	val    rec_args = filter     is_rec args;
   80.50 +	val    rec_args = List.filter     is_rec args;
   80.51  	val    recs_cnt = length rec_args;
   80.52  	val allargs     = nonrec_args @ rec_args
   80.53  				      @ map (upd_vname (fn s=> s^"'")) rec_args;
   80.54 @@ -114,10 +114,10 @@
   80.55  					 (allargs~~((allargs_cnt-1) downto 0)));
   80.56  	fun rel_app i ra = proj (Bound(allargs_cnt+2)) eqs (rec_of ra) $ 
   80.57  			   Bound (2*recs_cnt-i) $ Bound (recs_cnt-i);
   80.58 -	val capps = foldr mk_conj (mapn rel_app 1 rec_args, mk_conj(
   80.59 +	val capps = Library.foldr mk_conj (mapn rel_app 1 rec_args, mk_conj(
   80.60  	   Bound(allargs_cnt+1)===mk_cRep_CFun(%%:con,map (bound_arg allvns) vns1),
   80.61  	   Bound(allargs_cnt+0)===mk_cRep_CFun(%%:con,map (bound_arg allvns) vns2)));
   80.62 -        in foldr mk_ex (allvns, foldr mk_conj 
   80.63 +        in Library.foldr mk_ex (allvns, Library.foldr mk_conj 
   80.64  			      (map (defined o Bound) nonlazy_idxs,capps)) end;
   80.65        fun one_comp n (_,cons) =mk_all(x_name(n+1),mk_all(x_name(n+1)^"'",mk_imp(
   80.66  	 		proj (Bound 2) eqs n $ Bound 1 $ Bound 0,
   80.67 @@ -129,7 +129,7 @@
   80.68  	|> add_axioms_i (infer_types thy' dfs)(*add_defs_i*)
   80.69  	|> add_axioms_i (infer_types thy' axs)
   80.70  	|> Theory.parent_path;
   80.71 -  val thy = foldl add_one (thy', mapn (calc_axioms comp_dname eqs) 0 eqs);
   80.72 +  val thy = Library.foldl add_one (thy', mapn (calc_axioms comp_dname eqs) 0 eqs);
   80.73  in thy |> Theory.add_path comp_dnam  
   80.74         |> add_axioms_i (infer_types thy' 
   80.75  		(bisim_def::(if length eqs>1 then [copy_def] else [])))
    81.1 --- a/src/HOLCF/domain/extender.ML	Thu Mar 03 09:22:35 2005 +0100
    81.2 +++ b/src/HOLCF/domain/extender.ML	Thu Mar 03 12:43:01 2005 +0100
    81.3 @@ -44,11 +44,11 @@
    81.4      val defaultS = Sign.defaultS sg;
    81.5      val test_dupl_typs = (case duplicates (map fst dtnvs) of 
    81.6  	[] => false | dups => error ("Duplicate types: " ^ commas_quote dups));
    81.7 -    val test_dupl_cons = (case duplicates (map first (flat cons'')) of 
    81.8 +    val test_dupl_cons = (case duplicates (map first (List.concat cons'')) of 
    81.9  	[] => false | dups => error ("Duplicate constructors: " 
   81.10  							 ^ commas_quote dups));
   81.11      val test_dupl_sels = (case duplicates 
   81.12 -			       (map second (flat (map third (flat cons'')))) of
   81.13 +			       (map second (List.concat (map third (List.concat cons'')))) of
   81.14          [] => false | dups => error("Duplicate selectors: "^commas_quote dups));
   81.15      val test_dupl_tvars = exists(fn s=>case duplicates(map(fst o rep_TFree)s)of
   81.16  	[] => false | dups => error("Duplicate type arguments: " 
   81.17 @@ -110,7 +110,7 @@
   81.18      val eqs' = check_and_sort_domain (dtnvs,cons'') sg'';
   81.19      val thy' = thy'' |> Domain_Syntax.add_syntax (comp_dnam,eqs');
   81.20      val dts  = map (Type o fst) eqs';
   81.21 -    fun strip ss = drop (find_index_eq "'" ss +1, ss);
   81.22 +    fun strip ss = Library.drop (find_index_eq "'" ss +1, ss);
   81.23      fun typid (Type  (id,_)) =
   81.24            let val c = hd (Symbol.explode (Sign.base_name id))
   81.25            in if Symbol.is_letter c then c else "t" end
   81.26 @@ -131,7 +131,7 @@
   81.27  in
   81.28    theorems_thy
   81.29    |> Theory.add_path (Sign.base_name comp_dnam)
   81.30 -  |> (#1 o (PureThy.add_thmss [(("rews", flat rewss @ take_rews), [])]))
   81.31 +  |> (#1 o (PureThy.add_thmss [(("rews", List.concat rewss @ take_rews), [])]))
   81.32    |> Theory.parent_path
   81.33  end;
   81.34  
    82.1 --- a/src/HOLCF/domain/interface.ML	Thu Mar 03 09:22:35 2005 +0100
    82.2 +++ b/src/HOLCF/domain/interface.ML	Thu Mar 03 12:43:01 2005 +0100
    82.3 @@ -33,7 +33,7 @@
    82.4        cat_lines (map (gen_vals dname) axioms1)^"\n"^
    82.5        gen_vall "con_defs"       (map (fn (con,_,_) => 
    82.6  		get dname (strip_esc con^"_def")) cons')^"\n"^
    82.7 -      gen_vall "sel_defs" (flat (map (fn (_,_,args) => map (fn (_,sel,_) => 
    82.8 +      gen_vall "sel_defs" (List.concat (map (fn (_,_,args) => map (fn (_,sel,_) => 
    82.9  		get dname (sel^"_def")) args)    cons'))^"\n"^
   82.10        gen_vall "dis_defs"       (map (fn (con,_,_) => 
   82.11  		get dname (dis_name_ con^"_def")) cons')^"\n"^
    83.1 --- a/src/HOLCF/domain/library.ML	Thu Mar 03 09:22:35 2005 +0100
    83.2 +++ b/src/HOLCF/domain/library.ML	Thu Mar 03 12:43:01 2005 +0100
    83.3 @@ -13,12 +13,12 @@
    83.4  fun mapn f n []      = []
    83.5  |   mapn f n (x::xs) = (f n x) :: mapn f (n+1) xs;
    83.6  
    83.7 -fun foldr'' f (l,f2) = let fun itr []  = raise LIST "foldr''"
    83.8 +fun foldr'' f (l,f2) = let fun itr []  = raise Fail "foldr''"
    83.9  			     | itr [a] = f2 a
   83.10  			     | itr (a::l) = f(a, itr l)
   83.11  in  itr l  end;
   83.12  fun foldr' f l = foldr'' f (l,Id);
   83.13 -fun map_cumulr f start xs = foldr (fn (x,(ys,res))=>case f(x,res) of (y,res2) =>
   83.14 +fun map_cumulr f start xs = Library.foldr (fn (x,(ys,res))=>case f(x,res) of (y,res2) =>
   83.15  						  (y::ys,res2)) (xs,([],start));
   83.16  
   83.17  
   83.18 @@ -98,7 +98,7 @@
   83.19  fun is_rec         arg = rec_of arg >=0;
   83.20  fun is_nonlazy_rec arg = is_rec arg andalso not (is_lazy arg);
   83.21  fun nonlazy     args   = map vname (filter_out is_lazy    args);
   83.22 -fun nonlazy_rec args   = map vname (filter is_nonlazy_rec args);
   83.23 +fun nonlazy_rec args   = map vname (List.filter is_nonlazy_rec args);
   83.24  
   83.25  (* ----- support for type and mixfix expressions ----- *)
   83.26  
   83.27 @@ -123,7 +123,7 @@
   83.28  	 	    |   sg _       = Imposs "library:sg";
   83.29  		    fun sf [] = %%:"_emptysort"
   83.30  		    |   sf s  = %%:"_sort" $ sg s
   83.31 -		    fun tf (Type (s,args)) = foldl (op $) (%:s,map tf args)
   83.32 +		    fun tf (Type (s,args)) = Library.foldl (op $) (%:s,map tf args)
   83.33  		    |   tf (TFree(s,sort)) = %%:"_ofsort" $ %:s $ sf sort
   83.34  		    |   tf _               = Imposs "library:tf";
   83.35  in
   83.36 @@ -146,7 +146,7 @@
   83.37  infix 9 `  ; fun f`  x = %%:"Rep_CFun" $ f $ x;
   83.38  infix 9 `% ; fun f`% s = f` %: s;
   83.39  infix 9 `%%; fun f`%%s = f` %%:s;
   83.40 -fun mk_cRep_CFun (F,As) = foldl (op `) (F,As);
   83.41 +fun mk_cRep_CFun (F,As) = Library.foldl (op `) (F,As);
   83.42  fun con_app2 con f args = mk_cRep_CFun(%%:con,map f args);
   83.43  fun con_app con = con_app2 con %#;
   83.44  fun if_rec  arg f y   = if is_rec arg then f (rec_of arg) else y;
   83.45 @@ -162,7 +162,7 @@
   83.46  	(fn S => fn t => Const("cfst",mk_prodT(dummyT,t)->>dummyT)`S) 
   83.47  	(fn S => fn t => Const("csnd",mk_prodT(t,dummyT)->>dummyT)`S) 
   83.48  		       T (map ((fn tp => tp ->> tp) o Type o fix_tp o fst) eqs);
   83.49 -fun lift tfn = foldr (fn (x,t)=> (mk_trp(tfn x) ===> t));
   83.50 +fun lift tfn = Library.foldr (fn (x,t)=> (mk_trp(tfn x) ===> t));
   83.51  
   83.52  fun /\ v T = %%:"Abs_CFun" $ mk_lam(v,T);
   83.53  fun /\# (arg,T) = /\ (vname arg) T;
    84.1 --- a/src/HOLCF/domain/syntax.ML	Thu Mar 03 09:22:35 2005 +0100
    84.2 +++ b/src/HOLCF/domain/syntax.ML	Thu Mar 03 12:43:01 2005 +0100
    84.3 @@ -22,14 +22,14 @@
    84.4  			    else foldr' mk_sprodT (map opt_lazy args);
    84.5    fun freetvar s = let val tvar = mk_TFree s in
    84.6  		   if tvar mem typevars then freetvar ("t"^s) else tvar end;
    84.7 -  fun when_type (_   ,_,args) = foldr (op ->>) (map third args,freetvar "t");
    84.8 +  fun when_type (_   ,_,args) = Library.foldr (op ->>) (map third args,freetvar "t");
    84.9  in
   84.10    val dtype  = Type(dname,typevars);
   84.11    val dtype2 = foldr' mk_ssumT (map prod cons');
   84.12    val dnam = Sign.base_name dname;
   84.13    val const_rep  = (dnam^"_rep" ,              dtype  ->> dtype2, NoSyn);
   84.14    val const_abs  = (dnam^"_abs" ,              dtype2 ->> dtype , NoSyn);
   84.15 -  val const_when = (dnam^"_when",foldr (op ->>) ((map when_type cons'),
   84.16 +  val const_when = (dnam^"_when",Library.foldr (op ->>) ((map when_type cons'),
   84.17  					        dtype ->> freetvar "t"), NoSyn);
   84.18    val const_copy = (dnam^"_copy", dtypeprod ->> dtype  ->> dtype , NoSyn);
   84.19  end;
   84.20 @@ -42,7 +42,7 @@
   84.21  							 else      c::esc cs
   84.22  	|   esc []      = []
   84.23  	in implode o esc o Symbol.explode end;
   84.24 -  fun con (name,s,args) = (name,foldr (op ->>) (map third args,dtype),s);
   84.25 +  fun con (name,s,args) = (name,Library.foldr (op ->>) (map third args,dtype),s);
   84.26    fun dis (con ,s,_   ) = (dis_name_ con, dtype->>trT,
   84.27  			   Mixfix(escape ("is_" ^ con), [], Syntax.max_pri));
   84.28  			(* stricly speaking, these constants have one argument,
   84.29 @@ -52,7 +52,7 @@
   84.30  in
   84.31    val consts_con = map con cons';
   84.32    val consts_dis = map dis cons';
   84.33 -  val consts_sel = flat(map sel cons');
   84.34 +  val consts_sel = List.concat(map sel cons');
   84.35  end;
   84.36  
   84.37  (* ----- constants concerning induction ------------------------------------- *)
   84.38 @@ -70,7 +70,7 @@
   84.39  					 (string_of_int m));
   84.40  	fun app s (l,r)   = mk_appl (Constant s) [l,r];
   84.41  	fun case1 n (con,mx,args) = mk_appl (Constant "_case1")
   84.42 -		 [foldl (app "Rep_CFun") (c_ast con mx, (mapn (argvar n) 1 args)),
   84.43 +		 [Library.foldl (app "Rep_CFun") (c_ast con mx, (mapn (argvar n) 1 args)),
   84.44  		  expvar n];
   84.45  	fun arg1 n (con,_,args) = if args = [] then expvar n 
   84.46  				  else mk_appl (Constant "LAM ") 
   84.47 @@ -80,7 +80,7 @@
   84.48        (mk_appl (Constant "_case_syntax") [Variable "x", foldr'
   84.49  				(fn (c,cs) => mk_appl (Constant"_case2") [c,cs])
   84.50  				 (mapn case1 1 cons')],
   84.51 -       mk_appl (Constant "Rep_CFun") [foldl 
   84.52 +       mk_appl (Constant "Rep_CFun") [Library.foldl 
   84.53  				(fn (w,a ) => mk_appl (Constant"Rep_CFun" ) [w,a ])
   84.54  				 (Constant (dnam^"_when"),mapn arg1 1 cons'),
   84.55  				 Variable "x"])
   84.56 @@ -107,10 +107,10 @@
   84.57    val const_copy   = (comp_dnam^"_copy"  ,funprod ->> funprod, NoSyn);
   84.58    val const_bisim  = (comp_dnam^"_bisim" ,relprod --> boolT  , NoSyn);
   84.59    val ctt           = map (calc_syntax funprod) eqs';
   84.60 -in thy'' |> ContConsts.add_consts_i (flat (map fst ctt) @ 
   84.61 +in thy'' |> ContConsts.add_consts_i (List.concat (map fst ctt) @ 
   84.62  				    (if length eqs'>1 then [const_copy] else[])@
   84.63  				    [const_bisim])
   84.64 -	 |> Theory.add_trrules_i (flat(map snd ctt))
   84.65 +	 |> Theory.add_trrules_i (List.concat(map snd ctt))
   84.66  end; (* let *)
   84.67  
   84.68  end; (* local *)
    85.1 --- a/src/HOLCF/domain/theorems.ML	Thu Mar 03 09:22:35 2005 +0100
    85.2 +++ b/src/HOLCF/domain/theorems.ML	Thu Mar 03 12:43:01 2005 +0100
    85.3 @@ -71,7 +71,7 @@
    85.4  val ax_when_def   = ga "when_def" dname;
    85.5  val axs_con_def   = map (fn (con,_) => ga (extern_name con^"_def") dname) cons;
    85.6  val axs_dis_def   = map (fn (con,_) => ga (   dis_name con^"_def") dname) cons;
    85.7 -val axs_sel_def   = flat(map (fn (_,args) => 
    85.8 +val axs_sel_def   = List.concat(map (fn (_,args) => 
    85.9                      map (fn     arg => ga (sel_of arg     ^"_def") dname) args)
   85.10  									  cons);
   85.11  val ax_copy_def   = ga "copy_def" dname;
   85.12 @@ -101,7 +101,7 @@
   85.13                              etac (ax_rep_iso RS subst) 1];
   85.14  fun exh foldr1 cn quant foldr2 var = let
   85.15    fun one_con (con,args) = let val vns = map vname args in
   85.16 -    foldr quant (vns, foldr2 ((%:x_name === con_app2 con (var vns) vns)::
   85.17 +    Library.foldr quant (vns, foldr2 ((%:x_name === con_app2 con (var vns) vns)::
   85.18                                map (defined o (var vns)) (nonlazy args))) end
   85.19    in foldr1 ((cn(%:x_name===UU))::map one_con cons) end;
   85.20  in
   85.21 @@ -130,9 +130,9 @@
   85.22                                  prod_tac args THEN sum_rest_tac p) THEN
   85.23                                  sum_tac cons' prems
   85.24              |   sum_tac _ _ = Imposs "theorems:sum_tac";
   85.25 -          in pg'' thy [] (exh (fn l => foldr (op ===>) (l,mk_trp(%:"P")))
   85.26 +          in pg'' thy [] (exh (fn l => Library.foldr (op ===>) (l,mk_trp(%:"P")))
   85.27                                (fn T => T ==> %:"P") mk_All
   85.28 -                              (fn l => foldr (op ===>) (map mk_trp l,
   85.29 +                              (fn l => Library.foldr (op ===>) (map mk_trp l,
   85.30                                                              mk_trp(%:"P")))
   85.31                                bound_arg)
   85.32                               (fn prems => [
   85.33 @@ -153,9 +153,9 @@
   85.34  end;
   85.35  
   85.36  local 
   85.37 -  fun bind_fun t = foldr mk_All (when_funs cons,t);
   85.38 +  fun bind_fun t = Library.foldr mk_All (when_funs cons,t);
   85.39    fun bound_fun i _ = Bound (length cons - i);
   85.40 -  val when_app  = foldl (op `) (%%:(dname^"_when"), mapn bound_fun 1 cons);
   85.41 +  val when_app  = Library.foldl (op `) (%%:(dname^"_when"), mapn bound_fun 1 cons);
   85.42    val when_appl = pg [ax_when_def] (bind_fun(mk_trp(when_app`%x_name ===
   85.43               when_body cons (fn (m,n)=> bound_fun (n-m) 0)`(dc_rep`%x_name))))[
   85.44                                  simp_tac HOLCF_ss 1];
   85.45 @@ -182,7 +182,7 @@
   85.46                          (mk_trp((%%:(dis_name c))`(con_app con args) ===
   85.47                                %%:(if con=c then "TT" else "FF"))))) [
   85.48                                  asm_simp_tac (HOLCF_ss addsimps when_rews) 1];
   85.49 -        in flat(map (fn (c,_) => map (one_dis c) cons) cons) end;
   85.50 +        in List.concat(map (fn (c,_) => map (one_dis c) cons) cons) end;
   85.51    val dis_defins = map (fn (con,args) => pg [] (defined(%:x_name) ==> 
   85.52                        defined(%%:(dis_name con)`%x_name)) [
   85.53                                  rtac casedist 1,
   85.54 @@ -191,7 +191,7 @@
   85.55                                          (HOLCF_ss addsimps dis_apps) 1))]) cons;
   85.56  in dis_stricts @ dis_defins @ dis_apps end;
   85.57  
   85.58 -val con_stricts = flat(map (fn (con,args) => map (fn vn =>
   85.59 +val con_stricts = List.concat(map (fn (con,args) => map (fn vn =>
   85.60                          pg (axs_con_def) 
   85.61                             (mk_trp(con_app2 con (fn arg => if vname arg = vn 
   85.62                                          then UU else %# arg) args === UU))[
   85.63 @@ -207,22 +207,22 @@
   85.64  
   85.65  val sel_stricts = let fun one_sel sel = pg axs_sel_def (mk_trp(strict(%%:sel))) [
   85.66                                  simp_tac (HOLCF_ss addsimps when_rews) 1];
   85.67 -in flat(map (fn (_,args) =>map (fn arg => one_sel (sel_of arg)) args) cons) end;
   85.68 +in List.concat(map (fn (_,args) =>map (fn arg => one_sel (sel_of arg)) args) cons) end;
   85.69  val sel_apps = let fun one_sel c n sel = map (fn (con,args) => 
   85.70                  let val nlas = nonlazy args;
   85.71                      val vns  = map vname args;
   85.72                  in pg axs_sel_def (lift_defined %:
   85.73 -                   (filter (fn v => con=c andalso (v<>nth_elem(n,vns))) nlas,
   85.74 +                   (List.filter (fn v => con=c andalso (v<>List.nth(vns,n))) nlas,
   85.75                                  mk_trp((%%:sel)`(con_app con args) === 
   85.76 -                                (if con=c then %:(nth_elem(n,vns)) else UU))))
   85.77 +                                (if con=c then %:(List.nth(vns,n)) else UU))))
   85.78                              ( (if con=c then [] 
   85.79                         else map(case_UU_tac(when_rews@con_stricts)1) nlas)
   85.80 -                     @(if con=c andalso ((nth_elem(n,vns)) mem nlas)
   85.81 +                     @(if con=c andalso ((List.nth(vns,n)) mem nlas)
   85.82                                   then[case_UU_tac (when_rews @ con_stricts) 1 
   85.83 -                                                  (nth_elem(n,vns))] else [])
   85.84 +                                                  (List.nth(vns,n))] else [])
   85.85                       @ [asm_simp_tac(HOLCF_ss addsimps when_rews)1])end) cons;
   85.86 -in flat(map  (fn (c,args) => 
   85.87 -     flat(mapn (fn n => fn arg => one_sel c n (sel_of arg)) 0 args)) cons) end;
   85.88 +in List.concat(map  (fn (c,args) => 
   85.89 +     List.concat(mapn (fn n => fn arg => one_sel c n (sel_of arg)) 0 args)) cons) end;
   85.90  val sel_defins = if length cons=1 then map (fn arg => pg [](defined(%:x_name)==> 
   85.91                          defined(%%:(sel_of arg)`%x_name)) [
   85.92                                  rtac casedist 1,
   85.93 @@ -249,7 +249,7 @@
   85.94      fun distincts []      = []
   85.95      |   distincts (c::cs) = (map (distinct c) cs) :: distincts cs;
   85.96  in distincts cons end;
   85.97 -val dist_les = flat (flat distincts_le);
   85.98 +val dist_les = List.concat (List.concat distincts_le);
   85.99  val dist_eqs = let
  85.100      fun distinct (_,args1) ((_,args2),leqs) = let
  85.101          val (le1,le2) = (hd leqs, hd(tl leqs));
  85.102 @@ -273,10 +273,10 @@
  85.103                              mk_trp (foldr' mk_conj 
  85.104                                  (ListPair.map rel
  85.105  				 (map %# largs, map %# rargs)))))) end;
  85.106 -  val cons' = filter (fn (_,args) => args<>[]) cons;
  85.107 +  val cons' = List.filter (fn (_,args) => args<>[]) cons;
  85.108  in
  85.109  val inverts = map (fn (con,args) => 
  85.110 -                pgterm (op <<) con args (flat(map (fn arg => [
  85.111 +                pgterm (op <<) con args (List.concat(map (fn arg => [
  85.112                                  TRY(rtac conjI 1),
  85.113                                  dres_inst_tac [("fo",sel_of arg)] monofun_cfun_arg 1,
  85.114                                  asm_full_simp_tac (HOLCF_ss addsimps sel_apps) 1]
  85.115 @@ -302,7 +302,7 @@
  85.116                  (con_app2 con (app_rec_arg (cproj (%:"f") eqs)) args))))
  85.117                          (map (case_UU_tac (abs_strict::when_strict::con_stricts)
  85.118                                   1 o vname)
  85.119 -                         (filter (fn a => not (is_rec a orelse is_lazy a)) args)
  85.120 +                         (List.filter (fn a => not (is_rec a orelse is_lazy a)) args)
  85.121                          @[asm_simp_tac (HOLCF_ss addsimps when_apps) 1,
  85.122                            simp_tac (HOLCF_ss addsimps axs_con_def) 1]))cons;
  85.123  val copy_stricts = map (fn (con,args) => pg [] (mk_trp(dc_copy`UU`
  85.124 @@ -310,7 +310,7 @@
  85.125       (let val rews = cfst_strict::csnd_strict::copy_strict::copy_apps@con_rews
  85.126                           in map (case_UU_tac rews 1) (nonlazy args) @ [
  85.127                               asm_simp_tac (HOLCF_ss addsimps rews) 1] end))
  85.128 -                        (filter (fn (_,args)=>exists is_nonlazy_rec args) cons);
  85.129 +                        (List.filter (fn (_,args)=>exists is_nonlazy_rec args) cons);
  85.130  val copy_rews = copy_strict::copy_apps @ copy_stricts;
  85.131  in thy |> Theory.add_path (Sign.base_name dname)
  85.132         |> (#1 o (PureThy.add_thmss (map Thm.no_attributes [
  85.133 @@ -352,8 +352,8 @@
  85.134  local fun gt  s dn = get_thm  thy (dn ^ "." ^ s, NONE);
  85.135        fun gts s dn = get_thms thy (dn ^ "." ^ s, NONE) in
  85.136  val cases     =       map (gt  "casedist" ) dnames;
  85.137 -val con_rews  = flat (map (gts "con_rews" ) dnames);
  85.138 -val copy_rews = flat (map (gts "copy_rews") dnames);
  85.139 +val con_rews  = List.concat (map (gts "con_rews" ) dnames);
  85.140 +val copy_rews = List.concat (map (gts "copy_rews") dnames);
  85.141  end; (* local *)
  85.142  
  85.143  fun dc_take dn = %%:(dn^"_take");
  85.144 @@ -379,17 +379,17 @@
  85.145                                  simp_tac iterate_Cprod_ss 1]) 1 dnames;
  85.146    val c_UU_tac = case_UU_tac (take_stricts'::copy_con_rews) 1;
  85.147    val take_apps = pg copy_take_defs (mk_trp(foldr' mk_conj 
  85.148 -            (flat(map (fn ((dn,_),cons) => map (fn (con,args) => foldr mk_all 
  85.149 +            (List.concat(map (fn ((dn,_),cons) => map (fn (con,args) => Library.foldr mk_all 
  85.150          (map vname args,(dc_take dn $ (%%:"Suc" $ %:"n"))`(con_app con args) ===
  85.151 -         con_app2 con (app_rec_arg (fn n=>dc_take (nth_elem(n,dnames))$ %:"n"))
  85.152 +         con_app2 con (app_rec_arg (fn n=>dc_take (List.nth(dnames,n))$ %:"n"))
  85.153                                args)) cons) eqs)))) ([
  85.154                                  simp_tac iterate_Cprod_ss 1,
  85.155                                  induct_tac "n" 1,
  85.156                              simp_tac(iterate_Cprod_ss addsimps copy_con_rews) 1,
  85.157                                  asm_full_simp_tac (HOLCF_ss addsimps 
  85.158 -                                      (filter (has_fewer_prems 1) copy_rews)) 1,
  85.159 +                                      (List.filter (has_fewer_prems 1) copy_rews)) 1,
  85.160                                  TRY(safe_tac HOL_cs)] @
  85.161 -                        (flat(map (fn ((dn,_),cons) => map (fn (con,args) => 
  85.162 +                        (List.concat(map (fn ((dn,_),cons) => map (fn (con,args) => 
  85.163                                  if nonlazy_rec args = [] then all_tac else
  85.164                                  EVERY(map c_UU_tac (nonlazy_rec args)) THEN
  85.165                                  asm_full_simp_tac (HOLCF_ss addsimps copy_rews)1
  85.166 @@ -399,23 +399,23 @@
  85.167  end; (* local *)
  85.168  
  85.169  local
  85.170 -  fun one_con p (con,args) = foldr mk_All (map vname args,
  85.171 +  fun one_con p (con,args) = Library.foldr mk_All (map vname args,
  85.172          lift_defined (bound_arg (map vname args)) (nonlazy args,
  85.173          lift (fn arg => %:(P_name (1+rec_of arg)) $ bound_arg args arg)
  85.174 -         (filter is_rec args,mk_trp(%:p $ con_app2 con (bound_arg args) args))));
  85.175 +         (List.filter is_rec args,mk_trp(%:p $ con_app2 con (bound_arg args) args))));
  85.176    fun one_eq ((p,cons),concl) = (mk_trp(%:p $ UU) ===> 
  85.177 -                           foldr (op ===>) (map (one_con p) cons,concl));
  85.178 -  fun ind_term concf = foldr one_eq (mapn (fn n => fn x => (P_name n, x))1conss,
  85.179 +                           Library.foldr (op ===>) (map (one_con p) cons,concl));
  85.180 +  fun ind_term concf = Library.foldr one_eq (mapn (fn n => fn x => (P_name n, x))1conss,
  85.181                          mk_trp(foldr' mk_conj (mapn concf 1 dnames)));
  85.182    val take_ss = HOL_ss addsimps take_rews;
  85.183    fun quant_tac i = EVERY(mapn(fn n=> fn _=> res_inst_tac[("x",x_name n)]spec i)
  85.184                                 1 dnames);
  85.185 -  fun ind_prems_tac prems = EVERY(flat (map (fn cons => (
  85.186 +  fun ind_prems_tac prems = EVERY(List.concat (map (fn cons => (
  85.187                                       resolve_tac prems 1 ::
  85.188 -                                     flat (map (fn (_,args) => 
  85.189 +                                     List.concat (map (fn (_,args) => 
  85.190                                         resolve_tac prems 1 ::
  85.191                                         map (K(atac 1)) (nonlazy args) @
  85.192 -                                       map (K(atac 1)) (filter is_rec args))
  85.193 +                                       map (K(atac 1)) (List.filter is_rec args))
  85.194                                       cons))) conss));
  85.195    local 
  85.196      (* check whether every/exists constructor of the n-th part of the equation:
  85.197 @@ -425,11 +425,11 @@
  85.198            is_rec arg andalso not(rec_of arg mem ns) andalso
  85.199            ((rec_of arg =  n andalso nfn(lazy_rec orelse is_lazy arg)) orelse 
  85.200              rec_of arg <> n andalso rec_to quant nfn rfn (rec_of arg::ns) 
  85.201 -              (lazy_rec orelse is_lazy arg) (n, (nth_elem(rec_of arg,conss))))
  85.202 +              (lazy_rec orelse is_lazy arg) (n, (List.nth(conss,rec_of arg))))
  85.203            ) o snd) cons;
  85.204      fun all_rec_to ns  = rec_to forall not all_rec_to  ns;
  85.205      fun warn (n,cons)  = if all_rec_to [] false (n,cons) then (warning
  85.206 -        ("domain "^nth_elem(n,dnames)^" is empty!"); true) else false;
  85.207 +        ("domain "^List.nth(dnames,n)^" is empty!"); true) else false;
  85.208      fun lazy_rec_to ns = rec_to exists Id  lazy_rec_to ns;
  85.209  
  85.210    in val n__eqs     = mapn (fn n => fn (_,cons) => (n,cons)) 0 eqs;
  85.211 @@ -444,18 +444,18 @@
  85.212                                  induct_tac "n" 1,
  85.213                                  simp_tac (take_ss addsimps prems) 1,
  85.214                                  TRY(safe_tac HOL_cs)]
  85.215 -                                @ flat(map (fn (cons,cases) => [
  85.216 +                                @ List.concat(map (fn (cons,cases) => [
  85.217                                   res_inst_tac [("x","x")] cases 1,
  85.218                                   asm_simp_tac (take_ss addsimps prems) 1]
  85.219 -                                 @ flat(map (fn (con,args) => 
  85.220 +                                 @ List.concat(map (fn (con,args) => 
  85.221                                    asm_simp_tac take_ss 1 ::
  85.222                                    map (fn arg =>
  85.223                                     case_UU_tac (prems@con_rews) 1 (
  85.224 -                           nth_elem(rec_of arg,dnames)^"_take n$"^vname arg))
  85.225 -                                  (filter is_nonlazy_rec args) @ [
  85.226 +                           List.nth(dnames,rec_of arg)^"_take n$"^vname arg))
  85.227 +                                  (List.filter is_nonlazy_rec args) @ [
  85.228                                    resolve_tac prems 1] @
  85.229                                    map (K (atac 1))      (nonlazy args) @
  85.230 -                                  map (K (etac spec 1)) (filter is_rec args)) 
  85.231 +                                  map (K (etac spec 1)) (List.filter is_rec args)) 
  85.232                                   cons))
  85.233                                  (conss~~cases)));
  85.234  
  85.235 @@ -496,14 +496,14 @@
  85.236                                  induct_tac "n" 1,
  85.237                                  simp_tac take_ss 1,
  85.238                          TRY(safe_tac(empty_cs addSEs[conjE] addSIs[conjI]))] @
  85.239 -                                flat(mapn (fn n => fn (cons,cases) => [
  85.240 +                                List.concat(mapn (fn n => fn (cons,cases) => [
  85.241                                    simp_tac take_ss 1,
  85.242                                    rtac allI 1,
  85.243                                    res_inst_tac [("x",x_name n)] cases 1,
  85.244                                    asm_simp_tac take_ss 1] @ 
  85.245 -                                  flat(map (fn (con,args) => 
  85.246 +                                  List.concat(map (fn (con,args) => 
  85.247                                      asm_simp_tac take_ss 1 ::
  85.248 -                                    flat(map (fn vn => [
  85.249 +                                    List.concat(map (fn vn => [
  85.250                                        eres_inst_tac [("x",vn)] all_dupE 1,
  85.251                                        etac disjE 1,
  85.252                                        asm_simp_tac (HOL_ss addsimps con_rews) 1,
  85.253 @@ -523,7 +523,7 @@
  85.254    (finites,
  85.255     pg'' thy[](ind_term (fn n => fn dn => %:(P_name n) $ %:(x_name n)))(fn prems =>
  85.256                                  TRY(safe_tac HOL_cs) ::
  85.257 -                         flat (map (fn (finite,fin_ind) => [
  85.258 +                         List.concat (map (fn (finite,fin_ind) => [
  85.259                                 rtac(rewrite_rule axs_finite_def finite RS exE)1,
  85.260                                  etac subst 1,
  85.261                                  rtac fin_ind 1,
  85.262 @@ -532,7 +532,7 @@
  85.263  ) end (* let *) else
  85.264    (mapn (fn n => fn dn => read_instantiate_sg (sign_of thy) 
  85.265                      [("P",dn^"_finite "^x_name n)] excluded_middle) 1 dnames,
  85.266 -   pg'' thy [] (foldr (op ===>) (mapn (fn n => K(mk_trp(%%:"adm" $ %:(P_name n))))
  85.267 +   pg'' thy [] (Library.foldr (op ===>) (mapn (fn n => K(mk_trp(%%:"adm" $ %:(P_name n))))
  85.268                 1 dnames, ind_term (fn n => fn dn => %:(P_name n) $ %:(x_name n))))
  85.269                     (fn prems => map (fn ax_reach => rtac (ax_reach RS subst) 1) 
  85.270                                      axs_reach @ [
  85.271 @@ -556,8 +556,8 @@
  85.272    val take_ss = HOL_ss addsimps take_rews;
  85.273    val sproj   = prj (fn s => K("fst("^s^")")) (fn s => K("snd("^s^")"));
  85.274    val coind_lemma=pg[ax_bisim_def](mk_trp(mk_imp(%%:(comp_dname^"_bisim") $ %:"R",
  85.275 -                foldr (fn (x,t)=> mk_all(x,mk_all(x^"'",t))) (xs,
  85.276 -                  foldr mk_imp (mapn (fn n => K(proj (%:"R") eqs n $ 
  85.277 +                Library.foldr (fn (x,t)=> mk_all(x,mk_all(x^"'",t))) (xs,
  85.278 +                  Library.foldr mk_imp (mapn (fn n => K(proj (%:"R") eqs n $ 
  85.279                                        bnd_arg n 0 $ bnd_arg n 1)) 0 dnames,
  85.280                      foldr' mk_conj (mapn (fn n => fn dn => 
  85.281                                  (dc_take dn $ %:"n" `bnd_arg n 0 === 
  85.282 @@ -566,7 +566,7 @@
  85.283                                  induct_tac "n" 1,
  85.284                                  simp_tac take_ss 1,
  85.285                                  safe_tac HOL_cs] @
  85.286 -                                flat(mapn (fn n => fn x => [
  85.287 +                                List.concat(mapn (fn n => fn x => [
  85.288                                    rotate_tac (n+1) 1,
  85.289                                    etac all2E 1,
  85.290                                    eres_inst_tac [("P1", sproj "R" eqs n^
  85.291 @@ -576,11 +576,11 @@
  85.292                                  0 xs));
  85.293  in
  85.294  val coind = pg [] (mk_trp(%%:(comp_dname^"_bisim") $ %:"R") ===>
  85.295 -                foldr (op ===>) (mapn (fn n => fn x => 
  85.296 +                Library.foldr (op ===>) (mapn (fn n => fn x => 
  85.297                    mk_trp(proj (%:"R") eqs n $ %:x $ %:(x^"'"))) 0 xs,
  85.298                    mk_trp(foldr' mk_conj (map (fn x => %:x === %:(x^"'")) xs)))) ([
  85.299                                  TRY(safe_tac HOL_cs)] @
  85.300 -                                flat(map (fn take_lemma => [
  85.301 +                                List.concat(map (fn take_lemma => [
  85.302                                    rtac take_lemma 1,
  85.303                                    cut_facts_tac [coind_lemma] 1,
  85.304                                    fast_tac HOL_cs 1])
    86.1 --- a/src/Provers/Arith/abel_cancel.ML	Thu Mar 03 09:22:35 2005 +0100
    86.2 +++ b/src/Provers/Arith/abel_cancel.ML	Thu Mar 03 12:43:01 2005 +0100
    86.3 @@ -160,7 +160,7 @@
    86.4         val _ = if null common then raise Cancel  (*nothing to do*)
    86.5                                     else ()
    86.6  
    86.7 -       fun cancelled tms = mk_sum ty (foldl cancel1 (tms, common))
    86.8 +       fun cancelled tms = mk_sum ty (Library.foldl cancel1 (tms, common))
    86.9  
   86.10         val lt' = cancelled ltms
   86.11         and rt' = cancelled rtms
    87.1 --- a/src/Provers/Arith/cancel_numeral_factor.ML	Thu Mar 03 09:22:35 2005 +0100
    87.2 +++ b/src/Provers/Arith/cancel_numeral_factor.ML	Thu Mar 03 12:43:01 2005 +0100
    87.3 @@ -75,7 +75,7 @@
    87.4  	    Data.prove_conv [Data.norm_tac] sg hyps xs
    87.5  	      (t',   Data.mk_bal (newshape(n1,t1'), newshape(n2,t2')))
    87.6    in
    87.7 -      apsome Data.simplify_meta_eq
    87.8 +      Option.map Data.simplify_meta_eq
    87.9         (Data.prove_conv 
   87.10  	       [Data.trans_tac reshape, rtac Data.cancel 1,
   87.11  		Data.numeral_simp_tac] sg hyps xs (t', rhs))
    88.1 --- a/src/Provers/Arith/cancel_numerals.ML	Thu Mar 03 09:22:35 2005 +0100
    88.2 +++ b/src/Provers/Arith/cancel_numerals.ML	Thu Mar 03 12:43:01 2005 +0100
    88.3 @@ -59,11 +59,11 @@
    88.4  (*a left-to-right scan of terms1, seeking a term of the form #n*u, where
    88.5    #m*u is in terms2 for some m*)
    88.6  fun find_common (terms1,terms2) =
    88.7 -  let val tab2 = foldl update_by_coeff (Termtab.empty, terms2)
    88.8 +  let val tab2 = Library.foldl update_by_coeff (Termtab.empty, terms2)
    88.9        fun seek [] = raise TERM("find_common", []) 
   88.10  	| seek (t::terms) =
   88.11  	      let val (_,u) = Data.dest_coeff t 
   88.12 -	      in  if is_some (Termtab.lookup (tab2, u)) then u
   88.13 +	      in  if isSome (Termtab.lookup (tab2, u)) then u
   88.14  		  else seek terms
   88.15  	      end
   88.16    in  seek terms1 end;
   88.17 @@ -91,7 +91,7 @@
   88.18  			 Data.mk_bal (newshape(n1,terms1'), 
   88.19  				      newshape(n2,terms2')))
   88.20    in
   88.21 -      apsome Data.simplify_meta_eq
   88.22 +      Option.map Data.simplify_meta_eq
   88.23         (if n2<=n1 then 
   88.24  	    Data.prove_conv 
   88.25  	       [Data.trans_tac reshape, rtac Data.bal_add1 1,
    89.1 --- a/src/Provers/Arith/combine_numerals.ML	Thu Mar 03 09:22:35 2005 +0100
    89.2 +++ b/src/Provers/Arith/combine_numerals.ML	Thu Mar 03 12:43:01 2005 +0100
    89.3 @@ -78,7 +78,7 @@
    89.4  			 Data.mk_sum T ([Data.mk_coeff(m,u),
    89.5  				         Data.mk_coeff(n,u)] @ terms))
    89.6    in
    89.7 -      apsome Data.simplify_meta_eq
    89.8 +      Option.map Data.simplify_meta_eq
    89.9  	 (Data.prove_conv 
   89.10  	    [Data.trans_tac reshape, rtac Data.left_distrib 1,
   89.11  	     Data.numeral_simp_tac] sg xs
    90.1 --- a/src/Provers/Arith/extract_common_term.ML	Thu Mar 03 09:22:35 2005 +0100
    90.2 +++ b/src/Provers/Arith/extract_common_term.ML	Thu Mar 03 12:43:01 2005 +0100
    90.3 @@ -42,10 +42,10 @@
    90.4  
    90.5  (*a left-to-right scan of terms1, seeking a term u that is also in terms2*)
    90.6  fun find_common (terms1,terms2) =
    90.7 -  let val tab2 = foldl update_by_coeff (Termtab.empty, terms2)
    90.8 +  let val tab2 = Library.foldl update_by_coeff (Termtab.empty, terms2)
    90.9        fun seek [] = raise TERM("find_common", []) 
   90.10  	| seek (u::terms) =
   90.11 -	      if is_some (Termtab.lookup (tab2, u)) then u
   90.12 +	      if isSome (Termtab.lookup (tab2, u)) then u
   90.13  	      else seek terms
   90.14    in  seek terms1 end;
   90.15  
   90.16 @@ -68,7 +68,7 @@
   90.17  		 Data.mk_bal (Data.mk_sum T (u::terms1'), 
   90.18  		              Data.mk_sum T (u::terms2')))
   90.19    in
   90.20 -      apsome Data.simplify_meta_eq reshape
   90.21 +      Option.map Data.simplify_meta_eq reshape
   90.22    end
   90.23    handle TERM _ => NONE
   90.24         | TYPE _ => NONE;   (*Typically (if thy doesn't include Numeral)
    91.1 --- a/src/Provers/Arith/fast_lin_arith.ML	Thu Mar 03 09:22:35 2005 +0100
    91.2 +++ b/src/Provers/Arith/fast_lin_arith.ML	Thu Mar 03 12:43:01 2005 +0100
    91.3 @@ -171,7 +171,7 @@
    91.4  (* PRE: ex[v] must be 0! *)
    91.5  fun eval (ex:rat list) v (a:int,le,cs:int list) =
    91.6    let val rs = map rat_of_int cs
    91.7 -      val rsum = foldl ratadd (rat0,map ratmul (rs ~~ ex))
    91.8 +      val rsum = Library.foldl ratadd (rat0,map ratmul (rs ~~ ex))
    91.9    in (ratmul(ratadd(rat_of_int a,ratneg rsum), ratinv(el v rs)), le) end;
   91.10  (* If el v rs < 0, le should be negated.
   91.11     Instead this swap is taken into account in ratrelmin2.
   91.12 @@ -217,14 +217,14 @@
   91.13                      in if ratle(lb,ub') then ub' else raise NoEx end;
   91.14  
   91.15  fun findex1 discr (ex,(v,lineqs)) =
   91.16 -  let val nz = filter (fn (Lineq(_,_,cs,_)) => el v cs <> 0) lineqs;
   91.17 -      val ineqs = foldl elim_eqns ([],nz)
   91.18 -      val (ge,le) = partition (fn (_,_,cs) => el v cs > 0) ineqs
   91.19 +  let val nz = List.filter (fn (Lineq(_,_,cs,_)) => el v cs <> 0) lineqs;
   91.20 +      val ineqs = Library.foldl elim_eqns ([],nz)
   91.21 +      val (ge,le) = List.partition (fn (_,_,cs) => el v cs > 0) ineqs
   91.22        val lb = ratrelmax(map (eval ex v) ge)
   91.23        val ub = ratrelmin(map (eval ex v) le)
   91.24 -  in nth_update (choose2 (nth_elem(v,discr)) (lb,ub)) (v,ex) end;
   91.25 +  in nth_update (choose2 (List.nth(discr,v)) (lb,ub)) (v,ex) end;
   91.26  
   91.27 -fun findex discr = foldl (findex1 discr);
   91.28 +fun findex discr = Library.foldl (findex1 discr);
   91.29  
   91.30  fun elim1 v x =
   91.31    map (fn (a,le,bs) => (ratadd(a,ratneg(ratmul(el v bs,x))), le,
   91.32 @@ -239,9 +239,9 @@
   91.33    in case nz of [] => ex
   91.34       | (_,_,cs) :: _ =>
   91.35         let val v = find_index (not o equal rat0) cs
   91.36 -           val d = nth_elem(v,discr)
   91.37 +           val d = List.nth(discr,v)
   91.38             val pos = ratge0(el v cs)
   91.39 -           val sv = filter (single_var v) nz
   91.40 +           val sv = List.filter (single_var v) nz
   91.41             val minmax =
   91.42               if pos then if d then ratroundup o fst o ratrelmax
   91.43                           else ratexact true o ratrelmax
   91.44 @@ -255,7 +255,7 @@
   91.45    end;
   91.46  
   91.47  fun findex0 discr n lineqs =
   91.48 -  let val ineqs = foldl elim_eqns ([],lineqs)
   91.49 +  let val ineqs = Library.foldl elim_eqns ([],lineqs)
   91.50        val rineqs = map (fn (a,le,cs) => (rat_of_int a, le, map rat_of_int cs))
   91.51                         ineqs
   91.52    in pick_vars discr (rineqs,replicate n rat0) end;
   91.53 @@ -321,7 +321,7 @@
   91.54    case ty  of Eq => k <> 0 | Le => k > 0 | Lt => k >= 0;
   91.55  
   91.56  fun calc_blowup l =
   91.57 -  let val (p,n) = partition (apl(0,op<)) (filter (apl(0,op<>)) l)
   91.58 +  let val (p,n) = List.partition (apl(0,op<)) (List.filter (apl(0,op<>)) l)
   91.59    in (length p) * (length n) end;
   91.60  
   91.61  (* ------------------------------------------------------------------------- *)
   91.62 @@ -337,7 +337,7 @@
   91.63  (* ------------------------------------------------------------------------- *)
   91.64  
   91.65  fun allpairs f xs ys =
   91.66 -  flat(map (fn x => map (fn y => f x y) ys) xs);
   91.67 +  List.concat(map (fn x => map (fn y => f x y) ys) xs);
   91.68  
   91.69  fun extract_first p =
   91.70    let fun extract xs (y::ys) = if p y then (SOME y,xs@ys)
   91.71 @@ -358,7 +358,7 @@
   91.72  
   91.73  fun elim(ineqs,hist) =
   91.74    let val dummy = print_ineqs ineqs;
   91.75 -      val (triv,nontriv) = partition is_trivial ineqs in
   91.76 +      val (triv,nontriv) = List.partition is_trivial ineqs in
   91.77    if not(null triv)
   91.78    then case Library.find_first is_answer triv of
   91.79           NONE => elim(nontriv,hist)
   91.80 @@ -366,16 +366,16 @@
   91.81    else
   91.82    if null nontriv then Failure(hist)
   91.83    else
   91.84 -  let val (eqs,noneqs) = partition (fn (Lineq(_,ty,_,_)) => ty=Eq) nontriv in
   91.85 +  let val (eqs,noneqs) = List.partition (fn (Lineq(_,ty,_,_)) => ty=Eq) nontriv in
   91.86    if not(null eqs) then
   91.87 -     let val clist = foldl (fn (cs,Lineq(_,_,l,_)) => l union cs) ([],eqs)
   91.88 +     let val clist = Library.foldl (fn (cs,Lineq(_,_,l,_)) => l union cs) ([],eqs)
   91.89           val sclist = sort (fn (x,y) => int_ord(abs(x),abs(y)))
   91.90 -                           (filter (fn i => i<>0) clist)
   91.91 +                           (List.filter (fn i => i<>0) clist)
   91.92           val c = hd sclist
   91.93           val (SOME(eq as Lineq(_,_,ceq,_)),othereqs) =
   91.94                 extract_first (fn Lineq(_,_,l,_) => c mem l) eqs
   91.95           val v = find_index_eq c ceq
   91.96 -         val (ioth,roth) = partition (fn (Lineq(_,_,l,_)) => el v l = 0)
   91.97 +         val (ioth,roth) = List.partition (fn (Lineq(_,_,l,_)) => el v l = 0)
   91.98                                       (othereqs @ noneqs)
   91.99           val others = map (elim_var v eq) roth @ ioth
  91.100       in elim(others,(v,nontriv)::hist) end
  91.101 @@ -385,12 +385,12 @@
  91.102        val coeffs = map (fn i => map (el i) lists) numlist
  91.103        val blows = map calc_blowup coeffs
  91.104        val iblows = blows ~~ numlist
  91.105 -      val nziblows = filter (fn (i,_) => i<>0) iblows
  91.106 +      val nziblows = List.filter (fn (i,_) => i<>0) iblows
  91.107    in if null nziblows then Failure((~1,nontriv)::hist)
  91.108       else
  91.109       let val (c,v) = hd(sort (fn (x,y) => int_ord(fst(x),fst(y))) nziblows)
  91.110 -         val (no,yes) = partition (fn (Lineq(_,_,l,_)) => el v l = 0) ineqs
  91.111 -         val (pos,neg) = partition(fn (Lineq(_,_,l,_)) => el v l > 0) yes
  91.112 +         val (no,yes) = List.partition (fn (Lineq(_,_,l,_)) => el v l = 0) ineqs
  91.113 +         val (pos,neg) = List.partition(fn (Lineq(_,_,l,_)) => el v l > 0) yes
  91.114       in elim(no @ allpairs (elim_var v) pos neg, (v,nontriv)::hist) end
  91.115    end
  91.116    end
  91.117 @@ -420,9 +420,9 @@
  91.118  in
  91.119  fun mkthm sg asms just =
  91.120    let val {add_mono_thms, mult_mono_thms, inj_thms, lessD, simpset} = Data.get_sg sg;
  91.121 -      val atoms = foldl (fn (ats,(lhs,_,_,rhs,_,_)) =>
  91.122 +      val atoms = Library.foldl (fn (ats,(lhs,_,_,rhs,_,_)) =>
  91.123                              map fst lhs  union  (map fst rhs  union  ats))
  91.124 -                        ([], mapfilter (fn thm => if Thm.no_prems thm
  91.125 +                        ([], List.mapPartial (fn thm => if Thm.no_prems thm
  91.126                                          then LA_Data.decomp sg (concl_of thm)
  91.127                                          else NONE) asms)
  91.128  
  91.129 @@ -438,7 +438,7 @@
  91.130        fun addthms thm1 thm2 =
  91.131          case add2 thm1 thm2 of
  91.132            NONE => (case try_add ([thm1] RL inj_thms) thm2 of
  91.133 -                     NONE => ( the(try_add ([thm2] RL inj_thms) thm1)
  91.134 +                     NONE => ( valOf(try_add ([thm2] RL inj_thms) thm1)
  91.135                                 handle OPTION =>
  91.136                                 (trace_thm "" thm1; trace_thm "" thm2;
  91.137                                  sys_error "Lin.arith. failed to add thms")
  91.138 @@ -468,8 +468,8 @@
  91.139          let val thm' = trace_thm "Simplified:" (full_simplify simpset thm)
  91.140          in if LA_Logic.is_False thm' then raise FalseE thm' else thm' end
  91.141  
  91.142 -      fun mk(Asm i) = trace_thm "Asm" (nth_elem(i,asms))
  91.143 -        | mk(Nat i) = (trace_msg "Nat"; LA_Logic.mk_nat_thm sg (nth_elem(i,atoms)))
  91.144 +      fun mk(Asm i) = trace_thm "Asm" (List.nth(asms,i))
  91.145 +        | mk(Nat i) = (trace_msg "Nat"; LA_Logic.mk_nat_thm sg (List.nth(atoms,i)))
  91.146          | mk(LessD(j)) = trace_thm "L" (hd([mk j] RL lessD))
  91.147          | mk(NotLeD(j)) = trace_thm "NLe" (mk j RS LA_Logic.not_leD)
  91.148          | mk(NotLeDD(j)) = trace_thm "NLeD" (hd([mk j RS LA_Logic.not_leD] RL lessD))
  91.149 @@ -484,7 +484,7 @@
  91.150          in trace_thm "After simplification:" fls;
  91.151             if LA_Logic.is_False fls then fls
  91.152             else
  91.153 -            (tracing "Assumptions:"; seq print_thm asms;
  91.154 +            (tracing "Assumptions:"; List.app print_thm asms;
  91.155               tracing "Proved:"; print_thm fls;
  91.156               warning "Linear arithmetic should have refuted the assumptions.\n\
  91.157                       \Please inform Tobias Nipkow (nipkow@in.tum.de).";
  91.158 @@ -496,7 +496,7 @@
  91.159  
  91.160  fun coeff poly atom = case assoc(poly,atom) of NONE => 0 | SOME i => i;
  91.161  
  91.162 -fun lcms is = foldl lcm (1,is);
  91.163 +fun lcms is = Library.foldl lcm (1,is);
  91.164  
  91.165  fun integ(rlhs,r,rel,rrhs,s,d) =
  91.166  let val (rn,rd) = rep_rat r and (sn,sd) = rep_rat s
  91.167 @@ -593,17 +593,17 @@
  91.168  fun add_datoms(dats,((lhs,_,_,rhs,_,d),_)) =
  91.169      (map (pair d o fst) lhs) union ((map (pair d o fst) rhs) union dats)
  91.170  
  91.171 -fun discr initems = map fst (foldl add_datoms ([],initems));
  91.172 +fun discr initems = map fst (Library.foldl add_datoms ([],initems));
  91.173  
  91.174  fun refutes sg (pTs,params) ex =
  91.175  let
  91.176    fun refute (initems::initemss) js =
  91.177 -    let val atoms = foldl add_atoms ([],initems)
  91.178 +    let val atoms = Library.foldl add_atoms ([],initems)
  91.179          val n = length atoms
  91.180          val mkleq = mklineq n atoms
  91.181          val ixs = 0 upto (n-1)
  91.182          val iatoms = atoms ~~ ixs
  91.183 -        val natlineqs = mapfilter (mknat pTs ixs) iatoms
  91.184 +        val natlineqs = List.mapPartial (mknat pTs ixs) iatoms
  91.185          val ineqs = map mkleq initems @ natlineqs
  91.186      in case elim(ineqs,[]) of
  91.187           Success(j) =>
  91.188 @@ -628,7 +628,7 @@
  91.189      end
  91.190      state;
  91.191  
  91.192 -fun count P xs = length(filter P xs);
  91.193 +fun count P xs = length(List.filter P xs);
  91.194  
  91.195  (* The limit on the number of ~= allowed.
  91.196     Because each ~= is split into two cases, this can lead to an explosion.
    92.1 --- a/src/Provers/blast.ML	Thu Mar 03 09:22:35 2005 +0100
    92.2 +++ b/src/Provers/blast.ML	Thu Mar 03 12:43:01 2005 +0100
    92.3 @@ -134,7 +134,7 @@
    92.4  fun rand (f$x) = x;
    92.5  
    92.6  (* maps   (f, [t1,...,tn])  to  f(t1,...,tn) *)
    92.7 -val list_comb : term * term list -> term = foldl (op $);
    92.8 +val list_comb : term * term list -> term = Library.foldl (op $);
    92.9  
   92.10  
   92.11  (* maps   f(t1,...,tn)  to  (f, [t1,...,tn]) ; naturally tail-recursive*)
   92.12 @@ -412,7 +412,7 @@
   92.13  	| inst (Abs(a,t))    = inst t
   92.14  	| inst (f $ u)       = (inst f; inst u)
   92.15  	| inst _             = ()
   92.16 -      fun revert() = seq (fn v => v:=NONE) (!updated)
   92.17 +      fun revert() = List.app (fn v => v:=NONE) (!updated)
   92.18    in  inst t; revert  end;
   92.19  
   92.20  
   92.21 @@ -635,7 +635,7 @@
   92.22  	| printPairs _                 = ()
   92.23        fun printBrs (brs0 as {pairs, lits, lim, ...} :: brs) =
   92.24  	    (fullTrace := brs0 :: !fullTrace;
   92.25 -	     seq (fn _ => immediate_output "+") brs;
   92.26 +	     List.app (fn _ => immediate_output "+") brs;
   92.27  	     immediate_output (" [" ^ Int.toString lim ^ "] ");
   92.28  	     printPairs pairs;
   92.29  	     writeln"")
   92.30 @@ -652,7 +652,7 @@
   92.31  	  | 1 => immediate_output"\t1 variable UPDATED:"
   92.32  	  | n => immediate_output("\t" ^ Int.toString n ^ " variables UPDATED:");
   92.33         (*display the instantiations themselves, though no variable names*)
   92.34 -       seq (fn v => immediate_output("   " ^ string_of sign 4 (the (!v))))
   92.35 +       List.app (fn v => immediate_output("   " ^ string_of sign 4 (valOf (!v))))
   92.36             (List.take(!trail, !ntrail-ntrl));
   92.37         writeln"")
   92.38      else ();
   92.39 @@ -751,8 +751,8 @@
   92.40              end
   92.41        (*substitute throughout "stack frame"; extract affected formulae*)
   92.42        fun subFrame ((Gs,Hs), (changed, frames)) =
   92.43 -	    let val (changed', Gs') = foldr subForm (Gs, (changed, []))
   92.44 -                val (changed'', Hs') = foldr subForm (Hs, (changed', []))
   92.45 +	    let val (changed', Gs') = Library.foldr subForm (Gs, (changed, []))
   92.46 +                val (changed'', Hs') = Library.foldr subForm (Hs, (changed', []))
   92.47              in  (changed'', (Gs',Hs')::frames)  end
   92.48        (*substitute throughout literals; extract affected ones*)
   92.49        fun subLit (lit, (changed, nlits)) =
   92.50 @@ -760,8 +760,8 @@
   92.51  	    in  if nlit aconv lit then (changed, nlit::nlits)
   92.52  		                  else ((nlit,true)::changed, nlits)
   92.53              end
   92.54 -      val (changed, lits') = foldr subLit (lits, ([], []))
   92.55 -      val (changed', pairs') = foldr subFrame (pairs, (changed, []))
   92.56 +      val (changed, lits') = Library.foldr subLit (lits, ([], []))
   92.57 +      val (changed', pairs') = Library.foldr subFrame (pairs, (changed, []))
   92.58    in  if !trace then writeln ("Substituting " ^ traceTerm sign u ^
   92.59  			      " for " ^ traceTerm sign t ^ " in branch" )
   92.60        else ();
   92.61 @@ -974,7 +974,7 @@
   92.62  				    then lim - (1+log(length rules))
   92.63  				    else lim   (*discourage branching updates*)
   92.64  			 val vars  = vars_in_vars vars
   92.65 -			 val vars' = foldr add_terms_vars (prems, vars)
   92.66 +			 val vars' = Library.foldr add_terms_vars (prems, vars)
   92.67  			 val choices' = (ntrl, nbrs, PRV) :: choices
   92.68  			 val tacs' = (tac(updated,false,true)) 
   92.69                                       :: tacs  (*no duplication; rotate*)
   92.70 @@ -1101,7 +1101,7 @@
   92.71  		    then
   92.72  		     let val updated = ntrl < !ntrail (*branch updated*)
   92.73  			 val vars  = vars_in_vars vars
   92.74 -			 val vars' = foldr add_terms_vars (prems, vars)
   92.75 +			 val vars' = Library.foldr add_terms_vars (prems, vars)
   92.76  			    (*duplicate H if md permits*)
   92.77  			 val dup = md (*earlier had "andalso vars' <> vars":
   92.78                                    duplicate only if the subgoal has new vars*)
    93.1 --- a/src/Provers/clasimp.ML	Thu Mar 03 09:22:35 2005 +0100
    93.2 +++ b/src/Provers/clasimp.ML	Thu Mar 03 12:43:01 2005 +0100
    93.3 @@ -151,30 +151,30 @@
    93.4  in
    93.5  
    93.6  val op addIffs =
    93.7 -  foldl (addIff (Classical.addSDs, Classical.addSEs, Classical.addSIs)
    93.8 +  Library.foldl (addIff (Classical.addSDs, Classical.addSEs, Classical.addSIs)
    93.9      (Classical.addDs, Classical.addEs, Classical.addIs) Simplifier.addsimps);
   93.10 -val op delIffs = foldl (delIff Classical.delrules Simplifier.delsimps);
   93.11 +val op delIffs = Library.foldl (delIff Classical.delrules Simplifier.delsimps);
   93.12  
   93.13  fun AddIffs thms = store_clasimp (clasimpset () addIffs thms);
   93.14  fun DelIffs thms = store_clasimp (clasimpset () delIffs thms);
   93.15  
   93.16  fun addIffs_global (thy, ths) =
   93.17 -  foldl (addIff
   93.18 +  Library.foldl (addIff
   93.19      (ContextRules.addXDs_global, ContextRules.addXEs_global, ContextRules.addXIs_global)
   93.20      (ContextRules.addXDs_global, ContextRules.addXEs_global, ContextRules.addXIs_global) #1)
   93.21    ((thy, ()), ths) |> #1;
   93.22  
   93.23  fun addIffs_local (ctxt, ths) =
   93.24 -  foldl (addIff
   93.25 +  Library.foldl (addIff
   93.26      (ContextRules.addXDs_local, ContextRules.addXEs_local, ContextRules.addXIs_local)
   93.27      (ContextRules.addXDs_local, ContextRules.addXEs_local, ContextRules.addXIs_local) #1)
   93.28    ((ctxt, ()), ths) |> #1;
   93.29  
   93.30  fun delIffs_global (thy, ths) =
   93.31 -  foldl (delIff ContextRules.delrules_global #1) ((thy, ()), ths) |> #1;
   93.32 +  Library.foldl (delIff ContextRules.delrules_global #1) ((thy, ()), ths) |> #1;
   93.33  
   93.34  fun delIffs_local (ctxt, ths) =
   93.35 -  foldl (delIff ContextRules.delrules_local #1) ((ctxt, ()), ths) |> #1;
   93.36 +  Library.foldl (delIff ContextRules.delrules_local #1) ((ctxt, ()), ths) |> #1;
   93.37  
   93.38  end;
   93.39  
    94.1 --- a/src/Provers/classical.ML	Thu Mar 03 09:22:35 2005 +0100
    94.2 +++ b/src/Provers/classical.ML	Thu Mar 03 12:43:01 2005 +0100
    94.3 @@ -214,7 +214,7 @@
    94.4      let fun addrl (rl,brls) = (false, rl) :: (true, rl RSN (2,swap)) :: brls
    94.5      in  assume_tac      ORELSE'
    94.6          contr_tac       ORELSE'
    94.7 -        biresolve_tac (foldr addrl (rls,[]))
    94.8 +        biresolve_tac (Library.foldr addrl (rls,[]))
    94.9      end;
   94.10  
   94.11  (*Duplication of hazardous rules, for complete provers*)
   94.12 @@ -286,7 +286,7 @@
   94.13  fun rep_cs (CS args) = args;
   94.14  
   94.15  local
   94.16 -  fun wrap l tac = foldr (fn ((name,tacf),w) => tacf w) (l, tac);
   94.17 +  fun wrap l tac = Library.foldr (fn ((name,tacf),w) => tacf w) (l, tac);
   94.18  in
   94.19    fun appSWrappers (CS{swrappers,...}) = wrap swrappers;
   94.20    fun appWrappers  (CS{uwrappers,...}) = wrap uwrappers;
   94.21 @@ -316,7 +316,7 @@
   94.22  fun tag_brls' _ _ [] = []
   94.23    | tag_brls' w k (brl::brls) = ((w, k), brl) :: tag_brls' w (k + 1) brls;
   94.24  
   94.25 -fun insert_tagged_list kbrls netpr = foldr Tactic.insert_tagged_brl (kbrls, netpr);
   94.26 +fun insert_tagged_list kbrls netpr = Library.foldr Tactic.insert_tagged_brl (kbrls, netpr);
   94.27  
   94.28  (*Insert into netpair that already has nI intr rules and nE elim rules.
   94.29    Count the intr rules double (to account for swapify).  Negate to give the
   94.30 @@ -324,7 +324,7 @@
   94.31  fun insert (nI, nE) = insert_tagged_list o (tag_brls (~(2*nI+nE))) o joinrules;
   94.32  fun insert' w (nI, nE) = insert_tagged_list o tag_brls' w (~(nI + nE)) o joinrules';
   94.33  
   94.34 -fun delete_tagged_list brls netpr = foldr Tactic.delete_tagged_brl (brls, netpr);
   94.35 +fun delete_tagged_list brls netpr = Library.foldr Tactic.delete_tagged_brl (brls, netpr);
   94.36  fun delete x = delete_tagged_list (joinrules x);
   94.37  fun delete' x = delete_tagged_list (joinrules' x);
   94.38  
   94.39 @@ -355,7 +355,7 @@
   94.40            cs)
   94.41    else
   94.42    let val (safe0_rls, safep_rls) = (*0 subgoals vs 1 or more*)
   94.43 -          partition Thm.no_prems [th]
   94.44 +          List.partition Thm.no_prems [th]
   94.45        val nI = length safeIs + 1
   94.46        and nE = length safeEs
   94.47    in warn_dup th cs;
   94.48 @@ -380,7 +380,7 @@
   94.49            cs)
   94.50    else
   94.51    let val (safe0_rls, safep_rls) = (*0 subgoals vs 1 or more*)
   94.52 -          partition (fn rl => nprems_of rl=1) [th]
   94.53 +          List.partition (fn rl => nprems_of rl=1) [th]
   94.54        val nI = length safeIs
   94.55        and nE = length safeEs + 1
   94.56    in warn_dup th cs;
   94.57 @@ -397,7 +397,7 @@
   94.58          xtra_netpair = insert' 0 (nI,nE) ([], [th]) xtra_netpair}
   94.59    end;
   94.60  
   94.61 -fun rev_foldl f (e, l) = foldl f (e, rev l);
   94.62 +fun rev_foldl f (e, l) = Library.foldl f (e, rev l);
   94.63  
   94.64  val op addSIs = rev_foldl addSI;
   94.65  val op addSEs = rev_foldl addSE;
   94.66 @@ -470,7 +470,7 @@
   94.67            (cs as CS{safeIs, safeEs, hazIs, hazEs, swrappers, uwrappers,
   94.68                      safe0_netpair, safep_netpair, haz_netpair, dup_netpair, xtra_netpair}) =
   94.69   if mem_thm (th, safeIs) then
   94.70 -   let val (safe0_rls, safep_rls) = partition Thm.no_prems [th]
   94.71 +   let val (safe0_rls, safep_rls) = List.partition Thm.no_prems [th]
   94.72     in CS{safe0_netpair = delete (safe0_rls, []) safe0_netpair,
   94.73           safep_netpair = delete (safep_rls, []) safep_netpair,
   94.74           safeIs = rem_thm (safeIs,th),
   94.75 @@ -489,7 +489,7 @@
   94.76            (cs as CS{safeIs, safeEs, hazIs, hazEs, swrappers, uwrappers,
   94.77                      safe0_netpair, safep_netpair, haz_netpair, dup_netpair, xtra_netpair}) =
   94.78   if mem_thm (th, safeEs) then
   94.79 -   let val (safe0_rls, safep_rls) = partition (fn rl => nprems_of rl=1) [th]
   94.80 +   let val (safe0_rls, safep_rls) = List.partition (fn rl => nprems_of rl=1) [th]
   94.81     in CS{safe0_netpair = delete ([], safe0_rls) safe0_netpair,
   94.82           safep_netpair = delete ([], safep_rls) safep_netpair,
   94.83           safeIs = safeIs,
   94.84 @@ -550,7 +550,7 @@
   94.85      else (warning ("Undeclared classical rule\n" ^ (string_of_thm th)); cs)
   94.86    end;
   94.87  
   94.88 -val op delrules = foldl delrule;
   94.89 +val op delrules = Library.foldl delrule;
   94.90  
   94.91  
   94.92  (*** Modifying the wrapper tacticals ***)
   94.93 @@ -661,7 +661,7 @@
   94.94  (*version of bimatch_from_nets_tac that only applies rules that
   94.95    create precisely n subgoals.*)
   94.96  fun n_bimatch_from_nets_tac n =
   94.97 -    biresolution_from_nets_tac (Tactic.orderlist o filter (nsubgoalsP n)) true;
   94.98 +    biresolution_from_nets_tac (Tactic.orderlist o List.filter (nsubgoalsP n)) true;
   94.99  
  94.100  fun eq_contr_tac i = ematch_tac [not_elim] i  THEN  eq_assume_tac i;
  94.101  val eq_assume_contr_tac = eq_assume_tac ORELSE' eq_contr_tac;
    95.1 --- a/src/Provers/ind.ML	Thu Mar 03 09:22:35 2005 +0100
    95.2 +++ b/src/Provers/ind.ML	Thu Mar 03 12:43:01 2005 +0100
    95.3 @@ -41,9 +41,9 @@
    95.4  (*Generalizes over all free variables, with the named var outermost.*)
    95.5  fun all_frees_tac (var:string) i thm = 
    95.6      let val tsig = Sign.tsig_of (Thm.sign_of_thm thm);
    95.7 -        val frees = add_term_frees tsig (nth_elem(i-1,prems_of thm),[var]);
    95.8 +        val frees = add_term_frees tsig (List.nth(prems_of thm,i-1),[var]);
    95.9          val frees' = sort (rev_order o string_ord) (frees \ var) @ [var]
   95.10 -    in foldl (qnt_tac i) (all_tac,frees') thm end;
   95.11 +    in Library.foldl (qnt_tac i) (all_tac,frees') thm end;
   95.12  
   95.13  fun REPEAT_SIMP_TAC simp_tac n i =
   95.14  let fun repeat thm = 
    96.1 --- a/src/Provers/induct_method.ML	Thu Mar 03 09:22:35 2005 +0100
    96.2 +++ b/src/Provers/induct_method.ML	Thu Mar 03 12:43:01 2005 +0100
    96.3 @@ -59,7 +59,7 @@
    96.4      val xs = InductAttrib.vars_of tm;
    96.5    in
    96.6      align "Rule has fewer variables than instantiations given" xs ts
    96.7 -    |> mapfilter prep_var
    96.8 +    |> List.mapPartial prep_var
    96.9    end;
   96.10  
   96.11  
   96.12 @@ -96,7 +96,7 @@
   96.13      fun inst_rule r =
   96.14        if null insts then RuleCases.add r
   96.15        else (align_left "Rule has fewer premises than arguments given" (Thm.prems_of r) insts
   96.16 -        |> (flat o map (prep_inst align_left cert I))
   96.17 +        |> (List.concat o map (prep_inst align_left cert I))
   96.18          |> Drule.cterm_instantiate) r |> rpair (RuleCases.get r);
   96.19  
   96.20      val ruleq =
   96.21 @@ -108,8 +108,8 @@
   96.22            end
   96.23        | SOME r => Seq.single (inst_rule r));
   96.24  
   96.25 -    fun prep_rule (th, (cases, n)) = Seq.map (apsnd (rpair (drop (n, facts))) o rpair cases)
   96.26 -      (Method.multi_resolves (take (n, facts)) [th]);
   96.27 +    fun prep_rule (th, (cases, n)) = Seq.map (apsnd (rpair (Library.drop (n, facts))) o rpair cases)
   96.28 +      (Method.multi_resolves (Library.take (n, facts)) [th]);
   96.29    in resolveq_cases_tac (RuleCases.make is_open NONE) (Seq.flat (Seq.map prep_rule ruleq)) end;
   96.30  
   96.31  in
   96.32 @@ -161,7 +161,7 @@
   96.33    let
   96.34      val th = Thm.permute_prems (i - 1) 1 raw_th;
   96.35      val cprems = Drule.cprems_of th;
   96.36 -    val As = take (length cprems - 1, cprems);
   96.37 +    val As = Library.take (length cprems - 1, cprems);
   96.38      val C = Thm.cterm_of (Thm.sign_of_thm th) (Var (("C", #maxidx (Thm.rep_thm th) + 1), propT));
   96.39      val dummy_st = Drule.mk_triv_goal (Drule.list_implies (As, C));
   96.40    in th COMP Thm.lift_rule (dummy_st, 1) Data.local_impI end;
   96.41 @@ -256,7 +256,7 @@
   96.42        | rename_params ((y,_)::ys) = y::rename_params ys;
   96.43      fun rename_asm (A:term):term = 
   96.44        let val xs = rename_params (Logic.strip_params A)
   96.45 -          val xs' = case filter (equal x) xs of
   96.46 +          val xs' = case List.filter (equal x) xs of
   96.47                        [] => xs | [_] => xs | _ => index 1 xs
   96.48        in Logic.list_rename_params (xs',A) end;
   96.49      fun rename_prop (p:term) =
   96.50 @@ -268,9 +268,9 @@
   96.51    | rename _ thm = thm;
   96.52  
   96.53  fun find_inductT ctxt insts =
   96.54 -  foldr multiply (insts |> mapfilter (fn [] => NONE | ts => last_elem ts)
   96.55 +  Library.foldr multiply (insts |> List.mapPartial (fn [] => NONE | ts => List.last ts)
   96.56      |> map (InductAttrib.find_inductT ctxt o fastype_of), [[]])
   96.57 -  |> map join_rules |> flat |> map (rename insts);
   96.58 +  |> map join_rules |> List.concat |> map (rename insts);
   96.59  
   96.60  fun find_inductS ctxt (fact :: _) = InductAttrib.find_inductS ctxt fact
   96.61    | find_inductS _ _ = [];
   96.62 @@ -291,7 +291,7 @@
   96.63        if null insts then r
   96.64        else (align_right "Rule has fewer conclusions than arguments given"
   96.65            (Data.dest_concls (Thm.concl_of r)) insts
   96.66 -        |> (flat o map (prep_inst align_right cert (atomize_term sg)))
   96.67 +        |> (List.concat o map (prep_inst align_right cert (atomize_term sg)))
   96.68          |> Drule.cterm_instantiate) r);
   96.69  
   96.70      val ruleq =
   96.71 @@ -305,8 +305,8 @@
   96.72        | SOME r => r |> Seq.THEN (rule_versions, Seq.single o inst_rule));
   96.73  
   96.74      fun prep_rule (th, (cases, n)) =
   96.75 -      Seq.map (rpair (cases, n - length facts, drop (n, facts)))
   96.76 -        (Method.multi_resolves (take (n, facts)) [th]);
   96.77 +      Seq.map (rpair (cases, n - length facts, Library.drop (n, facts)))
   96.78 +        (Method.multi_resolves (Library.take (n, facts)) [th]);
   96.79      val tac = resolveq_cases_tac' RuleCases.make is_open (Seq.flat (Seq.map prep_rule ruleq));
   96.80    in tac THEN_ALL_NEW_CASES rulify_tac end;
   96.81  
    97.1 --- a/src/Provers/make_elim.ML	Thu Mar 03 09:22:35 2005 +0100
    97.2 +++ b/src/Provers/make_elim.ML	Thu Mar 03 12:43:01 2005 +0100
    97.3 @@ -41,7 +41,7 @@
    97.4  	      | rl'::_ => making (i+1,rl')
    97.5      in  making (2, hd (compose_extra 1 (rl, 1, revcut_rl')))  end
    97.6      handle (*in default, use the previous version, which never fails*)
    97.7 -	   THM _ => Tactic.make_elim rl | LIST _ => Tactic.make_elim rl;
    97.8 +	   THM _ => Tactic.make_elim rl | Empty => Tactic.make_elim rl;
    97.9  
   97.10  end
   97.11   
    98.1 --- a/src/Provers/order.ML	Thu Mar 03 09:22:35 2005 +0100
    98.2 +++ b/src/Provers/order.ML	Thu Mar 03 12:43:01 2005 +0100
    98.3 @@ -91,7 +91,7 @@
    98.4    (* Internal exception, raised if contradiction ( x < x ) was derived *)
    98.5  
    98.6  fun prove asms = 
    98.7 -  let fun pr (Asm i) = nth_elem (i, asms)
    98.8 +  let fun pr (Asm i) = List.nth (asms, i)
    98.9    |       pr (Thm (prfs, thm)) = (map pr prfs) MRS thm
   98.10    in pr end;
   98.11  
   98.12 @@ -437,7 +437,7 @@
   98.13  
   98.14     (* Compute, for each adjacency list, the list with reversed edges,
   98.15        and concatenate these lists. *)
   98.16 -   val flipped = foldr (op @) ((map flip g),nil)
   98.17 +   val flipped = Library.foldr (op @) ((map flip g),nil)
   98.18   
   98.19   in assemble g flipped end    
   98.20        
   98.21 @@ -475,7 +475,7 @@
   98.22        let
   98.23     val _ = visited := u :: !visited
   98.24     val descendents =
   98.25 -       foldr (fn ((v,l),ds) => if been_visited v then ds
   98.26 +       Library.foldr (fn ((v,l),ds) => if been_visited v then ds
   98.27              else v :: dfs_visit g v @ ds)
   98.28          ((adjacent (op aconv) g u) ,nil)
   98.29        in
   98.30 @@ -499,7 +499,7 @@
   98.31       dfs_visit along with u form a connected component. We
   98.32       collect all the connected components together in a
   98.33       list, which is what is returned. *)
   98.34 -  foldl (fn (comps,u) =>  
   98.35 +  Library.foldl (fn (comps,u) =>  
   98.36        if been_visited u then comps
   98.37        else ((u :: dfs_visit (transpose (op aconv) G) u) :: comps))  (nil,(!finish))
   98.38  end;
   98.39 @@ -525,7 +525,7 @@
   98.40        let
   98.41     val _ = visited := u :: !visited
   98.42     val descendents =
   98.43 -       foldr (fn ((v,l),ds) => if been_visited v then ds
   98.44 +       Library.foldr (fn ((v,l),ds) => if been_visited v then ds
   98.45              else v :: dfs_visit g v @ ds)
   98.46          ( ((adjacent (op =) g u)) ,nil)
   98.47     in  descendents end
   98.48 @@ -537,7 +537,7 @@
   98.49      ListPair.map (fn (a,b) => (a,b)) (0 upto (length components -1), components);
   98.50  
   98.51  fun indexNodes IndexComp = 
   98.52 -    flat (map (fn (index, comp) => (map (fn v => (v,index)) comp)) IndexComp);
   98.53 +    List.concat (map (fn (index, comp) => (map (fn v => (v,index)) comp)) IndexComp);
   98.54      
   98.55  fun getIndex v [] = ~1
   98.56  |   getIndex v ((v',k)::vs) = if v aconv v' then k else getIndex v vs; 
   98.57 @@ -651,15 +651,15 @@
   98.58  	       val v = upper edge
   98.59  	   in
   98.60               if (getIndex u ntc) = xi then 
   98.61 -	       (completeTermPath x u (nth_elem(xi, sccSubgraphs)) )@[edge]
   98.62 -	       @(completeTermPath v y' (nth_elem((getIndex y' ntc),sccSubgraphs)) )
   98.63 +	       (completeTermPath x u (List.nth(sccSubgraphs, xi)) )@[edge]
   98.64 +	       @(completeTermPath v y' (List.nth(sccSubgraphs, getIndex y' ntc)) )
   98.65  	     else (rev_completeComponentPath u)@[edge]
   98.66 -	          @(completeTermPath v y' (nth_elem((getIndex y' ntc),sccSubgraphs)) )
   98.67 +	          @(completeTermPath v y' (List.nth(sccSubgraphs, getIndex y' ntc)) )
   98.68             end
   98.69     in  
   98.70        if x aconv y then 
   98.71          [(Le (x, y, (Thm ([], Less.le_refl))))]
   98.72 -      else ( if xi = yi then completeTermPath x y (nth_elem(xi, sccSubgraphs))
   98.73 +      else ( if xi = yi then completeTermPath x y (List.nth(sccSubgraphs, xi))
   98.74               else rev_completeComponentPath y )  
   98.75     end;
   98.76  
   98.77 @@ -820,15 +820,15 @@
   98.78                  (* if SCC_x is linked to SCC_y via edge e *)
   98.79  		 else if ui = xi andalso vi = yi then (
   98.80                     case e of (Less (_, _,_)) => (
   98.81 -		        let val xypath = (completeTermPath x u (nth_elem(ui, sccSubgraphs)) ) @ [e] @ (completeTermPath v y (nth_elem(vi, sccSubgraphs)) )
   98.82 +		        let val xypath = (completeTermPath x u (List.nth(sccSubgraphs, ui)) ) @ [e] @ (completeTermPath v y (List.nth(sccSubgraphs, vi)) )
   98.83  			    val xyLesss = transPath (tl xypath, hd xypath)
   98.84  			in  (Thm ([getprf xyLesss], Less.less_imp_neq)) end)
   98.85  		   | _ => (   
   98.86  		        let 
   98.87 -			    val xupath = completeTermPath x u  (nth_elem(ui, sccSubgraphs))
   98.88 -			    val uxpath = completeTermPath u x  (nth_elem(ui, sccSubgraphs))
   98.89 -			    val vypath = completeTermPath v y  (nth_elem(vi, sccSubgraphs))
   98.90 -			    val yvpath = completeTermPath y v  (nth_elem(vi, sccSubgraphs))
   98.91 +			    val xupath = completeTermPath x u  (List.nth(sccSubgraphs, ui))
   98.92 +			    val uxpath = completeTermPath u x  (List.nth(sccSubgraphs, ui))
   98.93 +			    val vypath = completeTermPath v y  (List.nth(sccSubgraphs, vi))
   98.94 +			    val yvpath = completeTermPath y v  (List.nth(sccSubgraphs, vi))
   98.95  			    val xuLesss = transPath (tl xupath, hd xupath)     
   98.96  			    val uxLesss = transPath (tl uxpath, hd uxpath)			    
   98.97  			    val vyLesss = transPath (tl vypath, hd vypath)			
   98.98 @@ -841,15 +841,15 @@
   98.99  			)       
  98.100  		  ) else if ui = yi andalso vi = xi then (
  98.101  		     case e of (Less (_, _,_)) => (
  98.102 -		        let val xypath = (completeTermPath y u (nth_elem(ui, sccSubgraphs)) ) @ [e] @ (completeTermPath v x (nth_elem(vi, sccSubgraphs)) )
  98.103 +		        let val xypath = (completeTermPath y u (List.nth(sccSubgraphs, ui)) ) @ [e] @ (completeTermPath v x (List.nth(sccSubgraphs, vi)) )
  98.104  			    val xyLesss = transPath (tl xypath, hd xypath)
  98.105  			in (Thm ([(Thm ([getprf xyLesss], Less.less_imp_neq))] , thm "not_sym")) end ) 
  98.106  		     | _ => (
  98.107  		        
  98.108 -			let val yupath = completeTermPath y u (nth_elem(ui, sccSubgraphs))
  98.109 -			    val uypath = completeTermPath u y (nth_elem(ui, sccSubgraphs))
  98.110 -			    val vxpath = completeTermPath v x (nth_elem(vi, sccSubgraphs))
  98.111 -			    val xvpath = completeTermPath x v (nth_elem(vi, sccSubgraphs))
  98.112 +			let val yupath = completeTermPath y u (List.nth(sccSubgraphs, ui))
  98.113 +			    val uypath = completeTermPath u y (List.nth(sccSubgraphs, ui))
  98.114 +			    val vxpath = completeTermPath v x (List.nth(sccSubgraphs, vi))
  98.115 +			    val xvpath = completeTermPath x v (List.nth(sccSubgraphs, vi))
  98.116  			    val yuLesss = transPath (tl yupath, hd yupath)     
  98.117  			    val uyLesss = transPath (tl uypath, hd uypath)			    
  98.118  			    val vxLesss = transPath (tl vxpath, hd vxpath)			
  98.119 @@ -944,9 +944,9 @@
  98.120      fun processComponent (k, comp) = 
  98.121       let    
  98.122          (* all edges with weight <= of the actual component *)  
  98.123 -        val leqEdges = flat (map (adjacent (op aconv) leqG) comp);
  98.124 +        val leqEdges = List.concat (map (adjacent (op aconv) leqG) comp);
  98.125          (* all edges with weight ~= of the actual component *)  
  98.126 -        val neqEdges = map snd (flat (map (adjacent (op aconv) neqG) comp));
  98.127 +        val neqEdges = map snd (List.concat (map (adjacent (op aconv) neqG) comp));
  98.128  
  98.129         (* find an edge leading to a contradiction *)   
  98.130         fun findContr [] = NONE
  98.131 @@ -1064,7 +1064,7 @@
  98.132    val rfrees = map Free (rename_wrt_term A (Logic.strip_params A))
  98.133    val Hs = map (fn H => subst_bounds (rfrees, H)) (Logic.strip_assums_hyp A)
  98.134    val C = subst_bounds (rfrees, Logic.strip_assums_concl A)
  98.135 -  val lesss = flat (ListPair.map (mkasm_partial sign) (Hs, 0 upto (length Hs - 1)))
  98.136 +  val lesss = List.concat (ListPair.map (mkasm_partial sign) (Hs, 0 upto (length Hs - 1)))
  98.137    val prfs = solvePartialOrder sign (lesss, C);
  98.138    val (subgoals, prf) = mkconcl_partial sign C;
  98.139   in
  98.140 @@ -1082,7 +1082,7 @@
  98.141    val rfrees = map Free (rename_wrt_term A (Logic.strip_params A))
  98.142    val Hs = map (fn H => subst_bounds (rfrees, H)) (Logic.strip_assums_hyp A)
  98.143    val C = subst_bounds (rfrees, Logic.strip_assums_concl A)
  98.144 -  val lesss = flat (ListPair.map (mkasm_linear sign) (Hs, 0 upto (length Hs - 1)))
  98.145 +  val lesss = List.concat (ListPair.map (mkasm_linear sign) (Hs, 0 upto (length Hs - 1)))
  98.146    val prfs = solveTotalOrder sign (lesss, C);
  98.147    val (subgoals, prf) = mkconcl_linear sign C;
  98.148   in
    99.1 --- a/src/Provers/quasi.ML	Thu Mar 03 09:22:35 2005 +0100
    99.2 +++ b/src/Provers/quasi.ML	Thu Mar 03 12:43:01 2005 +0100
    99.3 @@ -92,7 +92,7 @@
    99.4    (* Internal exception, raised if contradiction ( x < x ) was derived *)
    99.5  
    99.6  fun prove asms = 
    99.7 -  let fun pr (Asm i) = nth_elem (i, asms)
    99.8 +  let fun pr (Asm i) = List.nth (asms, i)
    99.9    |       pr (Thm (prfs, thm)) = (map pr prfs) MRS thm
   99.10    in pr end;
   99.11  
   99.12 @@ -560,7 +560,7 @@
   99.13    val rfrees = map Free (rename_wrt_term A (Logic.strip_params A))
   99.14    val Hs = map (fn H => subst_bounds (rfrees, H)) (Logic.strip_assums_hyp A)
   99.15    val C = subst_bounds (rfrees, Logic.strip_assums_concl A)
   99.16 -  val lesss = flat (ListPair.map (mkasm_trans  sign) (Hs, 0 upto (length Hs - 1)))
   99.17 +  val lesss = List.concat (ListPair.map (mkasm_trans  sign) (Hs, 0 upto (length Hs - 1)))
   99.18    val prfs = solveLeTrans  sign (lesss, C);
   99.19    
   99.20    val (subgoal, prf) = mkconcl_trans  sign C;
   99.21 @@ -581,7 +581,7 @@
   99.22    val rfrees = map Free (rename_wrt_term A (Logic.strip_params A))
   99.23    val Hs = map (fn H => subst_bounds (rfrees, H)) (Logic.strip_assums_hyp A)
   99.24    val C = subst_bounds (rfrees, Logic.strip_assums_concl A)
   99.25 -  val lesss = flat (ListPair.map (mkasm_quasi sign) (Hs, 0 upto (length Hs - 1)))
   99.26 +  val lesss = List.concat (ListPair.map (mkasm_quasi sign) (Hs, 0 upto (length Hs - 1)))
   99.27    val prfs = solveQuasiOrder sign (lesss, C);
   99.28    val (subgoals, prf) = mkconcl_quasi sign C;
   99.29   in
   100.1 --- a/src/Provers/simp.ML	Thu Mar 03 09:22:35 2005 +0100
   100.2 +++ b/src/Provers/simp.ML	Thu Mar 03 12:43:01 2005 +0100
   100.3 @@ -78,7 +78,7 @@
   100.4  	  bimatch_tac (Net.match_term net
   100.5  		       (lhs_of (strip_assums_concl prem))) i);
   100.6  
   100.7 -fun nth_subgoal i thm = nth_elem(i-1,prems_of thm);
   100.8 +fun nth_subgoal i thm = List.nth(prems_of thm,i-1);
   100.9  
  100.10  fun goal_concl i thm = strip_assums_concl(nth_subgoal i thm);
  100.11  
  100.12 @@ -155,7 +155,7 @@
  100.13  		     in case f of
  100.14  			    Const(c,T) => 
  100.15  				if c mem ccs
  100.16 -				then foldr add_hvars (args,hvars)
  100.17 +				then Library.foldr add_hvars (args,hvars)
  100.18  				else add_term_vars(tm,hvars)
  100.19  			  | _ => add_term_vars(tm,hvars)
  100.20  		     end
  100.21 @@ -167,7 +167,7 @@
  100.22  		if at then vars else add_term_vars(tm,vars)
  100.23  	fun add_list(tm,al,vars) = let val (_,tml) = strip_comb tm
  100.24  		in if length(tml)=length(al)
  100.25 -		   then foldr itf (tml~~al,vars)
  100.26 +		   then Library.foldr itf (tml~~al,vars)
  100.27  		   else vars
  100.28  		end
  100.29  	fun add_vars (tm,vars) = case tm of
  100.30 @@ -188,12 +188,12 @@
  100.31      val lhs = rhs_of_eq 1 thm'
  100.32      val rhs = lhs_of_eq nops thm'
  100.33      val asms = tl(rev(tl(prems_of thm')))
  100.34 -    val hvars = foldr (add_hidden_vars ccs) (lhs::rhs::asms,[])
  100.35 +    val hvars = Library.foldr (add_hidden_vars ccs) (lhs::rhs::asms,[])
  100.36      val hvars = add_new_asm_vars new_asms (rhs,hvars)
  100.37      fun it_asms (asm,hvars) =
  100.38  	if atomic asm then add_new_asm_vars new_asms (asm,hvars)
  100.39  	else add_term_frees(asm,hvars)
  100.40 -    val hvars = foldr it_asms (asms,hvars)
  100.41 +    val hvars = Library.foldr it_asms (asms,hvars)
  100.42      val hvs = map (#1 o dest_Var) hvars
  100.43      val refl1_tac = refl_tac 1
  100.44      fun norm_step_tac st = st |>
  100.45 @@ -210,7 +210,7 @@
  100.46  
  100.47  fun add_norm_tags congs =
  100.48      let val ccs = map cong_const congs
  100.49 -	val new_asms = filter (exists not o #2)
  100.50 +	val new_asms = List.filter (exists not o #2)
  100.51  		(ccs ~~ (map (map atomic o prems_of) congs));
  100.52      in add_norms(congs,ccs,new_asms) end;
  100.53  
  100.54 @@ -249,7 +249,7 @@
  100.55      (writeln"\nDuplicate rewrite or congruence rule:"; print_thm th;
  100.56       net);
  100.57  
  100.58 -val insert_thms = foldr insert_thm_warn;
  100.59 +val insert_thms = Library.foldr insert_thm_warn;
  100.60  
  100.61  fun addrew(SS{auto_tac,congs,cong_net,mk_simps,simps,simp_net,
  100.62                splits,split_consts}, thm) =
  100.63 @@ -259,7 +259,7 @@
  100.64        splits=splits,split_consts=split_consts}
  100.65  end;
  100.66  
  100.67 -val op addrews = foldl addrew;
  100.68 +val op addrews = Library.foldl addrew;
  100.69  
  100.70  fun op addcongs(SS{auto_tac,congs,cong_net,mk_simps,simps,simp_net,
  100.71                     splits,split_consts}, thms) =
  100.72 @@ -283,7 +283,7 @@
  100.73        mk_simps=mk_simps,simps=simps,simp_net=simp_net,
  100.74        splits=splits@[mk_trans thm],split_consts=split_consts@[a]} end;
  100.75  
  100.76 -val op addsplits = foldl addsplit;
  100.77 +val op addsplits = Library.foldl addsplit;
  100.78  
  100.79  (** Deletion of congruences and rewrites **)
  100.80  
  100.81 @@ -294,11 +294,11 @@
  100.82      (writeln"\nNo such rewrite or congruence rule:";  print_thm th;
  100.83       net);
  100.84  
  100.85 -val delete_thms = foldr delete_thm_warn;
  100.86 +val delete_thms = Library.foldr delete_thm_warn;
  100.87  
  100.88  fun op delcongs(SS{auto_tac,congs,cong_net,mk_simps,simps,simp_net,
  100.89                     splits,split_consts}, thms) =
  100.90 -let val congs' = foldl (gen_rem Drule.eq_thm_prop) (congs,thms)
  100.91 +let val congs' = Library.foldl (gen_rem Drule.eq_thm_prop) (congs,thms)
  100.92  in SS{auto_tac=auto_tac, congs= congs',
  100.93        cong_net= delete_thms(map mk_trans thms,cong_net),
  100.94        mk_simps= normed_rews congs', simps=simps, simp_net=simp_net,
  100.95 @@ -318,7 +318,7 @@
  100.96        splits=splits,split_consts=split_consts}
  100.97  end;
  100.98  
  100.99 -val op delrews = foldl delrew;
 100.100 +val op delrews = Library.foldl delrew;
 100.101  
 100.102  
 100.103  fun op setauto(SS{congs,cong_net,mk_simps,simps,simp_net,
 100.104 @@ -447,9 +447,9 @@
 100.105  	    SOME(thm',_) =>
 100.106  		    let val ps = prems_of thm and ps' = prems_of thm';
 100.107  			val n = length(ps')-length(ps);
 100.108 -			val a = length(strip_assums_hyp(nth_elem(i-1,ps)))
 100.109 +			val a = length(strip_assums_hyp(List.nth(ps,i-1)))
 100.110  			val l = map (fn p => length(strip_assums_hyp(p)))
 100.111 -				    (take(n,drop(i-1,ps')));
 100.112 +				    (Library.take(n,Library.drop(i-1,ps')));
 100.113  		    in (simp_refl(rev(l),a,REW::ss),thm',anet,ats,cs) end
 100.114  	  | NONE => (REW::ss,thm,anet,ats,cs);
 100.115  
 100.116 @@ -460,7 +460,7 @@
 100.117  	val thms = map (trivial o cterm_of(#sign(rep_thm(thm))))As;
 100.118  	val new_rws = flat(map mk_rew_rules thms);
 100.119  	val rwrls = map mk_trans (flat(map mk_rew_rules thms));
 100.120 -	val anet' = foldr lhs_insert_thm (rwrls,anet)
 100.121 +	val anet' = Library.foldr lhs_insert_thm (rwrls,anet)
 100.122      in  if !tracing andalso not(null new_rws)
 100.123  	then (writeln"Adding rewrites:";  prths new_rws;  ())
 100.124  	else ();
 100.125 @@ -565,7 +565,7 @@
 100.126  fun Pinst(f,fT,(eq,eqT),k,i,T,yik,Ts) =
 100.127  let fun xn_list(x,n) =
 100.128  	let val ixs = map (fn i => (x^(radixstring(26,"a",i)),0)) (0 upto n);
 100.129 -	in ListPair.map eta_Var (ixs, take(n+1,Ts)) end
 100.130 +	in ListPair.map eta_Var (ixs, Library.take(n+1,Ts)) end
 100.131      val lhs = list_comb(f,xn_list("X",k-1))
 100.132      val rhs = list_comb(f,xn_list("X",i-1) @ [Bound 0] @ yik)
 100.133  in Abs("", T, Const(eq,[fT,fT]--->eqT) $ lhs $ rhs) end;
   101.1 --- a/src/Provers/splitter.ML	Thu Mar 03 09:22:35 2005 +0100
   101.2 +++ b/src/Provers/splitter.ML	Thu Mar 03 12:43:01 2005 +0100
   101.3 @@ -102,8 +102,8 @@
   101.4        fun down [] t i = Bound 0
   101.5          | down (p::ps) t i =
   101.6              let val (h,ts) = strip_comb t
   101.7 -                val v1 = ListPair.map var (take(p,ts), i upto (i+p-1))
   101.8 -                val u::us = drop(p,ts)
   101.9 +                val v1 = ListPair.map var (Library.take(p,ts), i upto (i+p-1))
  101.10 +                val u::us = Library.drop(p,ts)
  101.11                  val v2 = ListPair.map var (us, (i+p) upto (i+length(ts)-2))
  101.12        in list_comb(h,v1@[down ps u (i+length ts)]@v2) end;
  101.13    in Abs("", T, down (rev pos) t maxi) end;
  101.14 @@ -137,7 +137,7 @@
  101.15     has a body of type T; otherwise the expansion thm will fail later on
  101.16  *)
  101.17  fun type_test(T,lbnos,apsns) =
  101.18 -  let val (_,U,_) = nth_elem(foldl Int.min (hd lbnos, tl lbnos), apsns)
  101.19 +  let val (_,U,_) = List.nth(apsns, Library.foldl Int.min (hd lbnos, tl lbnos))
  101.20    in T=U end;
  101.21  
  101.22  (*************************************************************************
  101.23 @@ -171,8 +171,8 @@
  101.24  fun mk_split_pack(thm, T, T', n, ts, apsns, pos, TB, t) =
  101.25    if n > length ts then []
  101.26    else let val lev = length apsns
  101.27 -           val lbnos = foldl add_lbnos ([],take(n,ts))
  101.28 -           val flbnos = filter (fn i => i < lev) lbnos
  101.29 +           val lbnos = Library.foldl add_lbnos ([],Library.take(n,ts))
  101.30 +           val flbnos = List.filter (fn i => i < lev) lbnos
  101.31             val tt = incr_boundvars (~lev) t
  101.32         in if null flbnos then
  101.33              if T = T' then [(thm,[],pos,TB,tt)] else []
  101.34 @@ -234,7 +234,7 @@
  101.35                Const(c, cT) =>
  101.36                  let fun find [] = []
  101.37                        | find ((gcT, pat, thm, T, n)::tups) =
  101.38 -                          let val t2 = list_comb (h, take (n, ts))
  101.39 +                          let val t2 = list_comb (h, Library.take (n, ts))
  101.40                            in if Sign.typ_instance sg (cT, gcT)
  101.41                                  andalso fomatch (Sign.tsig_of sg) (Ts,pat,t2)
  101.42                               then mk_split_pack(thm,T,T',n,ts,apsns,pos,type_of1(Ts,t2),t2)
  101.43 @@ -242,11 +242,11 @@
  101.44                            end
  101.45                  in find (assocs cmap c) end
  101.46              | _ => []
  101.47 -          in snd(foldl iter ((0, a), ts)) end
  101.48 +          in snd(Library.foldl iter ((0, a), ts)) end
  101.49    in posns Ts [] [] t end;
  101.50  
  101.51  
  101.52 -fun nth_subgoal i thm = nth_elem(i-1,prems_of thm);
  101.53 +fun nth_subgoal i thm = List.nth(prems_of thm,i-1);
  101.54  
  101.55  fun shorter((_,ps,pos,_,_),(_,qs,qos,_,_)) =
  101.56    prod_ord (int_ord o pairself length) (order o pairself length)
  101.57 @@ -312,7 +312,7 @@
  101.58        (Logic.strip_assums_concl (#prop (rep_thm thm')))));
  101.59      val cert = cterm_of (sign_of_thm state);
  101.60      val cntxt = mk_cntxt_splitthm t tt TB;
  101.61 -    val abss = foldl (fn (t, T) => Abs ("", T, t));
  101.62 +    val abss = Library.foldl (fn (t, T) => Abs ("", T, t));
  101.63    in cterm_instantiate [(cert P, cert (abss (cntxt, Ts)))] thm'
  101.64    end;
  101.65  
  101.66 @@ -337,7 +337,7 @@
  101.67                    end
  101.68                  | _ => split_format_err())
  101.69               | _ => split_format_err())
  101.70 -      val cmap = foldl add_thm ([],splits);
  101.71 +      val cmap = Library.foldl add_thm ([],splits);
  101.72        fun lift_tac Ts t p st = rtac (inst_lift Ts t p st i) i st
  101.73        fun lift_split_tac state =
  101.74              let val (Ts, t, splits) = select cmap state i
  101.75 @@ -421,13 +421,13 @@
  101.76          let val (name,asm) = split_thm_info split
  101.77          in Simplifier.addloop (ss, (split_name name asm,
  101.78  		       (if asm then split_asm_tac else split_tac) [split])) end
  101.79 -  in foldl addsplit (ss,splits) end;
  101.80 +  in Library.foldl addsplit (ss,splits) end;
  101.81  
  101.82  fun ss delsplits splits =
  101.83    let fun delsplit(ss,split) =
  101.84          let val (name,asm) = split_thm_info split
  101.85          in Simplifier.delloop (ss, split_name name asm)
  101.86 -  end in foldl delsplit (ss,splits) end;
  101.87 +  end in Library.foldl delsplit (ss,splits) end;
  101.88  
  101.89  fun Addsplits splits = (Simplifier.simpset_ref() := 
  101.90  			Simplifier.simpset() addsplits splits);
   102.1 --- a/src/Provers/trancl.ML	Thu Mar 03 09:22:35 2005 +0100
   102.2 +++ b/src/Provers/trancl.ML	Thu Mar 03 12:43:01 2005 +0100
   102.3 @@ -88,7 +88,7 @@
   102.4   exception Cannot; (* internal exception: raised if no proof can be found *)
   102.5  
   102.6   fun prove asms = 
   102.7 -  let fun pr (Asm i) = nth_elem (i, asms)
   102.8 +  let fun pr (Asm i) = List.nth (asms, i)
   102.9    |       pr (Thm (prfs, thm)) = (map pr prfs) MRS thm
  102.10    in pr end;
  102.11  
  102.12 @@ -327,7 +327,7 @@
  102.13  
  102.14     (* Compute, for each adjacency list, the list with reversed edges,
  102.15        and concatenate these lists. *)
  102.16 -   val flipped = foldr (op @) ((map flip g),nil)
  102.17 +   val flipped = Library.foldr (op @) ((map flip g),nil)
  102.18   
  102.19   in assemble g flipped end    
  102.20   
  102.21 @@ -351,7 +351,7 @@
  102.22        let
  102.23     val _ = visited := u :: !visited
  102.24     val descendents =
  102.25 -       foldr (fn ((v,l),ds) => if been_visited v then ds
  102.26 +       Library.foldr (fn ((v,l),ds) => if been_visited v then ds
  102.27              else v :: dfs_visit g v @ ds)
  102.28          ( ((adjacent eq_comp g u)) ,nil)
  102.29     in  descendents end
  102.30 @@ -530,7 +530,7 @@
  102.31    val Hs = Logic.strip_assums_hyp A;
  102.32    val C = Logic.strip_assums_concl A;
  102.33    val (rel,subgoals, prf) = mkconcl_trancl C;
  102.34 -  val prems = flat (ListPair.map (mkasm_trancl rel) (Hs, 0 upto (length Hs - 1)))
  102.35 +  val prems = List.concat (ListPair.map (mkasm_trancl rel) (Hs, 0 upto (length Hs - 1)))
  102.36    val prfs = solveTrancl (prems, C);
  102.37  
  102.38   in
  102.39 @@ -548,7 +548,7 @@
  102.40    val C = Logic.strip_assums_concl A;
  102.41    val (rel,subgoals, prf) = mkconcl_rtrancl C;
  102.42  
  102.43 -  val prems = flat (ListPair.map (mkasm_rtrancl rel) (Hs, 0 upto (length Hs - 1)))
  102.44 +  val prems = List.concat (ListPair.map (mkasm_rtrancl rel) (Hs, 0 upto (length Hs - 1)))
  102.45    val prfs = solveRtrancl (prems, C);
  102.46   in
  102.47    METAHYPS (fn asms =>
   103.1 --- a/src/Provers/typedsimp.ML	Thu Mar 03 09:22:35 2005 +0100
   103.2 +++ b/src/Provers/typedsimp.ML	Thu Mar 03 12:43:01 2005 +0100
   103.3 @@ -70,7 +70,7 @@
   103.4      handle THM _ => (simp_rls, rl :: other_rls);
   103.5  
   103.6  (*Given the list rls, return the pair (simp_rls, other_rls).*)
   103.7 -fun process_rules rls = foldr add_rule (rls, ([],[]));
   103.8 +fun process_rules rls = Library.foldr add_rule (rls, ([],[]));
   103.9  
  103.10  (*Given list of rewrite rules, return list of both forms, reject others*)
  103.11  fun process_rewrites rls = 
   104.1 --- a/src/Pure/General/file.ML	Thu Mar 03 09:22:35 2005 +0100
   104.2 +++ b/src/Pure/General/file.ML	Thu Mar 03 12:43:01 2005 +0100
   104.3 @@ -96,7 +96,7 @@
   104.4      | s => SOME (Info s))
   104.5    end;
   104.6  
   104.7 -val exists = is_some o info;
   104.8 +val exists = isSome o info;
   104.9  
  104.10  
  104.11  (* directories *)
   105.1 --- a/src/Pure/General/graph.ML	Thu Mar 03 09:22:35 2005 +0100
   105.2 +++ b/src/Pure/General/graph.ML	Thu Mar 03 12:43:01 2005 +0100
   105.3 @@ -67,7 +67,7 @@
   105.4  val empty_keys = Table.empty: keys;
   105.5  
   105.6  infix mem_keys;
   105.7 -fun x mem_keys tab = is_some (Table.lookup (tab: keys, x));
   105.8 +fun x mem_keys tab = isSome (Table.lookup (tab: keys, x));
   105.9  
  105.10  infix ins_keys;
  105.11  fun x ins_keys tab = if x mem_keys tab then tab else Table.update ((x, ()), tab);
  105.12 @@ -114,7 +114,7 @@
  105.13      fun reach ((R, rs), x) =
  105.14        if x mem_keys R then (R, rs)
  105.15        else apsnd (cons x) (reachs ((x ins_keys R, rs), next x))
  105.16 -    and reachs R_xs = foldl reach R_xs;
  105.17 +    and reachs R_xs = Library.foldl reach R_xs;
  105.18    in foldl_map (reach o apfst (rpair [])) (empty_keys, xs) end;
  105.19  
  105.20  (*immediate*)
  105.21 @@ -122,13 +122,13 @@
  105.22  fun imm_succs G = #2 o #2 o get_entry G;
  105.23  
  105.24  (*transitive*)
  105.25 -fun all_preds G = flat o snd o reachable (imm_preds G);
  105.26 -fun all_succs G = flat o snd o reachable (imm_succs G);
  105.27 +fun all_preds G = List.concat o snd o reachable (imm_preds G);
  105.28 +fun all_succs G = List.concat o snd o reachable (imm_succs G);
  105.29  
  105.30  (*strongly connected components; see: David King and John Launchbury,
  105.31    "Structuring Depth First Search Algorithms in Haskell"*)
  105.32  fun strong_conn G = filter_out null (snd (reachable (imm_preds G)
  105.33 -  (flat (rev (snd (reachable (imm_succs G) (keys G)))))));
  105.34 +  (List.concat (rev (snd (reachable (imm_succs G) (keys G)))))));
  105.35  
  105.36  
  105.37  (* paths *)
  105.38 @@ -139,7 +139,7 @@
  105.39      fun paths ps p =
  105.40        if not (null ps) andalso eq_key (p, x) then [p :: ps]
  105.41        else if p mem_keys X andalso not (p mem_key ps)
  105.42 -      then flat (map (paths (p :: ps)) (imm_preds G p))
  105.43 +      then List.concat (map (paths (p :: ps)) (imm_preds G p))
  105.44        else [];
  105.45    in paths [] y end;
  105.46  
  105.47 @@ -155,8 +155,8 @@
  105.48    let
  105.49      fun del (x, (i, (preds, succs))) =
  105.50        if x mem_key xs then NONE
  105.51 -      else SOME (x, (i, (foldl op del_key (preds, xs), foldl op del_key (succs, xs))));
  105.52 -  in Graph (Table.make (mapfilter del (Table.dest tab))) end;
  105.53 +      else SOME (x, (i, (Library.foldl op del_key (preds, xs), Library.foldl op del_key (succs, xs))));
  105.54 +  in Graph (Table.make (List.mapPartial del (Table.dest tab))) end;
  105.55  
  105.56  
  105.57  (* edges *)
  105.58 @@ -176,7 +176,7 @@
  105.59    else G;
  105.60  
  105.61  fun diff_edges G1 G2 =
  105.62 -  flat (dest G1 |> map (fn (x, ys) => ys |> mapfilter (fn y =>
  105.63 +  List.concat (dest G1 |> map (fn (x, ys) => ys |> List.mapPartial (fn y =>
  105.64      if is_edge G2 (x, y) then NONE else SOME (x, y))));
  105.65  
  105.66  fun edges G = diff_edges G empty;
  105.67 @@ -205,7 +205,7 @@
  105.68      | cycles => raise CYCLES (map (cons x) cycles));
  105.69  
  105.70  fun add_deps_acyclic (y, xs) G =
  105.71 -  foldl (fn (H, x) => add_edge_acyclic (x, y) H) (G, xs);
  105.72 +  Library.foldl (fn (H, x) => add_edge_acyclic (x, y) H) (G, xs);
  105.73  
  105.74  fun merge_acyclic eq GG = gen_merge add_edge_acyclic eq GG;
  105.75  
   106.1 --- a/src/Pure/General/history.ML	Thu Mar 03 09:22:35 2005 +0100
   106.2 +++ b/src/Pure/General/history.ML	Thu Mar 03 12:43:01 2005 +0100
   106.3 @@ -35,7 +35,7 @@
   106.4  fun current (History (x, _)) = x;
   106.5  
   106.6  fun clear n (History (x, (lim, len, undo_list, redo_list))) =
   106.7 -  History (x, (lim, Int.max (0, len - n), drop (n, undo_list), redo_list));
   106.8 +  History (x, (lim, Int.max (0, len - n), Library.drop (n, undo_list), redo_list));
   106.9  
  106.10  fun undo (History (_, (_, _, [], _))) = error "No further undo information"
  106.11    | undo (History (x, (lim, len, u :: undo_list, redo_list))) =
  106.12 @@ -47,7 +47,7 @@
  106.13  
  106.14  fun push NONE _ x xs = x :: xs
  106.15    | push (SOME 0) _ _ _ = []
  106.16 -  | push (SOME n) len x xs = if len < n then x :: xs else take (n, x :: xs);
  106.17 +  | push (SOME n) len x xs = if len < n then x :: xs else Library.take (n, x :: xs);
  106.18  
  106.19  fun apply_copy cp f (History (x, (lim, len, undo_list, _))) =
  106.20    let val x' = cp x
   107.1 --- a/src/Pure/General/lazy_seq.ML	Thu Mar 03 09:22:35 2005 +0100
   107.2 +++ b/src/Pure/General/lazy_seq.ML	Thu Mar 03 12:43:01 2005 +0100
   107.3 @@ -83,7 +83,7 @@
   107.4  fun getItem (Seq s) = force s
   107.5  fun make f = Seq (delay f)
   107.6  
   107.7 -fun null s = is_some (getItem s)
   107.8 +fun null s = isSome (getItem s)
   107.9  
  107.10  local
  107.11      fun F n NONE = n
  107.12 @@ -397,8 +397,8 @@
  107.13  	make (fn () => copy (f x))
  107.14      end
  107.15  
  107.16 -fun EVERY fs = foldr THEN (fs, succeed)
  107.17 -fun FIRST fs = foldr ORELSE (fs, fail)
  107.18 +fun EVERY fs = Library.foldr THEN (fs, succeed)
  107.19 +fun FIRST fs = Library.foldr ORELSE (fs, fail)
  107.20  
  107.21  fun TRY f x =
  107.22      make (fn () =>
   108.1 --- a/src/Pure/General/name_space.ML	Thu Mar 03 09:22:35 2005 +0100
   108.2 +++ b/src/Pure/General/name_space.ML	Thu Mar 03 12:43:01 2005 +0100
   108.3 @@ -50,7 +50,7 @@
   108.4  val unpack = space_explode separator;
   108.5  val pack = space_implode separator;
   108.6  
   108.7 -val base = last_elem o unpack;
   108.8 +val base = List.last o unpack;
   108.9  
  108.10  fun map_base f name =
  108.11    let val uname = unpack name
  108.12 @@ -75,7 +75,7 @@
  108.13  (* basic operations *)
  108.14  
  108.15  fun map_space f xname tab =
  108.16 -  Symtab.update ((xname, f (if_none (Symtab.lookup (tab, xname)) ([], []))), tab);
  108.17 +  Symtab.update ((xname, f (getOpt (Symtab.lookup (tab, xname), ([], [])))), tab);
  108.18  
  108.19  fun change f xname (name, tab) =
  108.20    map_space (fn (names, names') => (f names name, names')) xname tab;
  108.21 @@ -100,9 +100,9 @@
  108.22  fun extend_aux (name, tab) =
  108.23    if is_hidden name then
  108.24      error ("Attempt to declare hidden name " ^ quote name)
  108.25 -  else foldl (fn (tb, xname) => change add xname (name, tb)) (tab, accesses name);
  108.26 +  else Library.foldl (fn (tb, xname) => change add xname (name, tb)) (tab, accesses name);
  108.27  
  108.28 -fun extend (NameSpace tab, names) = NameSpace (foldr extend_aux (names, tab));
  108.29 +fun extend (NameSpace tab, names) = NameSpace (Library.foldr extend_aux (names, tab));
  108.30  
  108.31  
  108.32  (* merge *)             (*1st preferred over 2nd*)
  108.33 @@ -123,10 +123,10 @@
  108.34    else if is_hidden name then
  108.35      error ("Attempt to hide hidden name " ^ quote name)
  108.36    else (change' add name (name,
  108.37 -    foldl (fn (tb, xname) => change del xname (name, tb))
  108.38 +    Library.foldl (fn (tb, xname) => change del xname (name, tb))
  108.39        (tab, if fully then accesses name else [base name])));
  108.40  
  108.41 -fun hide fully (NameSpace tab, names) = NameSpace (foldr (hide_aux fully) (names, tab));
  108.42 +fun hide fully (NameSpace tab, names) = NameSpace (Library.foldr (hide_aux fully) (names, tab));
  108.43  
  108.44  
  108.45  (* intern / extern names *)
  108.46 @@ -175,7 +175,7 @@
  108.47  
  108.48  fun dest (NameSpace tab) =
  108.49    map (apsnd (sort (int_ord o pairself size)))
  108.50 -    (Symtab.dest (Symtab.make_multi (mapfilter dest_entry (Symtab.dest tab))));
  108.51 +    (Symtab.dest (Symtab.make_multi (List.mapPartial dest_entry (Symtab.dest tab))));
  108.52  
  108.53  
  108.54  end;
   109.1 --- a/src/Pure/General/path.ML	Thu Mar 03 09:22:35 2005 +0100
   109.2 +++ b/src/Pure/General/path.ML	Thu Mar 03 12:43:01 2005 +0100
   109.3 @@ -90,7 +90,7 @@
   109.4    | rev_app xs (y :: ys) = rev_app (y :: xs) ys;
   109.5  
   109.6  fun append (Path xs) (Path ys) = Path (rev_app (rev xs) ys);
   109.7 -fun appends paths = foldl (uncurry append) (current, paths);
   109.8 +fun appends paths = Library.foldl (uncurry append) (current, paths);
   109.9  val make = appends o map basic;
  109.10  fun norm path = rev_app [] path;
  109.11  
  109.12 @@ -142,7 +142,7 @@
  109.13  val split_ext = split_path (fn (prfx, s) => apfst (append (Path prfx))
  109.14    (case take_suffix (not_equal ".") (explode s) of
  109.15      ([], _) => (Path [Basic s], "")
  109.16 -  | (cs, e) => (Path [Basic (implode (take (length cs - 1, cs)))], implode e)));
  109.17 +  | (cs, e) => (Path [Basic (implode (Library.take (length cs - 1, cs)))], implode e)));
  109.18  
  109.19  
  109.20  (* evaluate variables *)
  109.21 @@ -151,7 +151,7 @@
  109.22    | eval _ x = [x];
  109.23  
  109.24  fun evaluate env (Path xs) =
  109.25 -  Path (norm (flat (map (eval env) xs)));
  109.26 +  Path (norm (List.concat (map (eval env) xs)));
  109.27  
  109.28  val expand = evaluate (unpack o getenv);
  109.29  
   110.1 --- a/src/Pure/General/pretty.ML	Thu Mar 03 09:22:35 2005 +0100
   110.2 +++ b/src/Pure/General/pretty.ML	Thu Mar 03 12:43:01 2005 +0100
   110.3 @@ -204,7 +204,7 @@
   110.4    blk (1, [str "\"", prt, str "\""]);
   110.5  
   110.6  fun commas prts =
   110.7 -  flat (separate [str ",", brk 1] (map (fn x => [x]) prts));
   110.8 +  List.concat (separate [str ",", brk 1] (map (fn x => [x]) prts));
   110.9  
  110.10  fun breaks prts = separate (brk 1) prts;
  110.11  fun fbreaks prts = separate fbrk prts;
   111.1 --- a/src/Pure/General/scan.ML	Thu Mar 03 09:22:35 2005 +0100
   111.2 +++ b/src/Pure/General/scan.ML	Thu Mar 03 12:43:01 2005 +0100
   111.3 @@ -204,7 +204,7 @@
   111.4  
   111.5  fun trace scan toks =
   111.6    let val (x, toks') = scan toks
   111.7 -  in ((x, take (length toks - length toks', toks)), toks') end;
   111.8 +  in ((x, Library.take (length toks - length toks', toks)), toks') end;
   111.9  
  111.10  
  111.11  (* state based scanners *)
  111.12 @@ -247,7 +247,7 @@
  111.13    in
  111.14      if exists is_stopper input then
  111.15        raise ABORT "Stopper may not occur in input o