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

PICCA Frederic-Emmanuel frederic-emmanuel.picca at synchrotron-soleil.fr
Tue Mar 29 16:45:59 UTC 2016


Hello,

I end up with this sort of code using Maybe.

withDataspace :: HId_t -> (Maybe HId_t -> IO r) -> IO r
withDataspace hid f = bracket acquire release f
  where
    acquire = do
      space_id@(HId_t status) <- h5d_get_space hid
      return  $ if status < 0 then Nothing else (Just space_id)
    release (Just shid) = h5s_close shid
    release Nothing = return (HErr_t (-1))



More information about the Beginners mailing list