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

PICCA Frederic-Emmanuel frederic-emmanuel.picca at synchrotron-soleil.fr
Sat Mar 26 18:59:38 UTC 2016


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


More information about the Beginners mailing list