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

Scott Turner 2haskell at pkturner.org
Fri Jan 20 14:02:34 CET 2012


On 2012-01-19 23:52, Michael Snoyman wrote:
> 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.

I fully agree if it's IO, so that a failed pattern match leads to an 
exception.  The "nice" implementations of fail in the List and Maybe 
monads are a different story.

Ideally one would want to be able to turn on a warning whenever IO is 
used in a way which could generate a pattern match exception.  This 
would call for a type distinction, as you said, "reinstate the MonadZero 
constraint".

Here's an idea that might address SPJ's "killer".
       b) if you add an extra constructor to a single-constructor
          type then pattern matches on the original constructor
          suddenly become failable

Another binding operator might be introduced so that the code would show 
the intention either to have a failable or non-failable pattern match.
      do (x,y) <- pair       failable, requires MonadZero
      do (x,y) <=- pair      requires non-failable pattern
                             supports Monads that should not fail



More information about the Haskell-Cafe mailing list