fix: add tail recursion
This commit is contained in:
parent
7ce4658d30
commit
25a27f7fc4
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -34,7 +34,16 @@ let findIndex xs test =
|
||||||
in
|
in
|
||||||
recursiveHelper xs 0
|
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
|
match xs with
|
||||||
| [] -> Ok([])
|
| [] -> Ok([])
|
||||||
| Error e:: ys -> Error e
|
| Error e:: ys -> Error e
|
||||||
|
@ -43,6 +52,7 @@ let rec unwind xs =
|
||||||
| Ok(zs) -> Ok(y :: zs)
|
| Ok(zs) -> Ok(y :: zs)
|
||||||
| Error e -> Error e
|
| Error e -> Error e
|
||||||
)
|
)
|
||||||
|
*)
|
||||||
|
|
||||||
(* Basic samplers *)
|
(* Basic samplers *)
|
||||||
let sampleZeroToOne () : float = Random.float 1.0
|
let sampleZeroToOne () : float = Random.float 1.0
|
||||||
|
|
Loading…
Reference in New Issue
Block a user