Created
February 20, 2019 10:27
-
-
Save TerrorJack/7886031f2da28c427037a38c2701bf52 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let factorial : int -> int = fun num -> | |
let rec helper : int -> int -> int = fun n acc -> | |
if n > 0 | |
then helper (n-1) (acc * n) | |
else acc | |
in | |
helper num 1 | |
;; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generated by BUCKLESCRIPT VERSION 3.2.0, PLEASE EDIT WITH CARE | |
'use strict'; | |
var Caml_int32 = require("./stdlib/caml_int32.js"); | |
function factorial(num) { | |
var _n = num; | |
var _acc = 1; | |
while(true) { | |
var acc = _acc; | |
var n = _n; | |
if (n > 0) { | |
_acc = Caml_int32.imul(acc, n); | |
_n = n - 1 | 0; | |
continue ; | |
} else { | |
return acc; | |
} | |
}; | |
} | |
exports.factorial = factorial; | |
/* No side effect */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment