This is an OCaml language extension implementing a somewhat Go-ish
[%defer expr1]; expr2 which will defer the evaluation of
expr1 until after
expr1 will still be evaluated if
expr2 raises an exception.
If you are using Lwt you can use
[%defer.lwt expr1]; expr2.
Thanks to Drup for guidance in figuring out ppx details!
let () = let ic = open_in_bin "some_file" in [%defer close_in ic]; let length = in_channel_length ic in let bytes = really_input_string ic length in print_endline bytes
examples/ directory for more examples.