Require Import Base.

Definition fact n :=
  let iter := (fix iter store n :=
    println ("recursive call: n=" ++ string_of_nat n);
    match n with
    | 0 => store
    | S p => iter (n * store) p
    end)
  in
  iter 1 n.

Definition main := println ("answer="++ string_of_nat (fact 5)).

Extraction "fact.ml" main.
