MFP updates: ideas worth discussing

Augustsson, Lennart Lennart.Augustsson at
Wed Jun 17 13:39:48 UTC 2015

On this issue I totally agree with Ed. ☺

From: Libraries [mailto:libraries-bounces at] On Behalf Of Edward Kmett
Sent: 17 June 2015 14:34
To: David Luposchainsky
Cc: Haskell Libraries; ghc-devs at
Subject: Re: MFP updates: ideas worth discussing

There is a bit of a knee-jerk reaction that we should go to something simpler than Monad as a superclass constraint for MonadFail, but I think most of those reasons fall apart or at least lose much of their weight upon deeper inspection.

Ultimately, I'm a not concerned about interactions between ApplicativeDo notation and fail.

Any automatic desugaring into 'fail' will be in a context which is necessarily incurring a monad constraint.


   Just x <- m

has to pick up the Monad constraint anyways to deal with the binding!

This leaves only code that does something like.

foo = x <*> fail y

which is hand written to invoke fail.

Given that the entire "tree" of the Applicative" is available for inspection and that that fail can't depend on any context internal to the Applicative and remain 'just Applicative' I have a hard time foreseeing any real applications lost by continuing to assume a context of:

class Monad m => MonadFail m

and there is a lot of value in the simple context.

Most of the value in ApplicativeDo notation comes from the opportunities for increased parallelism, not so much from the reduced constraints on the resulting code, and as we can see above, it'll never arise during the desguaring in a place that wouldn't incur a Monad constraint anyways.

Even getting rid of the Monad constraint w/ ApplicativeDo is going to require gymnastics around `return`.


P.S. On an unrelated note, for the record, I'm very strongly +1 on a MonadFail instance for IO. There we use throwIO explicitly, so it is even able to be handled and caught locally. The set of things you can do in IO is large enough to support and reason about explicit failure.

P.P.S. I think if we extend the proposal to include an explicit member of the class for pattern match failure with the code we currently have lurking in the compiler for producing the string from the context, then most of the concerns raised by folks who would prefer to use a heavier weight -- but vastly harder to standardize -- exception mechanism would also be addressed in practice.

On Tue, Jun 16, 2015 at 11:07 AM, David Luposchainsky <dluposchainsky at<mailto:dluposchainsky at>> wrote:
Hash: SHA1

MonadFail proposal update 1

Rendered version of this text:

Original MFP:

Short summary
- -------------

A week has passed since I posted the MFP, and the initial discussion is mostly
over. Here are my observations:

- - Everyone agrees that `fail` should not be in `Monad`.
- - Almost everyone agrees that it should be thrown out of it.
- - Some would prefer to see the special desugaring be gone entirely.
- - The name `MonadFail` is controversial, because of a potential `Applicative`
- - We're still unsure about whether `IO` should get a `MonadFail` instance, but
  the bias seems to be towards "yes".

New ideas worth thinking about
- ------------------------------

### Special desugaring or not

Johann suggested an optional warning whenever something desugars to use `fail`.
I think that's an idea we should think about. It is easily implemented in the
compiler, and would probably behave similar to -fwarn-unused-do-binds in
practice: notation that is not wrong, but might not be what the programmer

### Errors vs. Exceptions

Henning is concerned about the confusion between exceptions and programming
errors. In his words,

> We should clearly decide what "fail" is intended for - for programming
> errors or for exceptions.

What I see clashing with his point is backwards compatibility. Removing the
`String` argument breaks all explicit invocations of `fail`. Unfortunately,
we're not in a position to break very much. If someone has a better idea I'd
love to hear about it though.

### ApplicativeDo

ApplicativeDo is somewhere out there on the horizon, and we're not sure yet how
much `fail` makes sense in the context of `Applicative`. An Applicative
computation is statically determined in its shape, so it either always or never
fails. Depending on previous results would introduce the `Monad` constraint

Probing status
- --------------

Henning has started to look at the impact of the proposal when explicit
invocations of `fail` are considered as well, something I have not done in my
original survey. Luckily, things don't look too bad, Lens and its forest of
dependencies can be fixed in around ten trivial changes, for example.

Version: GnuPG v1

Libraries mailing list
Libraries at<mailto:Libraries at>

This email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please delete all copies and notify the sender immediately. You may wish to refer to the incorporation details of Standard Chartered PLC, Standard Chartered Bank and their subsidiaries at

Insofar as this communication contains any market commentary, the market commentary has been prepared by a sales and/or trading desk of Standard Chartered Bank or its affiliate. It is not and does not constitute research material, independent research, recommendation or financial advice. Any market commentary is for information purpose only and shall not be relied for any other purpose, and is subject to the relevant disclaimers available at

Please visit  for important information with respect to derivative products.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Libraries mailing list