Created
January 30, 2020 17:33
-
-
Save Nymphium/fa8b0f3044ffdd8b32fcc6db290fde8a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let run_continuer : type a. ((unit -> (unit -> a)) -> a) -> a = | |
fun f -> | |
let module M = struct | |
effect Save : unit -> (unit -> a);; | |
let save () = perform @@ Save () | |
end | |
in | |
let open M in | |
match f save with | |
| effect (Save ()) k -> | |
let rec c k = | |
let k' = Obj.clone_continuation k in | |
continue k @@ fun () -> c k' | |
in c k | |
| x -> x | |
print_int @@ run_continuer @@ fun save -> | |
let i = ref 0 in | |
let c = save () in | |
if !i < 10 then | |
let () = incr i in | |
c () | |
else | |
!i |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment