Skip to content

Instantly share code, notes, and snippets.

@Gbury
Created December 16, 2016 13:52
Show Gist options
  • Save Gbury/fec6604b2bd11e62bd481d9d1126660d to your computer and use it in GitHub Desktop.
Save Gbury/fec6604b2bd11e62bd481d9d1126660d to your computer and use it in GitHub Desktop.
let fix f x =
match f x with
| `Ok -> Gen.singleton x
| `Gen gen ->
let s = Stack.create () in
Stack.push gen s;
let rec aux () =
if Stack.is_empty s then None
else begin
let g = Stack.top s in
match g () with
| Some y -> y
| None ->
let _ = Stack.pop s in
aux ()
end
in
aux
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment