<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Dec 20, 2013 at 6:27 PM, Ganesh Sittampalam <span dir="ltr"><<a href="mailto:ganesh@earth.li" target="_blank">ganesh@earth.li</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 16/12/2013 16:50, Herbert Valerio Riedel wrote:<br>
> On 2013-12-16 at 14:54:53 +0100, Andreas Abel wrote:<br>
>> On 16.12.2013 14:12, Roman Cheplyaka wrote:<br>
>>>>> The purpose of 'fail' is to handle monadic pattern-match failures.<br>
>>>>> I consider explicit use of 'fail' in user code a hack.<br>
>>><br>
>>> I treat 'fail' as a semi-private method of the Monad class. I may<br>
>>> override it, but I should never call it. It only exists for the<br>
>>> compiler.<br>
>><br>
>> This is useful information.  Please add it to the documentation.  That<br>
>> would definitely help newcomers to get some orientation in the design<br>
>> space of exceptions...<br>
><br>
> [...]<br>
><br>
> If this is really the intent of `fail`, shouldn't we then also attach a<br>
><br>
>   {-# WARNING fail "Monad(fail) is not supposed to be called directly" #-}<br>
><br>
> to the `fail` method definition to help catch illegal uses of `fail` in<br>
> user code?<br>
<div class="im">><br>
> (Fwiw, I've tested attaching such a warning to `fail` in GHC HEAD's<br>
> libraries/base/GHC/Base.lhs and it seems to work just fine so far... so<br>
> if there's consensus, we could add that for GHC 7.8)<br>
<br>
</div>I'm not sure I follow the logic of this. If it does continue to exist,<br>
what are the arguments against using it explicitly?<br>
<br>
Cheers,<br>
<br>
Ganesh<br></blockquote><div><br></div>Some monads have no sensible implementation for fail, so therefore, `fail` can't be bound by any laws besides what's in the type. So when you're writing common functions involving error handling, the type of `fail` gives you some requirements on how to use it, but you get no promise that it does something useful (note: `fail = error` is not useful).<br>

<br>However, when you use something like MonadError, you're guaranteed (by the type) that you can use throwError, and promised (by those who create instances for MonadError) that it will have a useful meaning.<br><br>

</div><div class="gmail_quote">(And this is just one of the reasons.)<br></div><div class="gmail_quote"><br></div><div class="gmail_quote">Regards,<br>Stijn<br></div></div></div>