Skip to content

Instantly share code, notes, and snippets.

@TerrorJack
Created February 20, 2019 10:27
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 TerrorJack/7886031f2da28c427037a38c2701bf52 to your computer and use it in GitHub Desktop.
Save TerrorJack/7886031f2da28c427037a38c2701bf52 to your computer and use it in GitHub Desktop.
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
;;
// 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