Hacker News new | ask | show | jobs
by noste 6042 days ago
"Note how instead of saying, "Ocaml doesn't have with-open-file or unwind-protect", he says, "Here's how you have to do with-open-file and unwind-protect in Ocaml". No! You do not go around trying to turn other languages into Lisp if you want to code in Lisp. If you want to code in Lisp, you code in Lisp."

What would be the OCaml solution for the problem that unwind-protect solves? In Haskell, I would use bracket, and appropriately the API documentation of bracket gives the definition of withFile as an example:

  withFile name mode = bracket (openFile name mode) hClose
(see http://haskell.org/ghc/docs/latest/html/libraries/base/Contr...)
2 comments

You can implement your own unwind-protect:

http://caml.inria.fr/pub/ml-archives/caml-list/2003/07/5ff66...

FWIW, F# has "using". Between "using" and IDispose, you've got all the resource-unlocking, unwinding, and rollbacks you'd ever want.

I think this article makes it very clear how having a huge existing set of libraries can really put a language into warp drive, whereas not having one means you are going to spend some time re-inventing the wheel. (But even in straight Ocaml, I fail to see the problem)