
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. E.g. do 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`. -Edward 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@googlemail.com> wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
MonadFail proposal update 1 ===========================
Rendered version of this text: https://github.com/quchen/articles/blob/master/monad_fail_update1.md
Original MFP: https://github.com/quchen/articles/blob/master/monad_fail.md
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` constraint. - - 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 intended.
### 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 anyway.
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.
Greetings, David/quchen -----BEGIN PGP SIGNATURE----- Version: GnuPG v1
iQEcBAEBAgAGBQJVgDvGAAoJELrQsaT5WQUspmIIAJi9UVYIitHv2CKvWSmk1fg0 hYaPRXDJMnyFS21v57+JeTPhM/dnI4k0guUUrlIB9k5WPaySQ6MKIAnB51o5O9Gv zt87FII5/oYsJtVPruKgBtLPbJVhg6zGUXmNco1S2wvB5m5HdBooQsiBRY+qiFfZ MJOdzXpRCrYJk/0PeF7sglBOElSwsSmGq/klvJUo4VeVAdi8bU+lKRfET/AmAAM5 oqckAI0SEaFo+w6EXBLPiL/F5SoFBmKR50Nu4NKWRBcoNGq7AwvWEKDZeU0PvC3a dykqSnFTRtL5LeWZnByuZTVVqlDG3afjX6ZYkrUbMKQeE9rVf24Gx9jlRusxSds= =zUDu -----END PGP SIGNATURE----- _______________________________________________ Libraries mailing list Libraries@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries