1519Re: "ocaml_beginners":: Handling resources.
- Dec 1, 2003On Fri, 28 Nov 2003 14:28:11 +0100, Hendrik Tews
>Uhm. I'm not quite sure what the language barrier here is, but clearly
> 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
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
>If you really insist to generate the protected function you canYuch. Klude.
>always use your favourite preprocessor, like m4 or cpp to
>preprocess your ocaml sources.
>You can also use camlp4, the ocamlLess of a kludge, but yet still a kludge.
> The problem being that a resource can be acquired usingMy mistake.
> no parameters,
>Use a dummy () argument.
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...Uhm. It's the same point.
>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.
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.
- << Previous post in topic Next post in topic >>