theory TermCodegen = Main files "term_codegen.ML": setup TermCodegen.setup global constdefs "term" :: "'a \ 'a" "term x == x" "to_term" :: "'a \ 'a" "to_term x == x" (* local consts foo :: "nat \ (nat \ nat \ bool) \ nat \ bool" primrec "foo 0 P = term (\y. True)" "foo (Suc x) P = term (\y. to_term (P x) y \ to_term (foo x P) y)" generate_code ("foo.ML") [term_of] test = "foo (Suc (Suc (Suc 0))) (\x. term (\y. to_term x = Suc y))" datatype foo = C nat consts bar :: "foo \ nat \ bool" primrec "bar (C n) = term (\n'. n' = to_term n)" generate_code ("bar.ML") [term_of] test = "bar (C (Suc (Suc 0)))" *) end