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.
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@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners