Loading ...
Sorry, an error occurred while loading the content.

1519Re: "ocaml_beginners"::[] Handling resources.

Expand Messages
  • Thaddeus L. Olczyk
    Dec 1, 2003
      On Fri, 28 Nov 2003 14:28:11 +0100, Hendrik Tews
      <tews@...-dresden.de> wrote:

      >
      > Took a look, but something is missing.
      > It would be nice write a function to generate
      > an "unwind-protected" function.
      >
      >You don't need to generate. You simply use higher-order functions
      >like make_protected.
      >
      Uhm. I'm not quite sure what the language barrier here is, but clearly
      you misunderstand.

      When I say "unwind-protected" function I mean a function which is
      similar to the original but with an unwind-protect type wrapper.

      When I say generate, I don't mean anything formal. Simply that
      a function takes a function and returns a modified function.
      A higher-order function no? So what I am saying would include
      make_protected.

      >If you really insist to generate the protected function you can
      >always use your favourite preprocessor, like m4 or cpp to
      >preprocess your ocaml sources.
      Yuch. Klude.
      >You can also use camlp4, the ocaml
      >preprocessor/pretty-printer.
      >
      Less of a kludge, but yet still a kludge.

      > The problem being that a resource can be acquired using
      > no parameters,
      >
      >Use a dummy () argument.
      >
      My mistake.
      I envisioned a function f with signature ()->x/
      I thought the make_protected could not handle
      such a function. I see now that it can.


      > one parameter, two parameters etc...
      >
      >pack the arguments in a tuple
      >
      > The other problem being that the function only takes one ( or two if
      > you count handle ) parameter. It's hard to see how to generalize.
      >
      >Same thing. You pass tuples of ressources around.
      >

      Uhm. It's the same point.

      I have a problem with changing multiple arguments to tuples.

      First functions don't usually come that way, so I have to modify
      the each function by hand. Second the function that is produced
      likely takes a tuple as an argument. Since that is not the way the
      original function works, it will cause confusion. So I have to curry
      the function, probably by hand each time. Third I have to
      remember these two steps each time I do this on a function.

      If there was some curry/uncurry function, then it wouldn't be
      a problem, but AFAIK no such functions exist.
      Thaddeus L. Olczyk
      -----------------------
      Think twice, code once.
    • Show all 12 messages in this topic