Skip to content

Instantly share code, notes, and snippets.

@stedolan
Created March 4, 2019 15:12
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 stedolan/32856f72d94f5c3ac4e6f88a94b07d76 to your computer and use it in GitHub Desktop.
Save stedolan/32856f72d94f5c3ac4e6f88a94b07d76 to your computer and use it in GitHub Desktop.
let print_res = function
| Ok n -> Printf.printf "Ok %d\n" n;
| Error exn -> Printf.printf "Error (%s)\n" (Printexc.to_string exn)
let run f =
match f () with
| n -> Ok n
| exception e -> Error e
module rec Bad : sig
val f : unit -> int
val a : (int, exn) result Lazy.t
val b : (int, exn) result Lazy.t
val c : (int, exn) result Lazy.t
val d : (int, exn) result Lazy.t
end = struct
let f () = 42
let a = lazy (run f)
let b = lazy (run Bad.f)
let c = lazy (run f)
let d = lazy (run Bad.f)
let _ = Lazy.force c
let _ = Lazy.force d
end
open Bad
let e = run f
let () = List.iter print_res [Lazy.force a; Lazy.force b; Lazy.force c; Lazy.force d; e]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment