src/HOL/Tools/Nitpick/nitpick_mono.ML
changeset 36385 ff5f88702590
parent 35832 1dac16f00cd2
child 37256 0dca1ec52999
--- a/src/HOL/Tools/Nitpick/nitpick_mono.ML	Sat Apr 24 16:17:30 2010 +0200
+++ b/src/HOL/Tools/Nitpick/nitpick_mono.ML	Sat Apr 24 16:33:01 2010 +0200
@@ -54,55 +54,42 @@
 exception MTYPE of string * mtyp list * typ list
 exception MTERM of string * mterm list
 
-(* string -> unit *)
 fun print_g (_ : string) = ()
 (* val print_g = tracing *)
 
-(* var -> string *)
 val string_for_var = signed_string_of_int
-(* string -> var list -> string *)
 fun string_for_vars sep [] = "0\<^bsub>" ^ sep ^ "\<^esub>"
   | string_for_vars sep xs = space_implode sep (map string_for_var xs)
 fun subscript_string_for_vars sep xs =
   if null xs then "" else "\<^bsub>" ^ string_for_vars sep xs ^ "\<^esub>"
 
-(* sign -> string *)
 fun string_for_sign Plus = "+"
   | string_for_sign Minus = "-"
 
-(* sign -> sign -> sign *)
 fun xor sn1 sn2 = if sn1 = sn2 then Plus else Minus
-(* sign -> sign *)
 val negate = xor Minus
 
-(* sign_atom -> string *)
 fun string_for_sign_atom (S sn) = string_for_sign sn
   | string_for_sign_atom (V x) = string_for_var x
 
-(* literal -> string *)
 fun string_for_literal (x, sn) = string_for_var x ^ " = " ^ string_for_sign sn
 
 val bool_M = MType (@{type_name bool}, [])
 val dummy_M = MType (nitpick_prefix ^ "dummy", [])
 
-(* mtyp -> bool *)
 fun is_MRec (MRec _) = true
   | is_MRec _ = false
-(* mtyp -> mtyp * sign_atom * mtyp *)
 fun dest_MFun (MFun z) = z
   | dest_MFun M = raise MTYPE ("Nitpick_Mono.dest_MFun", [M], [])
 
 val no_prec = 100
 
-(* mtyp -> int *)
 fun precedence_of_mtype (MFun _) = 1
   | precedence_of_mtype (MPair _) = 2
   | precedence_of_mtype _ = no_prec
 
-(* mtyp -> string *)
 val string_for_mtype =
   let
-    (* int -> mtyp -> string *)
     fun aux outer_prec M =
       let
         val prec = precedence_of_mtype M
@@ -126,22 +113,17 @@
       end
   in aux 0 end
 
-(* mtyp -> mtyp list *)
 fun flatten_mtype (MPair (M1, M2)) = maps flatten_mtype [M1, M2]
   | flatten_mtype (MType (_, Ms)) = maps flatten_mtype Ms
   | flatten_mtype M = [M]
 
-(* mterm -> bool *)
 fun precedence_of_mterm (MRaw _) = no_prec
   | precedence_of_mterm (MAbs _) = 1
   | precedence_of_mterm (MApp _) = 2
 
-(* Proof.context -> mterm -> string *)
 fun string_for_mterm ctxt =
   let
-    (* mtype -> string *)
     fun mtype_annotation M = "\<^bsup>" ^ string_for_mtype M ^ "\<^esup>"
-    (* int -> mterm -> string *)
     fun aux outer_prec m =
       let
         val prec = precedence_of_mterm m
@@ -158,7 +140,6 @@
       end
   in aux 0 end
 
-(* mterm -> mtyp *)
 fun mtype_of_mterm (MRaw (_, M)) = M
   | mtype_of_mterm (MAbs (_, _, M, a, m)) = MFun (M, a, mtype_of_mterm m)
   | mtype_of_mterm (MApp (m1, _)) =
@@ -166,29 +147,24 @@
       MFun (_, _, M12) => M12
     | M1 => raise MTYPE ("Nitpick_Mono.mtype_of_mterm", [M1], [])
 
-(* mterm -> mterm * mterm list *)
 fun strip_mcomb (MApp (m1, m2)) = strip_mcomb m1 ||> (fn ms => append ms [m2])
   | strip_mcomb m = (m, [])
 
-(* hol_context -> bool -> bool -> typ -> mdata *)
 fun initial_mdata hol_ctxt binarize no_harmless alpha_T =
   ({hol_ctxt = hol_ctxt, binarize = binarize, alpha_T = alpha_T,
     no_harmless = no_harmless, max_fresh = Unsynchronized.ref 0,
     datatype_mcache = Unsynchronized.ref [],
     constr_mcache = Unsynchronized.ref []} : mdata)
 
-(* typ -> typ -> bool *)
 fun could_exist_alpha_subtype alpha_T (T as Type (_, Ts)) =
     T = alpha_T orelse (not (is_fp_iterator_type T) andalso
                         exists (could_exist_alpha_subtype alpha_T) Ts)
   | could_exist_alpha_subtype alpha_T T = (T = alpha_T)
-(* theory -> typ -> typ -> bool *)
 fun could_exist_alpha_sub_mtype _ (alpha_T as TFree _) T =
     could_exist_alpha_subtype alpha_T T
   | could_exist_alpha_sub_mtype thy alpha_T T =
     (T = alpha_T orelse is_datatype thy [(NONE, true)] T)
 
-(* mtyp -> bool *)
 fun exists_alpha_sub_mtype MAlpha = true
   | exists_alpha_sub_mtype (MFun (M1, _, M2)) =
     exists exists_alpha_sub_mtype [M1, M2]
@@ -197,7 +173,6 @@
   | exists_alpha_sub_mtype (MType (_, Ms)) = exists exists_alpha_sub_mtype Ms
   | exists_alpha_sub_mtype (MRec _) = true
 
-(* mtyp -> bool *)
 fun exists_alpha_sub_mtype_fresh MAlpha = true
   | exists_alpha_sub_mtype_fresh (MFun (_, V _, _)) = true
   | exists_alpha_sub_mtype_fresh (MFun (_, _, M2)) =
@@ -208,11 +183,9 @@
     exists exists_alpha_sub_mtype_fresh Ms
   | exists_alpha_sub_mtype_fresh (MRec _) = true
 
-(* string * typ list -> mtyp list -> mtyp *)
 fun constr_mtype_for_binders z Ms =
   fold_rev (fn M => curry3 MFun M (S Minus)) Ms (MRec z)
 
-(* ((string * typ list) * mtyp) list -> mtyp list -> mtyp -> mtyp *)
 fun repair_mtype _ _ MAlpha = MAlpha
   | repair_mtype cache seen (MFun (M1, a, M2)) =
     MFun (repair_mtype cache seen M1, a, repair_mtype cache seen M2)
@@ -226,30 +199,24 @@
     | M => if member (op =) seen M then MType (s, [])
            else repair_mtype cache (M :: seen) M
 
-(* ((string * typ list) * mtyp) list Unsynchronized.ref -> unit *)
 fun repair_datatype_mcache cache =
   let
-    (* (string * typ list) * mtyp -> unit *)
     fun repair_one (z, M) =
       Unsynchronized.change cache
           (AList.update (op =) (z, repair_mtype (!cache) [] M))
   in List.app repair_one (rev (!cache)) end
 
-(* (typ * mtyp) list -> (styp * mtyp) list Unsynchronized.ref -> unit *)
 fun repair_constr_mcache dtype_cache constr_mcache =
   let
-    (* styp * mtyp -> unit *)
     fun repair_one (x, M) =
       Unsynchronized.change constr_mcache
           (AList.update (op =) (x, repair_mtype dtype_cache [] M))
   in List.app repair_one (!constr_mcache) end
 
-(* typ -> bool *)
 fun is_fin_fun_supported_type @{typ prop} = true
   | is_fin_fun_supported_type @{typ bool} = true
   | is_fin_fun_supported_type (Type (@{type_name option}, _)) = true
   | is_fin_fun_supported_type _ = false
-(* typ -> typ -> term -> term option *)
 fun fin_fun_body _ _ (t as @{term False}) = SOME t
   | fin_fun_body _ _ (t as Const (@{const_name None}, _)) = SOME t
   | fin_fun_body dom_T ran_T
@@ -265,7 +232,6 @@
                 $ (Const (@{const_name unknown}, ran_T)) $ (t0 $ t1 $ t2 $ t3)))
   | fin_fun_body _ _ _ = NONE
 
-(* mdata -> bool -> typ -> typ -> mtyp * sign_atom * mtyp *)
 fun fresh_mfun_for_fun_type (mdata as {max_fresh, ...} : mdata) all_minus
                             T1 T2 =
   let
@@ -277,12 +243,10 @@
             else
               S Minus
   in (M1, a, M2) end
-(* mdata -> bool -> typ -> mtyp *)
 and fresh_mtype_for_type (mdata as {hol_ctxt as {thy, ...}, binarize, alpha_T,
                                     datatype_mcache, constr_mcache, ...})
                          all_minus =
   let
-    (* typ -> mtyp *)
     fun do_type T =
       if T = alpha_T then
         MAlpha
@@ -329,21 +293,17 @@
       | _ => MType (Refute.string_of_typ T, [])
   in do_type end
 
-(* mtyp -> mtyp list *)
 fun prodM_factors (MPair (M1, M2)) = maps prodM_factors [M1, M2]
   | prodM_factors M = [M]
-(* mtyp -> mtyp list * mtyp *)
 fun curried_strip_mtype (MFun (M1, _, M2)) =
     curried_strip_mtype M2 |>> append (prodM_factors M1)
   | curried_strip_mtype M = ([], M)
-(* string -> mtyp -> mtyp *)
 fun sel_mtype_from_constr_mtype s M =
   let val (arg_Ms, dataM) = curried_strip_mtype M in
     MFun (dataM, S Minus,
           case sel_no_from_name s of ~1 => bool_M | n => nth arg_Ms n)
   end
 
-(* mdata -> styp -> mtyp *)
 fun mtype_for_constr (mdata as {hol_ctxt = {thy, ...}, alpha_T, constr_mcache,
                                 ...}) (x as (_, T)) =
   if could_exist_alpha_sub_mtype thy alpha_T T then
@@ -362,14 +322,11 @@
   x |> binarized_and_boxed_constr_for_sel hol_ctxt binarize
     |> mtype_for_constr mdata |> sel_mtype_from_constr_mtype s
 
-(* literal list -> sign_atom -> sign_atom *)
 fun resolve_sign_atom lits (V x) =
     x |> AList.lookup (op =) lits |> Option.map S |> the_default (V x)
   | resolve_sign_atom _ a = a
-(* literal list -> mtyp -> mtyp *)
 fun resolve_mtype lits =
   let
-    (* mtyp -> mtyp *)
     fun aux MAlpha = MAlpha
       | aux (MFun (M1, a, M2)) = MFun (aux M1, resolve_sign_atom lits a, aux M2)
       | aux (MPair Mp) = MPair (pairself aux Mp)
@@ -384,24 +341,19 @@
 
 type constraint_set = literal list * comp list * sign_expr list
 
-(* comp_op -> string *)
 fun string_for_comp_op Eq = "="
   | string_for_comp_op Leq = "\<le>"
 
-(* sign_expr -> string *)
 fun string_for_sign_expr [] = "\<bot>"
   | string_for_sign_expr lits =
     space_implode " \<or> " (map string_for_literal lits)
 
-(* literal -> literal list option -> literal list option *)
 fun do_literal _ NONE = NONE
   | do_literal (x, sn) (SOME lits) =
     case AList.lookup (op =) lits x of
       SOME sn' => if sn = sn' then SOME lits else NONE
     | NONE => SOME ((x, sn) :: lits)
 
-(* comp_op -> var list -> sign_atom -> sign_atom -> literal list * comp list
-   -> (literal list * comp list) option *)
 fun do_sign_atom_comp Eq [] a1 a2 (accum as (lits, comps)) =
     (case (a1, a2) of
        (S sn1, S sn2) => if sn1 = sn2 then SOME accum else NONE
@@ -419,8 +371,6 @@
   | do_sign_atom_comp cmp xs a1 a2 (lits, comps) =
     SOME (lits, insert (op =) (a1, a2, cmp, xs) comps)
 
-(* comp -> var list -> mtyp -> mtyp -> (literal list * comp list) option
-   -> (literal list * comp list) option *)
 fun do_mtype_comp _ _ _ _ NONE = NONE
   | do_mtype_comp _ _ MAlpha MAlpha accum = accum
   | do_mtype_comp Eq xs (MFun (M11, a1, M12)) (MFun (M21, a2, M22))
@@ -450,7 +400,6 @@
     raise MTYPE ("Nitpick_Mono.do_mtype_comp (" ^ string_for_comp_op cmp ^ ")",
                  [M1, M2], [])
 
-(* comp_op -> mtyp -> mtyp -> constraint_set -> constraint_set *)
 fun add_mtype_comp cmp M1 M2 ((lits, comps, sexps) : constraint_set) =
     (print_g ("*** Add " ^ string_for_mtype M1 ^ " " ^ string_for_comp_op cmp ^
               " " ^ string_for_mtype M2);
@@ -458,12 +407,9 @@
        NONE => (print_g "**** Unsolvable"; raise UNSOLVABLE ())
      | SOME (lits, comps) => (lits, comps, sexps))
 
-(* mtyp -> mtyp -> constraint_set -> constraint_set *)
 val add_mtypes_equal = add_mtype_comp Eq
 val add_is_sub_mtype = add_mtype_comp Leq
 
-(* sign -> sign_expr -> mtyp -> (literal list * sign_expr list) option
-   -> (literal list * sign_expr list) option *)
 fun do_notin_mtype_fv _ _ _ NONE = NONE
   | do_notin_mtype_fv Minus _ MAlpha accum = accum
   | do_notin_mtype_fv Plus [] MAlpha _ = NONE
@@ -499,7 +445,6 @@
   | do_notin_mtype_fv _ _ M _ =
     raise MTYPE ("Nitpick_Mono.do_notin_mtype_fv", [M], [])
 
-(* sign -> mtyp -> constraint_set -> constraint_set *)
 fun add_notin_mtype_fv sn M ((lits, comps, sexps) : constraint_set) =
     (print_g ("*** Add " ^ string_for_mtype M ^ " is " ^
               (case sn of Minus => "concrete" | Plus => "complete") ^ ".");
@@ -507,31 +452,23 @@
        NONE => (print_g "**** Unsolvable"; raise UNSOLVABLE ())
      | SOME (lits, sexps) => (lits, comps, sexps))
 
-(* mtyp -> constraint_set -> constraint_set *)
 val add_mtype_is_concrete = add_notin_mtype_fv Minus
 val add_mtype_is_complete = add_notin_mtype_fv Plus
 
 val bool_from_minus = true
 
-(* sign -> bool *)
 fun bool_from_sign Plus = not bool_from_minus
   | bool_from_sign Minus = bool_from_minus
-(* bool -> sign *)
 fun sign_from_bool b = if b = bool_from_minus then Minus else Plus
 
-(* literal -> PropLogic.prop_formula *)
 fun prop_for_literal (x, sn) =
   (not (bool_from_sign sn) ? PropLogic.Not) (PropLogic.BoolVar x)
-(* sign_atom -> PropLogic.prop_formula *)
 fun prop_for_sign_atom_eq (S sn', sn) =
     if sn = sn' then PropLogic.True else PropLogic.False
   | prop_for_sign_atom_eq (V x, sn) = prop_for_literal (x, sn)
-(* sign_expr -> PropLogic.prop_formula *)
 fun prop_for_sign_expr xs = PropLogic.exists (map prop_for_literal xs)
-(* var list -> sign -> PropLogic.prop_formula *)
 fun prop_for_exists_eq xs sn =
   PropLogic.exists (map (fn x => prop_for_literal (x, sn)) xs)
-(* comp -> PropLogic.prop_formula *)
 fun prop_for_comp (a1, a2, Eq, []) =
     PropLogic.SAnd (prop_for_comp (a1, a2, Leq, []),
                     prop_for_comp (a2, a1, Leq, []))
@@ -541,7 +478,6 @@
   | prop_for_comp (a1, a2, cmp, xs) =
     PropLogic.SOr (prop_for_exists_eq xs Minus, prop_for_comp (a1, a2, cmp, []))
 
-(* var -> (int -> bool option) -> literal list -> literal list *)
 fun literals_from_assignments max_var assigns lits =
   fold (fn x => fn accum =>
            if AList.defined (op =) lits x then
@@ -550,18 +486,15 @@
              SOME b => (x, sign_from_bool b) :: accum
            | NONE => accum) (max_var downto 1) lits
 
-(* comp -> string *)
 fun string_for_comp (a1, a2, cmp, xs) =
   string_for_sign_atom a1 ^ " " ^ string_for_comp_op cmp ^
   subscript_string_for_vars " \<and> " xs ^ " " ^ string_for_sign_atom a2
 
-(* literal list -> comp list -> sign_expr list -> unit *)
 fun print_problem lits comps sexps =
   print_g ("*** Problem:\n" ^ cat_lines (map string_for_literal lits @
                                          map string_for_comp comps @
                                          map string_for_sign_expr sexps))
 
-(* literal list -> unit *)
 fun print_solution lits =
   let val (pos, neg) = List.partition (curry (op =) Plus o snd) lits in
     print_g ("*** Solution:\n" ^
@@ -569,10 +502,8 @@
              "-: " ^ commas (map (string_for_var o fst) neg))
   end
 
-(* var -> constraint_set -> literal list option *)
 fun solve max_var (lits, comps, sexps) =
     let
-      (* (int -> bool option) -> literal list option *)
       fun do_assigns assigns =
         SOME (literals_from_assignments max_var assigns lits
               |> tap print_solution)
@@ -607,27 +538,21 @@
 
 val initial_gamma = {bound_Ts = [], bound_Ms = [], frees = [], consts = []}
 
-(* typ -> mtyp -> mtype_context -> mtype_context *)
 fun push_bound T M {bound_Ts, bound_Ms, frees, consts} =
   {bound_Ts = T :: bound_Ts, bound_Ms = M :: bound_Ms, frees = frees,
    consts = consts}
-(* mtype_context -> mtype_context *)
 fun pop_bound {bound_Ts, bound_Ms, frees, consts} =
   {bound_Ts = tl bound_Ts, bound_Ms = tl bound_Ms, frees = frees,
    consts = consts}
   handle List.Empty => initial_gamma (* FIXME: needed? *)
 
-(* mdata -> term -> accumulator -> mterm * accumulator *)
 fun consider_term (mdata as {hol_ctxt as {thy, ctxt, stds, fast_descrs,
                                           def_table, ...},
                              alpha_T, max_fresh, ...}) =
   let
-    (* typ -> mtyp *)
     val mtype_for = fresh_mtype_for_type mdata false
-    (* mtyp -> mtyp *)
     fun plus_set_mtype_for_dom M =
       MFun (M, S (if exists_alpha_sub_mtype M then Plus else Minus), bool_M)
-    (* typ -> accumulator -> mterm * accumulator *)
     fun do_all T (gamma, cset) =
       let
         val abs_M = mtype_for (domain_type (domain_type T))
@@ -656,7 +581,6 @@
       let
         val set_T = domain_type T
         val set_M = mtype_for set_T
-        (* typ -> mtyp *)
         fun custom_mtype_for (T as Type (@{type_name fun}, [T1, T2])) =
             if T = set_T then set_M
             else MFun (custom_mtype_for T1, S Minus, custom_mtype_for T2)
@@ -664,20 +588,16 @@
       in
         (custom_mtype_for T, (gamma, cset |> add_mtype_is_concrete set_M))
       end
-    (* typ -> accumulator -> mtyp * accumulator *)
     fun do_pair_constr T accum =
       case mtype_for (nth_range_type 2 T) of
         M as MPair (a_M, b_M) =>
         (MFun (a_M, S Minus, MFun (b_M, S Minus, M)), accum)
       | M => raise MTYPE ("Nitpick_Mono.consider_term.do_pair_constr", [M], [])
-    (* int -> typ -> accumulator -> mtyp * accumulator *)
     fun do_nth_pair_sel n T =
       case mtype_for (domain_type T) of
         M as MPair (a_M, b_M) =>
         pair (MFun (M, S Minus, if n = 0 then a_M else b_M))
       | M => raise MTYPE ("Nitpick_Mono.consider_term.do_nth_pair_sel", [M], [])
-    (* term -> string -> typ -> term -> term -> term -> accumulator
-       -> mterm * accumulator *)
     fun do_bounded_quantifier t0 abs_s abs_T connective_t bound_t body_t accum =
       let
         val abs_M = mtype_for abs_T
@@ -697,7 +617,6 @@
                                  MApp (bound_m, MRaw (Bound 0, M1))),
                            body_m))), accum)
       end
-    (* term -> accumulator -> mterm * accumulator *)
     and do_term t (accum as (gamma as {bound_Ts, bound_Ms, frees, consts},
                              cset)) =
         (case t of
@@ -747,7 +666,6 @@
               | @{const_name converse} =>
                 let
                   val x = Unsynchronized.inc max_fresh
-                  (* typ -> mtyp *)
                   fun mtype_for_set T =
                     MFun (mtype_for (domain_type T), V x, bool_M)
                   val ab_set_M = domain_type T |> mtype_for_set
@@ -757,7 +675,6 @@
               | @{const_name rel_comp} =>
                 let
                   val x = Unsynchronized.inc max_fresh
-                  (* typ -> mtyp *)
                   fun mtype_for_set T =
                     MFun (mtype_for (domain_type T), V x, bool_M)
                   val bc_set_M = domain_type T |> mtype_for_set
@@ -783,7 +700,6 @@
               | @{const_name Sigma} =>
                 let
                   val x = Unsynchronized.inc max_fresh
-                  (* typ -> mtyp *)
                   fun mtype_for_set T =
                     MFun (mtype_for (domain_type T), V x, bool_M)
                   val a_set_T = domain_type T
@@ -891,14 +807,12 @@
                                       string_for_mterm ctxt m))
   in do_term end
 
-(* int -> mtyp -> accumulator -> accumulator *)
 fun force_minus_funs 0 _ = I
   | force_minus_funs n (M as MFun (M1, _, M2)) =
     add_mtypes_equal M (MFun (M1, S Minus, M2))
     #> force_minus_funs (n - 1) M2
   | force_minus_funs _ M =
     raise MTYPE ("Nitpick_Mono.force_minus_funs", [M], [])
-(* mdata -> bool -> styp -> term -> term -> mterm * accumulator *)
 fun consider_general_equals mdata def (x as (_, T)) t1 t2 accum =
   let
     val (m1, accum) = consider_term mdata t1 accum
@@ -918,17 +832,12 @@
           accum)
   end
 
-(* mdata -> sign -> term -> accumulator -> mterm * accumulator *)
 fun consider_general_formula (mdata as {hol_ctxt = {ctxt, ...}, ...}) =
   let
-    (* typ -> mtyp *)
     val mtype_for = fresh_mtype_for_type mdata false
-    (* term -> accumulator -> mterm * accumulator *)
     val do_term = consider_term mdata
-    (* sign -> term -> accumulator -> mterm * accumulator *)
     fun do_formula sn t accum =
         let
-          (* styp -> string -> typ -> term -> mterm * accumulator *)
           fun do_quantifier (quant_x as (quant_s, _)) abs_s abs_T body_t =
             let
               val abs_M = mtype_for abs_T
@@ -944,7 +853,6 @@
                      MAbs (abs_s, abs_T, abs_M, S Minus, body_m)),
                accum |>> pop_bound)
             end
-          (* styp -> term -> term -> mterm * accumulator *)
           fun do_equals x t1 t2 =
             case sn of
               Plus => do_term t accum
@@ -1005,7 +913,6 @@
   [@{const_name ord_class.less}, @{const_name ord_class.less_eq}]
 val bounteous_consts = [@{const_name bisim}]
 
-(* mdata -> term -> bool *)
 fun is_harmless_axiom ({no_harmless = true, ...} : mdata) _ = false
   | is_harmless_axiom {hol_ctxt = {thy, stds, fast_descrs, ...}, ...} t =
     Term.add_consts t []
@@ -1013,12 +920,10 @@
     |> (forall (member (op =) harmless_consts o original_name o fst) orf
         exists (member (op =) bounteous_consts o fst))
 
-(* mdata -> term -> accumulator -> mterm * accumulator *)
 fun consider_nondefinitional_axiom mdata t =
   if is_harmless_axiom mdata t then pair (MRaw (t, dummy_M))
   else consider_general_formula mdata Plus t
 
-(* mdata -> term -> accumulator -> mterm * accumulator *)
 fun consider_definitional_axiom (mdata as {hol_ctxt = {thy, ...}, ...}) t =
   if not (is_constr_pattern_formula thy t) then
     consider_nondefinitional_axiom mdata t
@@ -1026,11 +931,8 @@
     pair (MRaw (t, dummy_M))
   else
     let
-      (* typ -> mtyp *)
       val mtype_for = fresh_mtype_for_type mdata false
-      (* term -> accumulator -> mterm * accumulator *)
       val do_term = consider_term mdata
-      (* term -> string -> typ -> term -> accumulator -> mterm * accumulator *)
       fun do_all quant_t abs_s abs_T body_t accum =
         let
           val abs_M = mtype_for abs_T
@@ -1043,7 +945,6 @@
                  MAbs (abs_s, abs_T, abs_M, S Minus, body_m)),
            accum |>> pop_bound)
         end
-      (* term -> term -> term -> accumulator -> mterm * accumulator *)
       and do_conjunction t0 t1 t2 accum =
         let
           val (m1, accum) = do_formula t1 accum
@@ -1058,7 +959,6 @@
         in
           (MApp (MApp (MRaw (t0, mtype_for (fastype_of t0)), m1), m2), accum)
         end
-      (* term -> accumulator -> accumulator *)
       and do_formula t accum =
           case t of
             (t0 as Const (@{const_name all}, _)) $ Abs (s1, T1, t1) =>
@@ -1083,22 +983,17 @@
                              \do_formula", [t])
     in do_formula t end
 
-(* Proof.context -> literal list -> term -> mtyp -> string *)
 fun string_for_mtype_of_term ctxt lits t M =
   Syntax.string_of_term ctxt t ^ " : " ^ string_for_mtype (resolve_mtype lits M)
 
-(* theory -> literal list -> mtype_context -> unit *)
 fun print_mtype_context ctxt lits ({frees, consts, ...} : mtype_context) =
   map (fn (x, M) => string_for_mtype_of_term ctxt lits (Free x) M) frees @
   map (fn (x, M) => string_for_mtype_of_term ctxt lits (Const x) M) consts
   |> cat_lines |> print_g
 
-(* ('a -> 'b -> 'c * 'd) -> 'a -> 'c list * 'b -> 'c list * 'd *)
 fun amass f t (ms, accum) =
   let val (m, accum) = f t accum in (m :: ms, accum) end
 
-(* string -> bool -> hol_context -> bool -> typ -> term list * term list
-   -> (literal list * (mterm list * mterm list) * (styp * mtyp) list) option *)
 fun infer which no_harmless (hol_ctxt as {ctxt, ...}) binarize alpha_T
           (nondef_ts, def_ts) =
   let
@@ -1127,15 +1022,11 @@
        | MTERM (loc, ms) =>
          raise BAD (loc, commas (map (string_for_mterm ctxt) ms))
 
-(* hol_context -> bool -> typ -> term list * term list -> bool *)
 val formulas_monotonic = is_some oooo infer "Monotonicity" false
 
-(* typ -> typ -> styp *)
 fun fin_fun_constr T1 T2 =
   (@{const_name FinFun}, (T1 --> T2) --> Type (@{type_name fin_fun}, [T1, T2]))
 
-(* hol_context -> bool -> (typ option * bool option) list -> typ
-   -> term list * term list -> term list * term list *)
 fun finitize_funs (hol_ctxt as {thy, stds, fast_descrs, constr_cache, ...})
                   binarize finitizes alpha_T tsp =
   case infer "Finiteness" true hol_ctxt binarize alpha_T tsp of
@@ -1144,12 +1035,10 @@
       tsp
     else
       let
-        (* typ -> sign_atom -> bool *)
         fun should_finitize T a =
           case triple_lookup (type_match thy) finitizes T of
             SOME (SOME false) => false
           | _ => resolve_sign_atom lits a = S Plus
-        (* typ -> mtyp -> typ *)
         fun type_from_mtype T M =
           case (M, T) of
             (MAlpha, _) => T
@@ -1161,12 +1050,10 @@
           | (MType _, _) => T
           | _ => raise MTYPE ("Nitpick_Mono.finitize_funs.type_from_mtype",
                               [M], [T])
-        (* styp -> styp *)
         fun finitize_constr (x as (s, T)) =
           (s, case AList.lookup (op =) constr_mtypes x of
                 SOME M => type_from_mtype T M
               | NONE => T)
-        (* typ list -> mterm -> term *)
         fun term_from_mterm Ts m =
           case m of
             MRaw (t, M) =>