Send Beginners mailing list submissions to
        beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  bracket or how to release ressources. (PICCA Frederic-Emmanuel)
   2. Re:  bracket or how to release ressources. (Rein Henrichs)
   3. Re:  bracket or how to release ressources.
      (PICCA Frederic-Emmanuel)


----------------------------------------------------------------------

Message: 1
Date: Sat, 26 Mar 2016 18:59:38 +0000
From: PICCA Frederic-Emmanuel
        <frederic-emmanuel.pi...@synchrotron-soleil.fr>
To: "beginners@haskell.org" <beginners@haskell.org>
Subject: [Haskell-beginners] bracket or how to release ressources.
Message-ID:
        
<a2a20ec3b8560d408356cac2fc148e53b305e...@sun-dag3.synchrotron-soleil.fr>
        
Content-Type: text/plain; charset="us-ascii"

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

------------------------------

Message: 2
Date: Sat, 26 Mar 2016 19:40:18 +0000
From: Rein Henrichs <rein.henri...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] bracket or how to release ressources.
Message-ID:
        <cajp6g8z6gf+rbzowkepz-9pveqhuu-a7g1vucyk0zyefure...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

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.pi...@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@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-0001.html>

------------------------------

Message: 3
Date: Sun, 27 Mar 2016 07:33:27 +0000
From: PICCA Frederic-Emmanuel
        <frederic-emmanuel.pi...@synchrotron-soleil.fr>
To: "The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell" <beginners@haskell.org>
Subject: Re: [Haskell-beginners] bracket or how to release ressources.
Message-ID:
        
<a2a20ec3b8560d408356cac2fc148e53b305e...@sun-dag3.synchrotron-soleil.fr>
        
Content-Type: text/plain; charset="us-ascii"

Looking at the haskellforall I found something which should be interesting in 
my case
A type dedicated to this sort of problem. the Resource Monad.

I will investigate :)

thanks

Frederic

[1] http://www.haskellforall.com/2013/06/the-resource-applicative.html

------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 93, Issue 23
*****************************************

Reply via email to