[Haskell-cafe] Re: Are there standard idioms for lazy, pure error handling?

Duncan Coutts duncan.coutts at googlemail.com
Wed Dec 9 08:50:34 EST 2009

On Mon, 2009-12-07 at 20:31 +0100, Henning Thielemann wrote:
> Somehow I missed this thread. I want to say that I have implemented a general 
> way to add the information of an exception to the "end" of an arbitrary data 
> structure.
> http://hackage.haskell.org/packages/archive/explicit-exception/0.1.4/doc/html/Control-Monad-Exception-Asynchronous.html
> Duncan already mentioned it:
> > data Exceptional e a = Exceptional {
> >   exception :: Maybe e
> >   result    :: a
> > }
> > However it's pretty clear from the structure of this type that it cannot
> > cope with lazy error handling in sequences. If you try it you'll find
> > you cannot do it without space leaks.
> Actually you spotted the space leak - but how is it pretty clear, that it 
> has the space leak?

Yes you're right, it's not that clear. First time I saw the type my
intuition was that would have a space leak but I had to do some work to
demonstrate it. I was misremembering, it's only clear in retrospect :-)

> I also agree with you, that the possibility to access the result directly, 
> and thus easily ignore the exception is bad. I thought it could be 
> improved by removing the field accessors and instead provide the function:
> switch :: (Maybe e -> c) -> (a -> c) -> Exceptional e a -> c


As a general approach though, I think I rather like just making up extra
algebraic types and handling them with their natural folds and unfolds.
It's very much in the pure lazy FP tradition.


More information about the Haskell-Cafe mailing list