David Sorokin | 8 Aug 14:51 2013
Picon

Proposal for adding finallyError to MonadError

Hi, Café!

I have a proposal. I offer to add a new function to the MonadError type 
class:

   finallyError :: MonadError e m => m a -> m b -> m a

This is a generalization of the standard finally function that has the 
following signature:

   finally: IO a -> IO b -> IO a

Like function finally, the finallyError function runs the first 
computation and then runs the second computation regardless of whether 
an error might arise in the first computation. The first computation 
defines the result.

Introducing semantics of a possible cancellation of the m computation, 
the finallyError function accepts an additional meaning. The second 
computation must be performed even in case of cancelling the 
computation, while function catchError must be ignored. It literally 
means that the finallyError function cannot be expressed in terms of the 
catchError function.

This idea is essentially inspired by the F# async workflow that does 
allow cancelling the Async computation. I implemented a similar monad 
Simulation.Aivika.Cont.Cont for my simulation library Aivika [1]. My 
monad Cont is an extension of the standard monad with the same name. It 
uses continuations (namely, three different continuations within one 
computation). It supports the exception handling and it allows 
(Continue reading)


Gmane