News for hackers. Stuff that matters.
Re:Rust-style resource management in OCaml by zenhack on Friday March 16, 2018 @11:55AM (#16601479)
I think pjmpl is referencing apis like this:

   with_file "hello.txt" (fun fd -> (* do stuff *) )

where you've basically created a c++ destructor style api with a lambda.

It's certainly not "verification" in any formal sense, and the type system can't help you there any more than it can in c++.

But this is a perfectly reasonable pattern.

Re:Rust-style resource management in OCaml by catnaroek on Friday March 16, 2018 @12:12PM (#16601587)
> where you've basically created a c++ destructor style api with a lambda.

Except for the part where destructors are meant to be called no more than once per object, at the end of its lifetime. All that you can guarantee is that `with_file` doesn't call the destructor more than once. But that's not terribly interesting.

Re:Rust-style resource management in OCaml by zenhack on Friday March 16, 2018 @01:03PM (#16602083)
You can screw up destructors in exactly the same ways. And it also serves to make sure you close the file at all.

But again hence the value of having the lifetime of the object enforced by the type system.

Re:Rust-style resource management in OCaml by catnaroek on Friday March 16, 2018 @02:40PM (#16602945)
In the presence of reference-counted mutable objects, destructors no longer guarantee that cleanup will happen. But that much is okay. This is a liveness property, and, as far as I can tell, nobody really knows of any non-annoying way to enforce liveness properties with types. On the other hand, “cleanup is the last operation that can be performed on an object” is a safety property, and types are excellent tools for verifying properties of this kind.
Re:Rust-style resource management in OCaml by pjmlp on Saturday March 17, 2018 @02:55AM (#16605892)
Yep, that was it. Thanks for the example.