Skip to content

Instantly share code, notes, and snippets.

@dbrattli
Created October 14, 2018 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbrattli/702d4b2ffc66f36ac956254c201de67d to your computer and use it in GitHub Desktop.
Save dbrattli/702d4b2ffc66f36ac956254c201de67d to your computer and use it in GitHub Desktop.
Factorial Promise
let rec factorial (n : bigint) : Promise<bigint> =
let pr = Promise<bigint> ()
pr.Resolve n
pr.Then (fun value ->
if value = (bigint 0) then
single (bigint 1)
else
factorial(n - (bigint 1)).Then (fun res -> single (n * res))
)
let pr = factorial (bigint 10000)
pr.Then (fun value ->
printfn "Result = %A" value
) |> ignore
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment