by catnaroek · 8y ago · 0 comments
I am afraid you are talking nonsense. Higher-order functions make verification harder, not easier, because they hide the point at which control flow is transferred from one module to another. This is backwards, because this point should be prominent, in big neon letters, precisely so that you can tell exactly when a resource stops being available, or when an invariant goes from being “your responsibility” to “someone else's problem”.
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.
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.
But again hence the value of having the lifetime of the object enforced by the type system.