(* iterative (tail-recursive) version of factorial *) let fact n = let (* if n >= 0, then fct(n, m) returns n factorial * m *) rec fct(n, m) = if n = 0 then m else fct(n - 1, n * m) in if n < 0 then -1 else fct(n, 1) (* try: fact 6;; *)