
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/htm... 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? I wondered why 'unzip' does not have the space leak, although when I sequence a lot of Exceptional values using mconcat, I'm doing something pretty similar. 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