Created
March 4, 2019 15:12
-
-
Save stedolan/32856f72d94f5c3ac4e6f88a94b07d76 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 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