[ create a new paste ] login | about

Link: http://codepad.org/i8vprhP5    [ raw code | output | fork ]

OCaml, pasted on Jan 17:
let rec fact1 n =
  match n with
    0 -> 1
  | n -> n * fact1 (n - 1);;

print_int (fact1 5);;

print_string "\n";;

let rec fact2 n = 
  if n < 2 then 1 
           else n * fact2 (n - 1);;

print_int (fact2 5);;

print_string "\n";;

let rec fact3 = function
  | 0 -> 1 
  | x -> x*fact3 (x-1);; 

print_int (fact3 5);;


Output:
1
2
3
120
120
120


Create a new paste based on this one


Comments: