<div dir="ltr">Hi Jeremy and the haskell community,<br><br> I think now my question is why isn't there a higher-order "with" function in the Haskell Prelude?<br><br>Regards, Vasili<br><br><div class="gmail_quote">
On Wed, Aug 6, 2008 at 2:25 AM, Jeremy Shaw <span dir="ltr"><<a href="mailto:jeremy@n-heptane.com">jeremy@n-heptane.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
At Wed, 6 Aug 2008 00:43:55 -0500,<br>
Galchin, Vasili wrote:<br>
><br>
> [1 <multipart/alternative (7bit)>]<br>
> [1.1 <text/plain; ISO-8859-1 (7bit)>]<br>
<div class="Ih2E3d">> Hello,<br>
><br>
> 1) Is there a common assumed semantics across all of the Haskell "with"<br>
> things? withString? withData?<br>
<br>
</div>A vague semantic is that some resource is acquired, used, and then released.<br>
<div class="Ih2E3d"><br>
> 2) If the answer to 1) is yes, then does this imply some kind of<br>
> polymorphism? Couldn't "with" be "reduced" to a higher order function then<br>
> ??<br>
<br>
</div>I think Control.Exception.bracket is used to implement many, but not<br>
all, of the with* functions.<br>
<br>
> newThing :: IO a<br>
> newThing = ...<br>
<br>
> destroyThing :: a -> IO b<br>
> destroyThing ...<br>
<br>
> withThing :: (Thing -> IO a) -> IO a<br>
> withThing useThing = bracket newThing destroyThing useThing<br>
<br>
I have not fully answered either of your questions, but hopefully this<br>
is a start.<br>
<font color="#888888"><br>
j.<br>
</font></blockquote></div><br></div>