[Haskell-cafe] Why were unfailable patterns removed and "fail" added to Monad?

Michael Snoyman michael at snoyman.com
Tue Jan 24 11:32:03 CET 2012


On Fri, Jan 20, 2012 at 6:52 AM, Michael Snoyman <michael at snoyman.com> wrote:
> On Fri, Jan 20, 2012 at 6:41 AM, Edward Z. Yang <ezyang at mit.edu> wrote:
>> Aw, that is really suboptimal.  Have you filed a bug?
>
> I think it's a feature, not a bug. When dealing with monads that
> provide nice[1] implementations of `fail`, you can (ab)use this to
> avoid writing a bunch of case expressions. I remember reading it in
> one of the first tutorials on Haskell I looked at (four years ago now?
> you can see how much this bothered me if I still remember that).
>
> I admit that there are some use cases where the current behavior is
> convenient, but I think we're paying too steep a price. If we got rid
> of this feature entirely, we could (a) get rid of fail and (b) have
> the compiler warn us about a bunch of errors at compile time.
>
> But maybe I should file a feature request: provide an extra warning
> flag (turned on by -Wall) that will warn when you match on a failable
> pattern. Essentially, I would want:
>
> SomeConstr args <- someAction
>
> to be interpreted as:
>
> temp <- someAction
> case temp of
>    SomeConstr args ->
>
> Michael

I've filed a feature request for this warning:

http://hackage.haskell.org/trac/ghc/ticket/5813

Michael



More information about the Haskell-Cafe mailing list