fix: add tail recursion

This commit is contained in:
NunoSempere 2023-10-15 01:14:41 +01:00
parent 7ce4658d30
commit 25a27f7fc4
5 changed files with 11 additions and 1 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -34,7 +34,16 @@ let findIndex xs test =
in
recursiveHelper xs 0
let rec unwind xs =
let unwind xs =
let rec tailRecursiveHelper ys acc =
match ys with
| [] -> Ok(acc)
| Error e :: _ -> Error e
| Ok(y) :: ys -> tailRecursiveHelper ys (y :: acc)
in
tailRecursiveHelper xs []
(* previous version, which wasn't tail-recursive
match xs with
| [] -> Ok([])
| Error e:: ys -> Error e
@ -43,6 +52,7 @@ let rec unwind xs =
| Ok(zs) -> Ok(y :: zs)
| Error e -> Error e
)
*)
(* Basic samplers *)
let sampleZeroToOne () : float = Random.float 1.0