0 people like it.

factorial.fsx

Factorial recursive function using match ... with pattern.

1: 
2: 
3: 
4: 
5: 
6: 
let rec factorial n =
    match n with
        | 0 -> 1
        | x -> x * factorial (x-1)

printfn "%d", factorial(5)
val factorial : n:int -> int

Full name: Script.factorial
val n : int
val x : int
val printfn : format:Printf.TextWriterFormat<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
Raw view Test code New version

More information

Link:http://fssnip.net/l1
Posted:11 years ago
Author:gg00xiv
Tags: factorial , pattern , match , with , rec , let , tryfsharp