doc-src/IsarAdvanced/Codegen/Thy/examples/fac_case.ML
author berghofe
Wed, 07 May 2008 10:56:52 +0200
changeset 26803 0af0f674845d
parent 25160 72fcf0832cfe
permissions -rw-r--r--
- Explicitely passed pred_subset_eq and pred_equals_eq as an argument to the to_set and to_pred attributes, because it is no longer applied automatically - Manually applied predicate1I in proof of accp_subset, because it is no longer part of the claset - Replaced psubset_def by less_le

structure Nat = 
struct

datatype nat = Suc of nat | Zero_nat;

val one_nat : nat = Suc Zero_nat;

fun nat_case f1 f2 Zero_nat = f1
  | nat_case f1 f2 (Suc nat) = f2 nat;

fun plus_nat (Suc m) n = plus_nat m (Suc n)
  | plus_nat Zero_nat n = n;

fun times_nat (Suc m) n = plus_nat n (times_nat m n)
  | times_nat Zero_nat n = Zero_nat;

end; (*struct Nat*)

structure Codegen = 
struct

fun fac n =
  (case n of Nat.Zero_nat => Nat.one_nat
     | Nat.Suc m => Nat.times_nat n (fac m));

end; (*struct Codegen*)