-mkSelectorBinds tyvars pat locals_and_globals val_expr
- = if is_simple_tuple_pat pat then
- mkTupleBind tyvars [] locals_and_globals val_expr
- else
- mkErrorAppDs iRREFUT_PAT_ERROR_ID res_ty "" `thenDs` \ error_msg ->
- matchSimply val_expr pat res_ty local_tuple error_msg `thenDs` \ tuple_expr ->
- mkTupleBind tyvars [] locals_and_globals tuple_expr
- where
- locals = [local | (local, _) <- locals_and_globals]
- local_tuple = mkTupleExpr locals
- res_ty = coreExprType local_tuple
-
- is_simple_tuple_pat (TuplePat ps) = all is_var_pat ps
- is_simple_tuple_pat other = False
-
- is_var_pat (VarPat v) = True
- is_var_pat other = False -- Even wild-card patterns aren't acceptable
-\end{code}
-
-We're about to match against some patterns. We want to make some
-@Ids@ to use as match variables. If a pattern has an @Id@ readily at
-hand, which should indeed be bound to the pattern as a whole, then use it;
-otherwise, make one up.
-\begin{code}
-selectMatchVars :: [TypecheckedPat] -> DsM [Id]
-selectMatchVars pats
- = mapDs var_from_pat_maybe pats
- where
- var_from_pat_maybe (VarPat var) = returnDs var
- var_from_pat_maybe (AsPat var pat) = returnDs var
- var_from_pat_maybe (LazyPat pat) = var_from_pat_maybe pat
- var_from_pat_maybe other_pat
- = newSysLocalDs (outPatType other_pat) -- OK, better make up one...
-\end{code}
-
-\begin{code}
-mkTupleBind :: [TyVar] -- Abstract wrt these...
- -> [DictVar] -- ... and these
-
- -> [(Id, Id)] -- Local, global pairs, equal in number
- -- to the size of the tuple. The types
- -- of the globals is the generalisation of
- -- the corresp local, wrt the tyvars and dicts
-
- -> CoreExpr -- Expr whose value is a tuple; the expression
- -- may mention the tyvars and dicts