Skip to content

Refactor the MatchResult type in the desugarer so that it does a better job of proving whether the fail operator is used.

Here, we redefine the MatchResult type so that instead of having what was effectively a Boolean value describing whether the match can fail or not, it has distinct constructors, one of which does not take a CoreExpr for the fail operator.

This keeps the code operating on MatchResults more honest about whether matches can fail, gaining a bit of type safety. As a consequence though, sometimes we ended up wanting to produce intermediate results that had a similar potential for a CoreExpr-shaped hole, but which were not themselves producing CoreExprs (cf. mkDataConCase). As a result, we split the definition into a parametric MatchResult' type, and let MatchResult be a synonym for MatchResult' CoreExpr. This new MatchResult' type is naturally Applicative, which was useful in the rework of mkDataConCase for aggregating information about whether all the alternatives were unfailable. We were able to use liftA2 and traverse to ensure the final MatchResult was failable if and only if any of the parts was, eliminating some separate aggregation of this information that was going on before.

Thinking about it now, it also ought to be a straightforward Monad instance, but we didn't quite need that yet.

Edited by John Ericson

Merge request reports