src/HOL/Tools/Nitpick/nitpick_mono.ML
changeset 40987 7d52af07bff1
parent 40986 cfd91aa80701
child 40988 f7af68bfa66d
equal deleted inserted replaced
40986:cfd91aa80701 40987:7d52af07bff1
   551 
   551 
   552 type mtype_schema = mtyp * constraint_set
   552 type mtype_schema = mtyp * constraint_set
   553 type mtype_context =
   553 type mtype_context =
   554   {bound_Ts: typ list,
   554   {bound_Ts: typ list,
   555    bound_Ms: mtyp list,
   555    bound_Ms: mtyp list,
       
   556    bound_frame: (int * annotation_atom) list,
   556    frees: (styp * mtyp) list,
   557    frees: (styp * mtyp) list,
   557    consts: (styp * mtyp) list}
   558    consts: (styp * mtyp) list}
   558 
   559 
   559 type accumulator = mtype_context * constraint_set
   560 type accumulator = mtype_context * constraint_set
   560 
   561 
   561 val initial_gamma = {bound_Ts = [], bound_Ms = [], frees = [], consts = []}
   562 val initial_gamma =
   562 
   563   {bound_Ts = [], bound_Ms = [], bound_frame = [], frees = [], consts = []}
   563 fun push_bound T M {bound_Ts, bound_Ms, frees, consts} =
   564 
   564   {bound_Ts = T :: bound_Ts, bound_Ms = M :: bound_Ms, frees = frees,
   565 fun push_bound T M {bound_Ts, bound_Ms, bound_frame, frees, consts} =
   565    consts = consts}
   566   {bound_Ts = T :: bound_Ts, bound_Ms = M :: bound_Ms,
   566 fun pop_bound {bound_Ts, bound_Ms, frees, consts} =
   567    bound_frame = bound_frame, frees = frees, consts = consts}
   567   {bound_Ts = tl bound_Ts, bound_Ms = tl bound_Ms, frees = frees,
   568 fun pop_bound {bound_Ts, bound_Ms, bound_frame, frees, consts} =
   568    consts = consts}
   569   {bound_Ts = tl bound_Ts, bound_Ms = tl bound_Ms, bound_frame = bound_frame,
       
   570    frees = frees, consts = consts}
   569   handle List.Empty => initial_gamma (* FIXME: needed? *)
   571   handle List.Empty => initial_gamma (* FIXME: needed? *)
   570 
   572 
   571 fun consider_term (mdata as {hol_ctxt = {thy, ctxt, stds, ...}, alpha_T,
   573 fun consider_term (mdata as {hol_ctxt = {thy, ctxt, stds, ...}, alpha_T,
   572                              max_fresh, ...}) =
   574                              max_fresh, ...}) =
   573   let
   575   let
   641                      MApp (MApp (MRaw (connective_t,
   643                      MApp (MApp (MRaw (connective_t,
   642                                        mtype_for (fastype_of connective_t)),
   644                                        mtype_for (fastype_of connective_t)),
   643                                  MApp (bound_m, MRaw (Bound 0, M1))),
   645                                  MApp (bound_m, MRaw (Bound 0, M1))),
   644                            body_m))), accum)
   646                            body_m))), accum)
   645       end
   647       end
   646     and do_term t (accum as ({bound_Ts, bound_Ms, frees, consts}, cset)) =
   648     and do_term t (accum as ({bound_Ts, bound_Ms, bound_frame, frees, consts},
       
   649                              cset)) =
   647         (trace_msg (fn () => "  \<Gamma> \<turnstile> " ^
   650         (trace_msg (fn () => "  \<Gamma> \<turnstile> " ^
   648                              Syntax.string_of_term ctxt t ^ " : _?");
   651                              Syntax.string_of_term ctxt t ^ " : _?");
   649          case t of
   652          case t of
   650            Const (x as (s, T)) =>
   653            Const (x as (s, T)) =>
   651            (case AList.lookup (op =) consts x of
   654            (case AList.lookup (op =) consts x of
   745                 else if is_built_in_const thy stds x then
   748                 else if is_built_in_const thy stds x then
   746                   (fresh_mtype_for_type mdata true T, accum)
   749                   (fresh_mtype_for_type mdata true T, accum)
   747                 else
   750                 else
   748                   let val M = mtype_for T in
   751                   let val M = mtype_for T in
   749                     (M, ({bound_Ts = bound_Ts, bound_Ms = bound_Ms,
   752                     (M, ({bound_Ts = bound_Ts, bound_Ms = bound_Ms,
   750                           frees = frees, consts = (x, M) :: consts}, cset))
   753                           bound_frame = bound_frame, frees = frees,
       
   754                           consts = (x, M) :: consts}, cset))
   751                   end) |>> curry MRaw t
   755                   end) |>> curry MRaw t
   752          | Free (x as (_, T)) =>
   756          | Free (x as (_, T)) =>
   753            (case AList.lookup (op =) frees x of
   757            (case AList.lookup (op =) frees x of
   754               SOME M => (M, accum)
   758               SOME M => (M, accum)
   755             | NONE =>
   759             | NONE =>
   756               let val M = mtype_for T in
   760               let val M = mtype_for T in
   757                 (M, ({bound_Ts = bound_Ts, bound_Ms = bound_Ms,
   761                 (M, ({bound_Ts = bound_Ts, bound_Ms = bound_Ms,
   758                       frees = (x, M) :: frees, consts = consts}, cset))
   762                       bound_frame = bound_frame, frees = (x, M) :: frees,
       
   763                       consts = consts}, cset))
   759               end) |>> curry MRaw t
   764               end) |>> curry MRaw t
   760          | Var _ => (trace_msg (K "*** Var"); raise UNSOLVABLE ())
   765          | Var _ => (trace_msg (K "*** Var"); raise UNSOLVABLE ())
   761          | Bound j => (MRaw (t, nth bound_Ms j), accum)
   766          | Bound j => (MRaw (t, nth bound_Ms j), accum)
   762          | Abs (s, T, t') =>
   767          | Abs (s, T, t') =>
   763            (case fin_fun_body T (fastype_of1 (T :: bound_Ts, t')) t' of
   768            (case fin_fun_body T (fastype_of1 (T :: bound_Ts, t')) t' of