-%* match on an unmixed block: the real business *
-%* *
-%************************************************************************
-\subsection[matchUnmixedEqns]{@matchUnmixedEqns@: getting down to business}
-
-The function @matchUnmixedEqns@ is where the matching stuff sets to
-work a block of equations, to which the mixture rule has been applied.
-Its arguments and results are the same as for the ``top-level'' @match@.
-
-\begin{code}
-matchUnmixedEqns :: [Id]
- -> [EquationInfo]
- -> DsM MatchResult
-
-matchUnmixedEqns [] _ = panic "matchUnmixedEqns: no names"
-
-matchUnmixedEqns all_vars@(var:vars) eqns_info
- | isWildPat first_pat
- = ASSERT( all isWildPat column_1_pats ) -- Sanity check
- -- Real true variables, just like in matchVar, SLPJ p 94
- -- No binding to do: they'll all be wildcards by now (done in tidy)
- match vars remaining_eqns_info
-
- | isConPat first_pat
- = ASSERT( patsAreAllCons column_1_pats )
- matchConFamily all_vars eqns_info
-
- | isLitPat first_pat
- = ASSERT( patsAreAllLits column_1_pats )
- -- see notes in MatchLiteral
- -- not worried about the same literal more than once in a column
- -- (ToDo: sort this out later)
- matchLiterals all_vars eqns_info
-
- | isSigPat first_pat
- = ASSERT( isSingleton eqns_info )
- matchSigPat all_vars (head eqns_info)
- where
- first_pat = head column_1_pats
- column_1_pats = [pat | EqnInfo _ _ (pat:_) _ <- eqns_info]
- remaining_eqns_info = [EqnInfo n ctx pats match_result | EqnInfo n ctx (_:pats) match_result <- eqns_info]
-\end{code}
-
-A SigPat is a type coercion and must be handled one at at time. We can't
-combine them unless the type of the pattern inside is identical, and we don't
-bother to check for that. For example:
-
- data T = T1 Int | T2 Bool
- f :: (forall a. a -> a) -> T -> t
- f (g::Int->Int) (T1 i) = T1 (g i)
- f (g::Bool->Bool) (T2 b) = T2 (g b)
-
-We desugar this as follows:
-
- f = \ g::(forall a. a->a) t::T ->
- let gi = g Int
- in case t of { T1 i -> T1 (gi i)
- other ->
- let gb = g Bool
- in case t of { T2 b -> T2 (gb b)
- other -> fail }}
-
-Note that we do not treat the first column of patterns as a
-column of variables, because the coerced variables (gi, gb)
-would be of different types. So we get rather grotty code.
-But I don't think this is a common case, and if it was we could
-doubtless improve it.
-
-Meanwhile, the strategy is:
- * treat each SigPat coercion (always non-identity coercions)
- as a separate block
- * deal with the stuff inside, and then wrap a binding round
- the result to bind the new variable (gi, gb, etc)
-
-\begin{code}
-matchSigPat :: [Id] -> EquationInfo -> DsM MatchResult
-matchSigPat (var:vars) (EqnInfo n ctx (SigPat pat ty co_fn : pats) result)
- = selectMatchVar pat `thenDs` \ new_var ->
- dsExpr (HsApp co_fn (HsVar var)) `thenDs` \ rhs ->
- match (new_var:vars) [EqnInfo n ctx (pat:pats) result] `thenDs` \ result' ->
- returnDs (adjustMatchResult (bindNonRec new_var rhs) result')
-\end{code}
-
-%************************************************************************
-%* *