[Haskell-cafe] Re: not possible with monad transformers ?
Jules Bean
jules at jellybean.co.uk
Tue Nov 30 17:49:37 EST 2004
On 30 Nov 2004, at 20:55, Pavel Zolnikov wrote:
> Now I realize that as long as I am using liftM2 it is not possible
> to have history of errors from a and b - only form a. And as I moved
> to custom lift functions I realized I didn’t need monads in the
> first place.
>
It's not liftM2 that's the problem, it's rather the strategy of the
Maybe monad. The strategy of the maybe monad is very roughly 'abort on
error'. As you correctly observe, it doesn't make it at all easy to
collect error messages, let alone tree-shaped error graphs.
However, your problem *does* have a natural underlying monad, if you
care to use it. It's a kind of Error monad, but not the standard one,
since you would have to implement your chosen rules for combining
errors. I'm not quite sure exactly what you want, probably either a
list of errors, or a tree of errors, depending how much structure
you're trying to preserve.
You may not find the monad approach easier than just coding by hand,
though... although if you have a large amount of code, I would expect
monads to make it a bit shorter and clearer.
Jules
More information about the Haskell-Cafe
mailing list