Skip to content

Factorial

editable example

Click the pencil to open this in an editor, change it, and run it in your browser. The same solution is posted on Rosetta Code.

ghul
use IO.Std.write_line
let factorial = n rec => if n <= 1 then 1L else cast(n) * rec(n - 1) fi
for n in [0, 1, 5, 10, 20] do
write_line("{n}! = {factorial(n)}")
od