src/HOL/Library/EfficientNat.thy
changeset 20713 823967ef47f1
parent 20700 7e3450c10c2d
child 20839 ed49d8709959
equal deleted inserted replaced
20712:b3cd1233167f 20713:823967ef47f1
   125 *}
   125 *}
   126 
   126 
   127 types_code
   127 types_code
   128   nat ("int")
   128   nat ("int")
   129 attach (term_of) {*
   129 attach (term_of) {*
   130 fun term_of_nat 0 = Const ("0", HOLogic.natT)
   130 fun term_of_nat 0 = Const ("HOL.zero", HOLogic.natT)
   131   | term_of_nat 1 = Const ("1", HOLogic.natT)
   131   | term_of_nat 1 = Const ("HOL.one", HOLogic.natT)
   132   | term_of_nat i = HOLogic.number_of_const HOLogic.natT $
   132   | term_of_nat i = HOLogic.number_of_const HOLogic.natT $
   133       HOLogic.mk_binum (IntInf.fromInt i);
   133       HOLogic.mk_binum (IntInf.fromInt i);
   134 *}
   134 *}
   135 attach (test) {*
   135 attach (test) {*
   136 fun gen_nat i = random_range 0 i;
   136 fun gen_nat i = random_range 0 i;
   139 code_type nat
   139 code_type nat
   140   (SML target_atom "IntInf.int")
   140   (SML target_atom "IntInf.int")
   141   (Haskell target_atom "Integer")
   141   (Haskell target_atom "Integer")
   142 
   142 
   143 consts_code
   143 consts_code
   144   0 :: nat ("0")
   144   "HOL.zero" :: nat ("0")
   145   Suc ("(_ + 1)")
   145   Suc ("(_ + 1)")
   146 
   146 
   147 text {*
   147 text {*
   148   Since natural numbers are implemented
   148   Since natural numbers are implemented
   149   using integers, the coercion function @{const "int"} of type
   149   using integers, the coercion function @{const "int"} of type