[Haskell-cafe] partial functions / failure,
Maybe and MonadError and good style
dm.maillists at gmail.com
Fri Dec 22 20:52:43 EST 2006
On Saturday 23 December 2006 14:21, Stefan O'Rear wrote:
> On Fri, Dec 22, 2006 at 08:05:08PM -0500, Steve Downey wrote:
> > Although terse, the subject really says it all.
> > If i've a partial function, like a parser, what is considered good
> > style for a library. The tradeoffs that I can see are that Maybe is a
> > binary operation, while Error can communicate more information in the
> > type of the error case.
> > Is there some way to defer the error handling Monad to the calling
> > context?
> Your title answers the question. :)
> All monads provide a "fail" operation, and any function that uses fail will
> be able to work with any monad's error handling mechanism.
Though this obviously forces you to encode your library's error information
into a String, which is a serious limitation in my book.
If your library is in an Error monad it seems straight forward for a consumer
to get the fail behaviour, or even provide a wrapper in the library. Going
the other way and having to decode Strings into richer error constructs may
or may not be straight forward.
I recall there has been previous (lengthy) discussion on errors and fail in
this list. It might be worth having a trawl to get the different points of
More information about the Haskell-Cafe