MFP updates: ideas worth discussing
ekmett at gmail.com
Wed Jun 17 13:33:31 UTC 2015
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
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
On Tue, Jun 16, 2015 at 11:07 AM, David Luposchainsky <
dluposchainsky at googlemail.com> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> 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
> 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
> - - 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
> I think that's an idea we should think about. It is easily implemented in
> 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
> 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
> 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
> 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.
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1
> -----END PGP SIGNATURE-----
> Libraries mailing list
> Libraries at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the ghc-devs