fun factorial (n:int): int = let fun loop(n: int, res: int): int = if n > 0 then loop(n-1, n*res) else res in loop(n, 1) end // end of [factorial]