Warn against using 'fail' directly in user-code (was: Proposal: die to System.Exit (and/or Prelude))

Stijn van Drongelen rhymoid at gmail.com
Mon Dec 16 21:15:17 UTC 2013


On Mon, Dec 16, 2013 at 5:50 PM, Herbert Valerio Riedel <hvr at gnu.org> wrote:

> On 2013-12-16 at 14:54:53 +0100, Andreas Abel wrote:
> > On 16.12.2013 14:12, Roman Cheplyaka wrote:
> >>>> The purpose of 'fail' is to handle monadic pattern-match failures.
> >>>> I consider explicit use of 'fail' in user code a hack.
> >>
> >> I treat 'fail' as a semi-private method of the Monad class. I may
> >> override it, but I should never call it. It only exists for the
> >> compiler.
> >
> > This is useful information.  Please add it to the documentation.  That
> > would definitely help newcomers to get some orientation in the design
> > space of exceptions...
>
> [...]
>
> If this is really the intent of `fail`, shouldn't we then also attach a
>
>   {-# WARNING fail "Monad(fail) is not supposed to be called directly" #-}
>
> to the `fail` method definition to help catch illegal uses of `fail` in
> user code?
>
> (Fwiw, I've tested attaching such a warning to `fail` in GHC HEAD's
> libraries/base/GHC/Base.lhs and it seems to work just fine so far... so
> if there's consensus, we could add that for GHC 7.8)
>
> Cheers,
>   hvr
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://www.haskell.org/mailman/listinfo/libraries
>

+1!

I think `fail` is a huge wart anyway.

I'm still partial to the Haskell 1.4 solution to this problem, where the
translation of refutable patterns in do-notation would involve `mzero`
rather than `fail "Here, have some debugging info."`.

:),
Stijn
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20131216/03294eb2/attachment.html>


More information about the Libraries mailing list