src/HOL/Tools/BNF/bnf_gfp_rec_sugar.ML
changeset 55100 697b41533e1a
parent 55061 a0adf838e2d1
child 55339 f09037306f25
equal deleted inserted replaced
55099:79c92e2dc359 55100:697b41533e1a
   874       in
   874       in
   875         chop n disc_eqns ||> cons extra_disc_eqn |> (op @)
   875         chop n disc_eqns ||> cons extra_disc_eqn |> (op @)
   876       end
   876       end
   877   end;
   877   end;
   878 
   878 
   879 fun find_corec_calls ctxt has_call basic_ctr_specs ({ctr, sel, rhs_term, ...} : coeqn_data_sel) =
   879 fun find_corec_calls ctxt has_call (basic_ctr_specs : basic_corec_ctr_spec list)
       
   880     ({ctr, sel, rhs_term, ...} : coeqn_data_sel) =
   880   let
   881   let
   881     val sel_no = find_first (curry (op =) ctr o #ctr) basic_ctr_specs
   882     val sel_no = find_first (curry (op =) ctr o #ctr) basic_ctr_specs
   882       |> find_index (curry (op =) sel) o #sels o the;
   883       |> find_index (curry (op =) sel) o #sels o the;
   883     fun find t = if has_call t then snd (fold_rev_let_if_case ctxt (K cons) [] t []) else [];
   884     fun find t = if has_call t then snd (fold_rev_let_if_case ctxt (K cons) [] t []) else [];
   884   in
   885   in
  1160                 |> pair ctr
  1161                 |> pair ctr
  1161                 |> pair eqn_pos
  1162                 |> pair eqn_pos
  1162                 |> single
  1163                 |> single
  1163             end;
  1164             end;
  1164 
  1165 
  1165         fun prove_code exhaustive disc_eqns sel_eqns nchotomys ctr_alist ctr_specs =
  1166         fun prove_code exhaustive (disc_eqns : coeqn_data_disc list)
       
  1167             (sel_eqns : coeqn_data_sel list) nchotomys ctr_alist ctr_specs =
  1166           let
  1168           let
  1167             val fun_data_opt =
  1169             val fun_data_opt =
  1168               (find_first (member (op =) (map #ctr ctr_specs) o #ctr) disc_eqns,
  1170               (find_first (member (op =) (map #ctr ctr_specs) o #ctr) disc_eqns,
  1169                find_first (member (op =) (map #ctr ctr_specs) o #ctr) sel_eqns)
  1171                find_first (member (op =) (map #ctr ctr_specs) o #ctr) sel_eqns)
  1170               |>> Option.map (fn x => (#fun_name x, #fun_T x, #fun_args x, #code_rhs_opt x))
  1172               |>> Option.map (fn x => (#fun_name x, #fun_T x, #fun_args x, #code_rhs_opt x))
  1188                       val ctr_thms =
  1190                       val ctr_thms =
  1189                         map (the_default FalseE o AList.lookup (op =) ctr_alist o snd) cond_ctrs;
  1191                         map (the_default FalseE o AList.lookup (op =) ctr_alist o snd) cond_ctrs;
  1190                     in SOME (false, rhs, raw_rhs, ctr_thms) end
  1192                     in SOME (false, rhs, raw_rhs, ctr_thms) end
  1191                   | NONE =>
  1193                   | NONE =>
  1192                     let
  1194                     let
  1193                       fun prove_code_ctr {ctr, sels, ...} =
  1195                       fun prove_code_ctr ({ctr, sels, ...} : corec_ctr_spec) =
  1194                         if not (exists (curry (op =) ctr o fst) ctr_alist) then NONE else
  1196                         if not (exists (curry (op =) ctr o fst) ctr_alist) then NONE else
  1195                           let
  1197                           let
  1196                             val prems = find_first (curry (op =) ctr o #ctr) disc_eqns
  1198                             val prems = find_first (curry (op =) ctr o #ctr) disc_eqns
  1197                               |> Option.map #prems |> the_default [];
  1199                               |> Option.map #prems |> the_default [];
  1198                             val t =
  1200                             val t =