src/HOL/Tools/datatype_prop.ML
changeset 7704 9a6783fdb9a5
parent 7015 85be09eb136c
child 8434 5e4bba59bfaa
equal deleted inserted replaced
7703:6b3424e877bd 7704:9a6783fdb9a5
   222 
   222 
   223         val reccombs' = map mk_reccomb (recs ~~ recTs')
   223         val reccombs' = map mk_reccomb (recs ~~ recTs')
   224 
   224 
   225       in (ts @ [HOLogic.mk_Trueprop (HOLogic.mk_eq
   225       in (ts @ [HOLogic.mk_Trueprop (HOLogic.mk_eq
   226         (comb_t $ list_comb (Const (cname, Ts ---> T), frees),
   226         (comb_t $ list_comb (Const (cname, Ts ---> T), frees),
   227          list_comb (f, frees @ (map (uncurry ap) (reccombs' ~~ frees')))))], fs)
   227          list_comb (f, frees @ (map (op $) (reccombs' ~~ frees')))))], fs)
   228       end
   228       end
   229 
   229 
   230   in fst (foldl (fn (x, ((dt, T), comb_t)) =>
   230   in fst (foldl (fn (x, ((dt, T), comb_t)) =>
   231     foldl (make_primrec T comb_t) (x, #3 (snd dt)))
   231     foldl (make_primrec T comb_t) (x, #3 (snd dt)))
   232       (([], rec_fns), descr' ~~ recTs ~~ reccombs))
   232       (([], rec_fns), descr' ~~ recTs ~~ reccombs))
   406           map (fn i => big_size_name ^ "_" ^ string_of_int i)
   406           map (fn i => big_size_name ^ "_" ^ string_of_int i)
   407             (1 upto length (flat (tl descr))));
   407             (1 upto length (flat (tl descr))));
   408     val size_consts = map (fn (s, T) =>
   408     val size_consts = map (fn (s, T) =>
   409       Const (s, T --> HOLogic.natT)) (size_names ~~ recTs);
   409       Const (s, T --> HOLogic.natT)) (size_names ~~ recTs);
   410 
   410 
   411     val plus_t = Const ("op +", [HOLogic.natT, HOLogic.natT] ---> HOLogic.natT);
   411     fun plus (t1, t2) = Const ("op +", [HOLogic.natT, HOLogic.natT] ---> HOLogic.natT) $ t1 $ t2;
   412 
   412 
   413     fun make_size_eqn size_const T (cname, cargs) =
   413     fun make_size_eqn size_const T (cname, cargs) =
   414       let
   414       let
   415         val recs = filter is_rec_type cargs;
   415         val recs = filter is_rec_type cargs;
   416         val Ts = map (typ_of_dtyp descr' sorts) cargs;
   416         val Ts = map (typ_of_dtyp descr' sorts) cargs;
   418         val tnames = make_tnames Ts;
   418         val tnames = make_tnames Ts;
   419         val rec_tnames = map fst (filter (is_rec_type o snd) (tnames ~~ cargs));
   419         val rec_tnames = map fst (filter (is_rec_type o snd) (tnames ~~ cargs));
   420         val ts = map (fn ((r, s), T) => nth_elem (dest_DtRec r, size_consts) $
   420         val ts = map (fn ((r, s), T) => nth_elem (dest_DtRec r, size_consts) $
   421           Free (s, T)) (recs ~~ rec_tnames ~~ recTs);
   421           Free (s, T)) (recs ~~ rec_tnames ~~ recTs);
   422         val t = if ts = [] then HOLogic.zero else
   422         val t = if ts = [] then HOLogic.zero else
   423           foldl1 (app plus_t) (ts @ [HOLogic.mk_nat 1])
   423           foldl1 plus (ts @ [HOLogic.mk_nat 1])
   424       in
   424       in
   425         HOLogic.mk_Trueprop (HOLogic.mk_eq (size_const $
   425         HOLogic.mk_Trueprop (HOLogic.mk_eq (size_const $
   426           list_comb (Const (cname, Ts ---> T), map Free (tnames ~~ Ts)), t))
   426           list_comb (Const (cname, Ts ---> T), map Free (tnames ~~ Ts)), t))
   427       end
   427       end
   428 
   428