Factorial in OCaml
Example for versions
OCaml 3.11
This example uses an auxiliary function so that tail recursion is possible.
let factorial n =
aux n 1;;
let rec aux n accum =
if n = 1 then accum
else aux (n-1) (accum*n);;
Comments
]]>blog comments powered by Disqus
]]>