src/HOL/Product_Type.thy
changeset 18013 3f5d0acdfdba
parent 17956 369e2af8ee45
child 18220 43cf5767f992
equal deleted inserted replaced
18012:23e6cfda8c4b 18013:3f5d0acdfdba
   785   "Pair"    ("(_,/ _)")
   785   "Pair"    ("(_,/ _)")
   786   "fst"     ("fst")
   786   "fst"     ("fst")
   787   "snd"     ("snd")
   787   "snd"     ("snd")
   788 
   788 
   789 ML {*
   789 ML {*
   790 local
   790 
       
   791 signature PRODUCT_TYPE_CODEGEN =
       
   792 sig
       
   793   val strip_abs: int -> term -> term list * term;
       
   794 end;
       
   795 
       
   796 structure ProductTypeCodegen : PRODUCT_TYPE_CODEGEN =
       
   797 struct
   791 
   798 
   792 fun strip_abs 0 t = ([], t)
   799 fun strip_abs 0 t = ([], t)
   793   | strip_abs i (Abs (s, T, t)) =
   800   | strip_abs i (Abs (s, T, t)) =
   794     let
   801       let
   795       val s' = Codegen.new_name t s;
   802         val s' = Codegen.new_name t s;
   796       val v = Free (s', T)
   803         val v = Free (s', T)
   797     in apfst (cons v) (strip_abs (i-1) (subst_bound (v, t))) end
   804       in apfst (cons v) (strip_abs (i-1) (subst_bound (v, t))) end
   798   | strip_abs i (u as Const ("split", _) $ t) = (case strip_abs (i+1) t of
   805   | strip_abs i (u as Const ("split", _) $ t) = (case strip_abs (i+1) t of
   799         (v :: v' :: vs, u) => (HOLogic.mk_prod (v, v') :: vs, u)
   806         (v :: v' :: vs, u) => (HOLogic.mk_prod (v, v') :: vs, u)
   800       | _ => ([], u))
   807       | _ => ([], u))
   801   | strip_abs i t = ([], t);
   808   | strip_abs i t = ([], t);
       
   809 
       
   810 end;
       
   811 
       
   812 local
       
   813 
       
   814 open ProductTypeCodegen;
   802 
   815 
   803 fun let_codegen thy defs gr dep thyname brack t = (case strip_comb t of
   816 fun let_codegen thy defs gr dep thyname brack t = (case strip_comb t of
   804     (t1 as Const ("Let", _), t2 :: t3 :: ts) =>
   817     (t1 as Const ("Let", _), t2 :: t3 :: ts) =>
   805     let
   818     let
   806       fun dest_let (l as Const ("Let", _) $ t $ u) =
   819       fun dest_let (l as Const ("Let", _) $ t $ u) =