Skip to content

Instantly share code, notes, and snippets.

@ztmr
Created March 12, 2014 20:24
Show Gist options
  • Save ztmr/9515539 to your computer and use it in GitHub Desktop.
Save ztmr/9515539 to your computer and use it in GitHub Desktop.
F# command line arguments parsing, factorial, lambdas, and pipe operator fun
// Build:
// $ fsharpc ztmr.fs
// Use:
// $ mono ztmr.exe 5
open System
let rec factorial n =
match n with
| 0 -> 1
| _ -> n * factorial (n - 1);
[<EntryPoint>]
let main(args : string[]) =
if args.Length <> 1 then
failwith "Usage: ztmr.exe <number>"
let n = int args.[0]
n
|> factorial
|> (fun i -> (n+1 |> factorial)/i)
|> printfn "%d = (%d+1)!/%d! = %d" (n+1) n n
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment