Skip to content

Change the fail operator argument of BindStmt to be a Maybe and use TTG

cgibbard requested to merge obsidiansystems/ghc:cg-do-fail-op-maybe into master

The BindStmt constructor contains a field holding an expression for the fail operator to be used when a pattern match fails. In cases where the match cannot fail, GHC presently puts noSyntaxExpr in that field (which is a string literal that otherwise gets ignored). This small refactoring turns the field into a Maybe instead, using Nothing to denote cases where the pattern is unfailable.

As part of an ongoing attempt to add an extension which would allow MonadFail translation of do-notation to be switched off on a per-module basis, this refactoring to make the fail-op field of BindStmt into a Maybe was helpful.

There is still something I encountered in this which I don't fully understand, which is that tcMonadFailOp seems to re-check whether the pattern is failable using isIrrefutableHsPat on it, even when this same function ought to have been used to check this when the fail-op field was being set initially. Regardless, removing that additional check caused problems that I've yet to fully investigate (the compiler would assume more patterns were failable and ended up demanding MonadFail constraints where they weren't provided or really needed).

If the reason for this could be sorted out, perhaps the re-check in tcMonadFailOp could be removed and its type changed to remove the Maybe in its result.

Edited by John Ericson

Merge request reports