<div dir="ltr">If your finalization step depends on the result of your action, bracket is not an appropriate choice. It is for resources that are known at the time they are acquired.</div><br><div class="gmail_quote"><div dir="ltr">On Sat, Mar 26, 2016 at 11:59 AM PICCA Frederic-Emmanuel <<a href="mailto:frederic-emmanuel.picca@synchrotron-soleil.fr">frederic-emmanuel.picca@synchrotron-soleil.fr</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello, I try to write a sort of withxxx method whcih release a file<br>
<br>
withH5File :: FilePath -> (HId_t -> IO r) -> IO r<br>
withH5File name = bracket (withCString name acquire) h5f_close<br>
where<br>
acquire file = h5f_open file h5f_ACC_RDONLY h5p_DEFAULT<br>
<br>
In my case h5f_open return a HId_t value (HId_t Int)<br>
If something went wrong the returned value is negativ.<br>
In that case I do not need to h5f_close the file but instead return an error<br>
<br>
My question is how should I write the bracket part when the finaliser (h5f_close) depends on the result of the acquire part.<br>
<br>
thanks for your help<br>
<br>
Frederic<br>
_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
</blockquote></div>