26 people like it.

Factorial

Calculates the factorial for positive integers

1: 
2: 
3: 
4: 
5: 
6: 
7: 
// calculates the factorial:
// n! = 1 * 2 * 3 * ... * n
// the factorial only exists for positive integers
let rec factorial n =
    match n with
    | 0 | 1 -> 1
    | _ -> n * factorial (n - 1)
val factorial : n:int -> int

Full name: Script.factorial
val n : int
Raw view Test code New version

More information

Link:http://fssnip.net/R
Posted:14 years ago
Author:Stefan Knoblauch
Tags: fac , factorial