Skip to content

Instantly share code, notes, and snippets.

@derrickturk
Created July 23, 2022 03:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save derrickturk/a362ce9a1c83e839daf97f6966e91ba9 to your computer and use it in GitHub Desktop.
Save derrickturk/a362ce9a1c83e839daf97f6966e91ba9 to your computer and use it in GitHub Desktop.
now this is podracing
(* yeah, so, Eff doesn't actually support polymorphic effects *)
effect Save: string -> int
effect Load: string * int -> empty
let save name = perform (Save name)
let load name v = absurd (perform (Load (name, v)))
let savegames = handler
| effect (Save name) k ->
let rec loading () = handler
| effect (Load (name', v)) _ ->
if name = name'
then
with loading () handle
continue k v
else load name' v
in
with loading () handle
continue k 0;;
with savegames handle
match save "first_save" with
| 0 ->
print_endline "first this...";
load "first_save" 23;
print_endline "shouldn't make it here"
| 23 ->
begin match save "second_save" with
| 0 ->
print_endline "now this";
load "second_save" 99;
print_endline "shouldn't make it here"
| n ->
print_endline "followed by this";
load "first_save" (n + 3);
print_endline "nor here"
end
| n ->
print_endline ("reloaded with: " ^ string_of_int n)
;;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment