2 % (c) The GRASP/AQUA Project, Glasgow University, 1997-1998
4 % Author: Juan J. Quintela <quintela@krilin.dc.fi.udc.es>
5 \section{Module @Check@ in @deSugar@}
10 module Check ( check , ExhaustivePat ) where
14 import TcHsSyn ( hsPatType )
15 import TcType ( tcTyConAppTyCon )
16 import DsUtils ( EquationInfo(..), MatchResult(..),
17 CanItFail(..), firstPat )
18 import MatchLit ( tidyLitPat, tidyNPat )
19 import Id ( Id, idType )
20 import DataCon ( DataCon, dataConTyCon, dataConOrigArgTys, dataConFieldLabels )
21 import Name ( Name, mkInternalName, getOccName, isDataSymOcc, getName, mkVarOcc )
23 import PrelNames ( unboundKey )
24 import TyCon ( tyConDataCons, tupleTyConBoxity, isTupleTyCon )
25 import BasicTypes ( Boxity(..) )
26 import SrcLoc ( noSrcLoc, Located(..), unLoc, noLoc )
28 import Util ( takeList, splitAtList, notNull )
32 #include "HsVersions.h"
35 This module performs checks about if one list of equations are:
40 To discover that we go through the list of equations in a tree-like fashion.
42 If you like theory, a similar algorithm is described in:
44 {\em Two Techniques for Compiling Lazy Pattern Matching},
46 INRIA Rocquencourt (RR-2385, 1994)
48 The algorithm is based on the first technique, but there are some differences:
50 \item We don't generate code
51 \item We have constructors and literals (not only literals as in the
53 \item We don't use directions, we must select the columns from
56 (By the way the second technique is really similar to the one used in
57 @Match.lhs@ to generate code)
59 This function takes the equations of a pattern and returns:
61 \item The patterns that are not recognized
62 \item The equations that are not overlapped
64 It simplify the patterns and then call @check'@ (the same semantics), and it
65 needs to reconstruct the patterns again ....
67 The problem appear with things like:
72 We want to put the two patterns with the same syntax, (prefix form) and
73 then all the constructors are equal:
75 f (: x (: y [])) = ....
78 (more about that in @simplify_eqns@)
80 We would prefer to have a @WarningPat@ of type @String@, but Strings and the
81 Pretty Printer are not friends.
83 We use @InPat@ in @WarningPat@ instead of @OutPat@
84 because we need to print the
85 warning messages in the same way they are introduced, i.e. if the user
90 He don't want a warning message written:
92 f (: x (: y [])) ........
94 Then we need to use InPats.
96 Juan Quintela 5 JUL 1998\\
97 User-friendliness and compiler writers are no friends.
101 type WarningPat = InPat Name
102 type ExhaustivePat = ([WarningPat], [(Name, [HsLit])])
104 type EqnSet = UniqSet EqnNo
107 check :: [EquationInfo] -> ([ExhaustivePat], [EquationInfo])
108 -- Second result is the shadowed equations
109 check qs = (untidy_warns, shadowed_eqns)
111 (warns, used_nos) = check' ([1..] `zip` map simplify_eqn qs)
112 untidy_warns = map untidy_exhaustive warns
113 shadowed_eqns = [eqn | (eqn,i) <- qs `zip` [1..],
114 not (i `elementOfUniqSet` used_nos)]
116 untidy_exhaustive :: ExhaustivePat -> ExhaustivePat
117 untidy_exhaustive ([pat], messages) =
118 ([untidy_no_pars pat], map untidy_message messages)
119 untidy_exhaustive (pats, messages) =
120 (map untidy_pars pats, map untidy_message messages)
122 untidy_message :: (Name, [HsLit]) -> (Name, [HsLit])
123 untidy_message (string, lits) = (string, map untidy_lit lits)
126 The function @untidy@ does the reverse work of the @simplify_pat@ funcion.
132 untidy_no_pars :: WarningPat -> WarningPat
133 untidy_no_pars p = untidy False p
135 untidy_pars :: WarningPat -> WarningPat
136 untidy_pars p = untidy True p
138 untidy :: NeedPars -> WarningPat -> WarningPat
139 untidy b (L loc p) = L loc (untidy' b p)
141 untidy' _ p@(WildPat _) = p
142 untidy' _ p@(VarPat name) = p
143 untidy' _ (LitPat lit) = LitPat (untidy_lit lit)
144 untidy' _ p@(ConPatIn name (PrefixCon [])) = p
145 untidy' b (ConPatIn name ps) = pars b (L loc (ConPatIn name (untidy_con ps)))
146 untidy' _ (ListPat pats ty) = ListPat (map untidy_no_pars pats) ty
147 untidy' _ (TuplePat pats boxed) = TuplePat (map untidy_no_pars pats) boxed
148 untidy' _ (PArrPat _ _) = panic "Check.untidy: Shouldn't get a parallel array here!"
149 untidy' _ (SigPatIn _ _) = panic "Check.untidy: SigPat"
151 untidy_con (PrefixCon pats) = PrefixCon (map untidy_pars pats)
152 untidy_con (InfixCon p1 p2) = InfixCon (untidy_pars p1) (untidy_pars p2)
153 untidy_con (RecCon bs) = RecCon [(f,untidy_pars p) | (f,p) <- bs]
155 pars :: NeedPars -> WarningPat -> Pat Name
156 pars True p = ParPat p
159 untidy_lit :: HsLit -> HsLit
160 untidy_lit (HsCharPrim c) = HsChar c
164 This equation is the same that check, the only difference is that the
165 boring work is done, that work needs to be done only once, this is
166 the reason top have two functions, check is the external interface,
167 @check'@ is called recursively.
169 There are several cases:
172 \item There are no equations: Everything is OK.
173 \item There are only one equation, that can fail, and all the patterns are
174 variables. Then that equation is used and the same equation is
176 \item All the patterns are variables, and the match can fail, there are
177 more equations then the results is the result of the rest of equations
178 and this equation is used also.
180 \item The general case, if all the patterns are variables (here the match
181 can't fail) then the result is that this equation is used and this
182 equation doesn't generate non-exhaustive cases.
184 \item In the general case, there can exist literals ,constructors or only
185 vars in the first column, we actuate in consequence.
192 check' :: [(EqnNo, EquationInfo)] -> ([ExhaustivePat], EqnSet)
193 check' [] = ([([],[])],emptyUniqSet)
195 check' [(n, EqnInfo { eqn_pats = ps, eqn_rhs = MatchResult CanFail _ })]
196 | all_vars ps = ([(takeList ps (repeat nlWildPat),[])], unitUniqSet n)
198 check' ((n, EqnInfo { eqn_pats = ps, eqn_rhs = MatchResult CanFail _}) : rs)
199 | all_vars ps = (pats, addOneToUniqSet indexs n)
201 (pats,indexs) = check' rs
203 check' qs@((n, EqnInfo { eqn_pats = ps }) : _)
204 | all_vars ps = ([], unitUniqSet n)
205 | literals = split_by_literals qs
206 | constructors = split_by_constructor qs
207 | only_vars = first_column_only_vars qs
208 | otherwise = pprPanic "Check.check': Not implemented :-(" (ppr first_pats)
210 -- Note: RecPats will have been simplified to ConPats
212 first_pats = ASSERT2( okGroup qs, pprGroup qs ) map firstPatN qs
213 constructors = any is_con first_pats
214 literals = any is_lit first_pats
215 only_vars = all is_var first_pats
218 Here begins the code to deal with literals, we need to split the matrix
219 in different matrix beginning by each literal and a last matrix with the
223 split_by_literals :: [(EqnNo, EquationInfo)] -> ([ExhaustivePat], EqnSet)
224 split_by_literals qs = process_literals used_lits qs
226 used_lits = get_used_lits qs
229 @process_explicit_literals@ is a function that process each literal that appears
230 in the column of the matrix.
233 process_explicit_literals :: [HsLit] -> [(EqnNo, EquationInfo)] -> ([ExhaustivePat],EqnSet)
234 process_explicit_literals lits qs = (concat pats, unionManyUniqSets indexs)
236 pats_indexs = map (\x -> construct_literal_matrix x qs) lits
237 (pats,indexs) = unzip pats_indexs
241 @process_literals@ calls @process_explicit_literals@ to deal with the literals
242 that appears in the matrix and deal also with the rest of the cases. It
243 must be one Variable to be complete.
247 process_literals :: [HsLit] -> [(EqnNo, EquationInfo)] -> ([ExhaustivePat],EqnSet)
248 process_literals used_lits qs
249 | null default_eqns = ([make_row_vars used_lits (head qs)] ++ pats,indexs)
250 | otherwise = (pats_default,indexs_default)
252 (pats,indexs) = process_explicit_literals used_lits qs
253 default_eqns = ASSERT2( okGroup qs, pprGroup qs )
254 [remove_var q | q <- qs, is_var (firstPatN q)]
255 (pats',indexs') = check' default_eqns
256 pats_default = [(nlWildPat:ps,constraints) | (ps,constraints) <- (pats')] ++ pats
257 indexs_default = unionUniqSets indexs' indexs
260 Here we have selected the literal and we will select all the equations that
261 begins for that literal and create a new matrix.
264 construct_literal_matrix :: HsLit -> [(EqnNo, EquationInfo)] -> ([ExhaustivePat],EqnSet)
265 construct_literal_matrix lit qs =
266 (map (\ (xs,ys) -> (new_lit:xs,ys)) pats,indexs)
268 (pats,indexs) = (check' (remove_first_column_lit lit qs))
269 new_lit = nlLitPat lit
271 remove_first_column_lit :: HsLit
272 -> [(EqnNo, EquationInfo)]
273 -> [(EqnNo, EquationInfo)]
274 remove_first_column_lit lit qs
275 = ASSERT2( okGroup qs, pprGroup qs )
276 [(n, shift_pat eqn) | q@(n,eqn) <- qs, is_var_lit lit (firstPatN q)]
278 shift_pat eqn@(EqnInfo { eqn_pats = _:ps}) = eqn { eqn_pats = ps }
279 shift_pat eqn@(EqnInfo { eqn_pats = []}) = panic "Check.shift_var: no patterns"
282 This function splits the equations @qs@ in groups that deal with the
286 split_by_constructor :: [(EqnNo, EquationInfo)] -> ([ExhaustivePat], EqnSet)
287 split_by_constructor qs
288 | notNull unused_cons = need_default_case used_cons unused_cons qs
289 | otherwise = no_need_default_case used_cons qs
291 used_cons = get_used_cons qs
292 unused_cons = get_unused_cons used_cons
295 The first column of the patterns matrix only have vars, then there is
299 first_column_only_vars :: [(EqnNo, EquationInfo)] -> ([ExhaustivePat],EqnSet)
300 first_column_only_vars qs = (map (\ (xs,ys) -> (nlWildPat:xs,ys)) pats,indexs)
302 (pats, indexs) = check' (map remove_var qs)
305 This equation takes a matrix of patterns and split the equations by
306 constructor, using all the constructors that appears in the first column
307 of the pattern matching.
309 We can need a default clause or not ...., it depends if we used all the
310 constructors or not explicitly. The reasoning is similar to @process_literals@,
311 the difference is that here the default case is not always needed.
314 no_need_default_case :: [Pat Id] -> [(EqnNo, EquationInfo)] -> ([ExhaustivePat],EqnSet)
315 no_need_default_case cons qs = (concat pats, unionManyUniqSets indexs)
317 pats_indexs = map (\x -> construct_matrix x qs) cons
318 (pats,indexs) = unzip pats_indexs
320 need_default_case :: [Pat Id] -> [DataCon] -> [(EqnNo, EquationInfo)] -> ([ExhaustivePat],EqnSet)
321 need_default_case used_cons unused_cons qs
322 | null default_eqns = (pats_default_no_eqns,indexs)
323 | otherwise = (pats_default,indexs_default)
325 (pats,indexs) = no_need_default_case used_cons qs
326 default_eqns = ASSERT2( okGroup qs, pprGroup qs )
327 [remove_var q | q <- qs, is_var (firstPatN q)]
328 (pats',indexs') = check' default_eqns
329 pats_default = [(make_whole_con c:ps,constraints) |
330 c <- unused_cons, (ps,constraints) <- pats'] ++ pats
331 new_wilds = make_row_vars_for_constructor (head qs)
332 pats_default_no_eqns = [(make_whole_con c:new_wilds,[]) | c <- unused_cons] ++ pats
333 indexs_default = unionUniqSets indexs' indexs
335 construct_matrix :: Pat Id -> [(EqnNo, EquationInfo)] -> ([ExhaustivePat],EqnSet)
336 construct_matrix con qs =
337 (map (make_con con) pats,indexs)
339 (pats,indexs) = (check' (remove_first_column con qs))
342 Here remove first column is more difficult that with literals due to the fact
343 that constructors can have arguments.
345 For instance, the matrix
357 remove_first_column :: Pat Id -- Constructor
358 -> [(EqnNo, EquationInfo)]
359 -> [(EqnNo, EquationInfo)]
360 remove_first_column (ConPatOut (L _ con) _ _ _ (PrefixCon con_pats) _) qs
361 = ASSERT2( okGroup qs, pprGroup qs )
362 [(n, shift_var eqn) | q@(n, eqn) <- qs, is_var_con con (firstPatN q)]
364 new_wilds = [WildPat (hsPatType arg_pat) | arg_pat <- con_pats]
365 shift_var eqn@(EqnInfo { eqn_pats = ConPatOut _ _ _ _ (PrefixCon ps') _ : ps})
366 = eqn { eqn_pats = map unLoc ps' ++ ps }
367 shift_var eqn@(EqnInfo { eqn_pats = WildPat _ : ps })
368 = eqn { eqn_pats = new_wilds ++ ps }
369 shift_var _ = panic "Check.Shift_var:No done"
371 make_row_vars :: [HsLit] -> (EqnNo, EquationInfo) -> ExhaustivePat
372 make_row_vars used_lits (_, EqnInfo { eqn_pats = pats})
373 = (nlVarPat new_var:takeList (tail pats) (repeat nlWildPat),[(new_var,used_lits)])
377 hash_x = mkInternalName unboundKey {- doesn't matter much -}
378 (mkVarOcc FSLIT("#x"))
381 make_row_vars_for_constructor :: (EqnNo, EquationInfo) -> [WarningPat]
382 make_row_vars_for_constructor (_, EqnInfo { eqn_pats = pats})
383 = takeList (tail pats) (repeat nlWildPat)
385 compare_cons :: Pat Id -> Pat Id -> Bool
386 compare_cons (ConPatOut (L _ id1) _ _ _ _ _) (ConPatOut (L _ id2) _ _ _ _ _) = id1 == id2
388 remove_dups :: [Pat Id] -> [Pat Id]
390 remove_dups (x:xs) | or (map (\y -> compare_cons x y) xs) = remove_dups xs
391 | otherwise = x : remove_dups xs
393 get_used_cons :: [(EqnNo, EquationInfo)] -> [Pat Id]
394 get_used_cons qs = remove_dups [pat | q <- qs, let pat = firstPatN q,
397 isConPatOut (ConPatOut {}) = True
398 isConPatOut other = False
400 remove_dups' :: [HsLit] -> [HsLit]
402 remove_dups' (x:xs) | x `elem` xs = remove_dups' xs
403 | otherwise = x : remove_dups' xs
406 get_used_lits :: [(EqnNo, EquationInfo)] -> [HsLit]
407 get_used_lits qs = remove_dups' all_literals
409 all_literals = get_used_lits' qs
411 get_used_lits' :: [(EqnNo, EquationInfo)] -> [HsLit]
412 get_used_lits' [] = []
413 get_used_lits' (q:qs)
414 | LitPat lit <- first_pat = lit : get_used_lits qs
415 | NPat lit _ _ _ <- first_pat = over_lit_lit lit : get_used_lits qs
416 | otherwise = get_used_lits qs
418 first_pat = firstPatN q
420 over_lit_lit :: HsOverLit id -> HsLit
421 -- Get a representative HsLit to stand for the OverLit
422 -- It doesn't matter which one, because they will only be compared
423 -- with other HsLits gotten in the same way
424 over_lit_lit (HsIntegral i _) = HsIntPrim i
425 over_lit_lit (HsFractional f _) = HsFloatPrim f
427 get_unused_cons :: [Pat Id] -> [DataCon]
428 get_unused_cons used_cons = unused_cons
430 (ConPatOut _ _ _ _ _ ty) = head used_cons
431 ty_con = tcTyConAppTyCon ty -- Newtype observable
432 all_cons = tyConDataCons ty_con
433 used_cons_as_id = map (\ (ConPatOut (L _ d) _ _ _ _ _) -> d) used_cons
434 unused_cons = uniqSetToList
435 (mkUniqSet all_cons `minusUniqSet` mkUniqSet used_cons_as_id)
437 all_vars :: [Pat Id] -> Bool
439 all_vars (WildPat _:ps) = all_vars ps
442 remove_var :: (EqnNo, EquationInfo) -> (EqnNo, EquationInfo)
443 remove_var (n, eqn@(EqnInfo { eqn_pats = WildPat _ : ps})) = (n, eqn { eqn_pats = ps })
444 remove_var _ = panic "Check.remove_var: equation does not begin with a variable"
446 -----------------------
447 eqnPats :: (EqnNo, EquationInfo) -> [Pat Id]
448 eqnPats (_, eqn) = eqn_pats eqn
450 okGroup :: [(EqnNo, EquationInfo)] -> Bool
451 -- True if all equations have at least one pattern, and
452 -- all have the same number of patterns
454 okGroup (e:es) = n_pats > 0 && and [length (eqnPats e) == n_pats | e <- es]
456 n_pats = length (eqnPats e)
459 pprGroup es = vcat (map pprEqnInfo es)
460 pprEqnInfo e = ppr (eqnPats e)
463 firstPatN :: (EqnNo, EquationInfo) -> Pat Id
464 firstPatN (_, eqn) = firstPat eqn
466 is_con :: Pat Id -> Bool
467 is_con (ConPatOut _ _ _ _ _ _) = True
470 is_lit :: Pat Id -> Bool
471 is_lit (LitPat _) = True
472 is_lit (NPat _ _ _ _) = True
475 is_var :: Pat Id -> Bool
476 is_var (WildPat _) = True
479 is_var_con :: DataCon -> Pat Id -> Bool
480 is_var_con con (WildPat _) = True
481 is_var_con con (ConPatOut (L _ id) _ _ _ _ _) | id == con = True
482 is_var_con con _ = False
484 is_var_lit :: HsLit -> Pat Id -> Bool
485 is_var_lit lit (WildPat _) = True
486 is_var_lit lit (LitPat lit') = lit == lit'
487 is_var_lit lit (NPat lit' _ _ _) = lit == over_lit_lit lit'
488 is_var_lit lit _ = False
491 The difference beteewn @make_con@ and @make_whole_con@ is that
492 @make_wole_con@ creates a new constructor with all their arguments, and
493 @make_con@ takes a list of argumntes, creates the contructor getting their
494 arguments from the list. See where \fbox{\ ???\ } are used for details.
496 We need to reconstruct the patterns (make the constructors infix and
497 similar) at the same time that we create the constructors.
499 You can tell tuple constructors using
503 You can see if one constructor is infix with this clearer code :-))))))))))
505 Lex.isLexConSym (Name.occNameString (Name.getOccName con))
508 Rather clumsy but it works. (Simon Peyton Jones)
511 We don't mind the @nilDataCon@ because it doesn't change the way to
512 print the messsage, we are searching only for things like: @[1,2,3]@,
515 In @reconstruct_pat@ we want to ``undo'' the work
516 that we have done in @simplify_pat@.
519 @((,) x y)@ & returns to be & @(x, y)@
520 \\ @((:) x xs)@ & returns to be & @(x:xs)@
521 \\ @(x:(...:[])@ & returns to be & @[x,...]@
524 The difficult case is the third one becouse we need to follow all the
525 contructors until the @[]@ to know that we need to use the second case,
526 not the second. \fbox{\ ???\ }
529 isInfixCon con = isDataSymOcc (getOccName con)
531 is_nil (ConPatIn con (PrefixCon [])) = unLoc con == getName nilDataCon
534 is_list (ListPat _ _) = True
537 return_list id q = id == consDataCon && (is_nil q || is_list q)
539 make_list p q | is_nil q = ListPat [p] placeHolderType
540 make_list p (ListPat ps ty) = ListPat (p:ps) ty
541 make_list _ _ = panic "Check.make_list: Invalid argument"
543 make_con :: Pat Id -> ExhaustivePat -> ExhaustivePat
544 make_con (ConPatOut (L _ id) _ _ _ _ _) (lp:lq:ps, constraints)
545 | return_list id q = (noLoc (make_list lp q) : ps, constraints)
546 | isInfixCon id = (nlInfixConPat (getName id) lp lq : ps, constraints)
549 make_con (ConPatOut (L _ id) _ _ _ (PrefixCon pats) _) (ps, constraints)
550 | isTupleTyCon tc = (noLoc (TuplePat pats_con (tupleTyConBoxity tc)) : rest_pats, constraints)
551 | isPArrFakeCon id = (noLoc (PArrPat pats_con placeHolderType) : rest_pats, constraints)
552 | otherwise = (nlConPat name pats_con : rest_pats, constraints)
555 (pats_con, rest_pats) = splitAtList pats ps
558 -- reconstruct parallel array pattern
560 -- * don't check for the type only; we need to make sure that we are really
561 -- dealing with one of the fake constructors and not with the real
564 make_whole_con :: DataCon -> WarningPat
565 make_whole_con con | isInfixCon con = nlInfixConPat name nlWildPat nlWildPat
566 | otherwise = nlConPat name pats
569 pats = [nlWildPat | t <- dataConOrigArgTys con]
572 This equation makes the same thing as @tidy@ in @Match.lhs@, the
573 difference is that here we can do all the tidy in one place and in the
574 @Match@ tidy it must be done one column each time due to bookkeeping
579 simplify_eqn :: EquationInfo -> EquationInfo
580 simplify_eqn eqn = eqn { eqn_pats = map simplify_pat (eqn_pats eqn) }
582 simplify_lpat :: LPat Id -> LPat Id
583 simplify_lpat p = fmap simplify_pat p
585 simplify_pat :: Pat Id -> Pat Id
586 simplify_pat pat@(WildPat gt) = pat
587 simplify_pat (VarPat id) = WildPat (idType id)
588 simplify_pat (VarPatOut id _) = WildPat (idType id) -- Ignore the bindings
589 simplify_pat (ParPat p) = unLoc (simplify_lpat p)
590 simplify_pat (LazyPat p) = unLoc (simplify_lpat p)
591 simplify_pat (AsPat id p) = unLoc (simplify_lpat p)
592 simplify_pat (SigPatOut p _) = unLoc (simplify_lpat p) -- I'm not sure this is right
594 simplify_pat (ConPatOut (L loc id) tvs dicts binds ps ty)
595 = ConPatOut (L loc id) tvs dicts binds (simplify_con id ps) ty
597 simplify_pat (ListPat ps ty) =
598 unLoc $ foldr (\ x y -> mkPrefixConPat consDataCon [x,y] list_ty)
600 (map simplify_lpat ps)
601 where list_ty = mkListTy ty
603 -- introduce fake parallel array constructors to be able to handle parallel
604 -- arrays with the existing machinery for constructor pattern
606 simplify_pat (PArrPat ps ty)
607 = mk_simple_con_pat (parrFakeCon (length ps))
608 (PrefixCon (map simplify_lpat ps))
611 simplify_pat (TuplePat ps boxity)
612 = mk_simple_con_pat (tupleCon boxity arity)
613 (PrefixCon (map simplify_lpat ps))
614 (mkTupleTy boxity arity (map hsPatType ps))
618 -- unpack string patterns fully, so we can see when they overlap with
619 -- each other, or even explicit lists of Chars.
620 simplify_pat pat@(LitPat (HsString s)) =
621 foldr (\c pat -> mk_simple_con_pat consDataCon (PrefixCon [mk_char_lit c,noLoc pat]) stringTy)
622 (mk_simple_con_pat nilDataCon (PrefixCon []) stringTy) (unpackFS s)
624 mk_char_lit c = noLoc (mk_simple_con_pat charDataCon (PrefixCon [nlLitPat (HsCharPrim c)]) charTy)
626 simplify_pat pat@(LitPat lit) = unLoc (tidyLitPat lit (noLoc pat))
628 simplify_pat pat@(NPat lit mb_neg _ lit_ty) = unLoc (tidyNPat lit mb_neg lit_ty (noLoc pat))
630 simplify_pat (NPlusKPat id hslit hsexpr1 hsexpr2)
631 = WildPat (idType (unLoc id))
633 simplify_pat (DictPat dicts methods)
634 = case num_of_d_and_ms of
635 0 -> simplify_pat (TuplePat [] Boxed)
636 1 -> simplify_pat (head dict_and_method_pats)
637 _ -> simplify_pat (TuplePat (map noLoc dict_and_method_pats) Boxed)
639 num_of_d_and_ms = length dicts + length methods
640 dict_and_method_pats = map VarPat (dicts ++ methods)
642 mk_simple_con_pat con args ty = ConPatOut (noLoc con) [] [] emptyLHsBinds args ty
645 simplify_con con (PrefixCon ps) = PrefixCon (map simplify_lpat ps)
646 simplify_con con (InfixCon p1 p2) = PrefixCon [simplify_lpat p1, simplify_lpat p2]
647 simplify_con con (RecCon fs)
648 | null fs = PrefixCon [nlWildPat | t <- dataConOrigArgTys con]
649 -- Special case for null patterns; maybe not a record at all
650 | otherwise = PrefixCon (map (simplify_lpat.snd) all_pats)
652 -- pad out all the missing fields with WildPats.
653 field_pats = map (\ f -> (f, nlWildPat)) (dataConFieldLabels con)
654 all_pats = foldr (\ (id,p) acc -> insertNm (getName (unLoc id)) p acc)
657 insertNm nm p [] = [(nm,p)]
658 insertNm nm p (x@(n,_):xs)
659 | nm == n = (nm,p):xs
660 | otherwise = x : insertNm nm p xs