[Haskell-cafe] Why were unfailable patterns removed and "fail" added to Monad?
Ganesh Sittampalam
ganesh at earth.li
Sat Jan 21 14:47:02 CET 2012
On 20/01/2012 03:23, Edward Z. Yang wrote:
> Oh, I'm sorry! On a closer reading of your message, you're asking not
> only asking why 'fail' was added to Monad, but why unfailable patterns
> were removed.
>
> Well, from the message linked:
>
> In Haskell 1.4 g would not be in MonadZero because (a,b) is unfailable
> (it can't fail to match). But the Haskell 1.4 story is unattractive becuase
> a) we have to introduce the (new) concept of unfailable
> b) if you add an extra constructor to a single-constructor type
> then pattern matches on the original constructor suddenly become
> failable
>
> (b) is a real killer: suppose that you want to add a new constructor and
> fix all of the places where you assumed there was only one constructor.
> The compiler needs to emit warnings in this case, and not silently transform
> these into failable patterns handled by MonadZero...
It's pretty ugly, but what about using a different 'do' to select the
MonadZero behaviour? "failable-do Foo x <- bar" translates to mzero,
whereas "do Foo x <- bar" translates to an error. That way programmer
intent is captured locally.
"failable-do" is a straw man name :-)
Ganesh
More information about the Haskell-Cafe
mailing list