Thiago Negri | 29 Jan 23:59 2013
Picon

Handling exceptions or gracefully releasing resources

`Control.Exception.bracket` is a nice function to acquire and release a resource in a small context.

But, how should I handle resources that are hold for a long time?

Should I put `Control.Exception.finally` on every single line of my finalizers?
What exceptions may occur on an IO operation? 
Every IO function has the risk of throwing an exception?

Thanks,
Thiago.

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Johan Tibell | 30 Jan 00:26 2013
Picon

Re: Handling exceptions or gracefully releasing resources

Hi,

The pattern is essentially the same as in imperative languages; every
allocation should involve a finally clause that deallocates the
resource.

On Tue, Jan 29, 2013 at 2:59 PM, Thiago Negri <evohunz <at> gmail.com> wrote:
> Should I put `Control.Exception.finally` on every single line of my
> finalizers?

I'm not sure what you're asking here. If your finally clause tries to
call close, you don't have to catch exceptions raise by close (what
would you do with them anyway).
Felipe Almeida Lessa | 30 Jan 13:47 2013
Picon

Re: Handling exceptions or gracefully releasing resources

Everything that Johan Tibell said + you may be interested in the
resourcet package [1] (which is used by conduit to handle resources).

Cheers,

[1] http://hackage.haskell.org/package/resourcet

On Tue, Jan 29, 2013 at 8:59 PM, Thiago Negri <evohunz <at> gmail.com> wrote:
> `Control.Exception.bracket` is a nice function to acquire and release a
> resource in a small context.
>
> But, how should I handle resources that are hold for a long time?
>
> Should I put `Control.Exception.finally` on every single line of my
> finalizers?
> What exceptions may occur on an IO operation?
> Every IO function has the risk of throwing an exception?
>
> Thanks,
> Thiago.
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe <at> haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>

--

-- 
Felipe.
Thiago Negri | 30 Jan 14:15 2013
Picon

Re: Handling exceptions or gracefully releasing resources

Felipe, I'm trying to use your Hipmunk package. :)
The resources I need to keep around are the objects used for the simulation.
Do you recomend using "resourcet" to handle this or something else?

Thanks.


2013/1/30 Felipe Almeida Lessa <felipe.lessa <at> gmail.com>
Everything that Johan Tibell said + you may be interested in the
resourcet package [1] (which is used by conduit to handle resources).

Cheers,

[1] http://hackage.haskell.org/package/resourcet

On Tue, Jan 29, 2013 at 8:59 PM, Thiago Negri <evohunz <at> gmail.com> wrote:
> `Control.Exception.bracket` is a nice function to acquire and release a
> resource in a small context.
>
> But, how should I handle resources that are hold for a long time?
>
> Should I put `Control.Exception.finally` on every single line of my
> finalizers?
> What exceptions may occur on an IO operation?
> Every IO function has the risk of throwing an exception?
>
> Thanks,
> Thiago.
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe <at> haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>



--
Felipe.

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe <at> haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe
Felipe Almeida Lessa | 30 Jan 14:52 2013
Picon

Re: Handling exceptions or gracefully releasing resources

AFAIR, the only object that you need to be careful with is the Space
[1], everything else is garbage collected.  You could put the Space in
a ResourceT, but only if it ran on its own thread (as soon as a block
of ResourceT finishes, everything is deallocated, so you wouldn't be
able to follow the approach taken by HipmunkPlayground).

Cheers,

[1] http://hackage.haskell.org/packages/archive/Hipmunk/5.2.0.10/doc/html/Physics-Hipmunk-Space.html#v:freeSpace

On Wed, Jan 30, 2013 at 11:15 AM, Thiago Negri <evohunz <at> gmail.com> wrote:
> Felipe, I'm trying to use your Hipmunk package. :)
> The resources I need to keep around are the objects used for the simulation.
> Do you recomend using "resourcet" to handle this or something else?
>
> Thanks.
>
>
> 2013/1/30 Felipe Almeida Lessa <felipe.lessa <at> gmail.com>
>>
>> Everything that Johan Tibell said + you may be interested in the
>> resourcet package [1] (which is used by conduit to handle resources).
>>
>> Cheers,
>>
>> [1] http://hackage.haskell.org/package/resourcet
>>
>> On Tue, Jan 29, 2013 at 8:59 PM, Thiago Negri <evohunz <at> gmail.com> wrote:
>> > `Control.Exception.bracket` is a nice function to acquire and release a
>> > resource in a small context.
>> >
>> > But, how should I handle resources that are hold for a long time?
>> >
>> > Should I put `Control.Exception.finally` on every single line of my
>> > finalizers?
>> > What exceptions may occur on an IO operation?
>> > Every IO function has the risk of throwing an exception?
>> >
>> > Thanks,
>> > Thiago.
>> >
>> >
>> > _______________________________________________
>> > Haskell-Cafe mailing list
>> > Haskell-Cafe <at> haskell.org
>> > http://www.haskell.org/mailman/listinfo/haskell-cafe
>> >
>>
>>
>>
>> --
>> Felipe.
>
>

--

-- 
Felipe.

Gmane