[Haskell-beginners] bracket or how to release ressources.

Rein Henrichs rein.henrichs at gmail.com
Sat Mar 26 19:40:18 UTC 2016


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.

On Sat, Mar 26, 2016 at 11:59 AM PICCA Frederic-Emmanuel <
frederic-emmanuel.picca at synchrotron-soleil.fr> wrote:

> Hello, I try to write a sort of withxxx method whcih release a file
>
> withH5File :: FilePath -> (HId_t -> IO r) -> IO r
> withH5File name = bracket (withCString name acquire) h5f_close
>     where
>        acquire file = h5f_open file h5f_ACC_RDONLY h5p_DEFAULT
>
> In my case h5f_open return a HId_t value (HId_t Int)
> If something went wrong the returned value is  negativ.
> In that case I do not need to h5f_close the file but instead return an
> error
>
> My question is how should I write the bracket part when the finaliser
> (h5f_close) depends on the result of the acquire part.
>
> thanks for your help
>
> Frederic
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160326/c0872d2b/attachment.html>


More information about the Beginners mailing list