# HG changeset patch # User haftmann # Date 1179767501 -7200 # Node ID d88d2087436dd5942048eaa0dc89f1fe3bbb0b5f # Parent fd89206652ddd834ebb6e368a77293518607a7a4 evaluation for integers diff -r fd89206652dd -r d88d2087436d src/HOL/Library/Eval.thy --- a/src/HOL/Library/Eval.thy Mon May 21 19:11:40 2007 +0200 +++ b/src/HOL/Library/Eval.thy Mon May 21 19:11:41 2007 +0200 @@ -11,8 +11,8 @@ subsection {* @{text typ_of} class *} -class typ_of = type + - fixes typ_of :: "'a itself \ typ" +class typ_of = + fixes typ_of :: "'a\{} itself \ typ" ML {* structure TypOf = @@ -34,6 +34,12 @@ end; *} +instance itself :: (typ_of) typ_of + "typ_of T \ STR ''itself'' {\} [typ_of TYPE('a\typ_of)]" .. + +instance "prop" :: typ_of + "typ_of T \ STR ''prop'' {\} []" .. + instance int :: typ_of "typ_of T \ STR ''IntDef.int'' {\} []" .. @@ -54,7 +60,7 @@ subsection {* @{text term_of} class *} class term_of = typ_of + - constrains typ_of :: "'a itself \ typ" + constrains typ_of :: "'a\{} itself \ typ" fixes term_of :: "'a \ term" ML {* @@ -112,6 +118,26 @@ in DatatypeCodegen.add_codetypes_hook_bootstrap hook end *} +abbreviation + intT :: "typ" +where + "intT \ STR ''IntDef.int'' {\} []" + +function + mk_int :: "int \ term" +where + "mk_int k = (if k = 0 then STR ''Numeral.Pls'' \\ intT + else if k = -1 then STR ''Numeral.Min'' \\ intT + else let (l, m) = divAlg (k, 2) + in STR ''Numeral.Bit'' \\ intT \ intT \ intT \ mk_int l \ + (if m = 0 then STR ''Numeral.bit.B0'' \\ intT else STR ''Numeral.bit.B1'' \\ intT))" +by pat_completeness auto +termination by (relation "measure (nat o abs)") (auto simp add: divAlg_mod_div) + +instance int :: term_of + "term_of k \ STR ''Numeral.number_class.number_of'' \\ intT \ intT \ intT \ mk_int k" .. + + text {* Adaption for @{typ ml_string}s *} lemmas [code func, code func del] = term_of_ml_string_def