5 \section[MatchProcessors]{Pattern-matching processors}
11 #include "HsVersions.h"
13 import AbsSyn -- the stuff being desugared
14 import PlainCore -- the output of desugaring;
15 -- importing this module also gets all the
16 -- CoreSyn utility functions
17 import DsMonad -- the monadery used in the desugarer
19 import AbsUniType ( mkTyVarTy, splitType, mkProcessorTyCon,
20 TyVar, TyCon, Class, UniType,
23 import DsUtils ( EquationInfo(..), selectMatchVars )
24 import Id ( getDataConFamily, getDataConTyCon,
25 getIdUniType, mkProcessorCon
27 import ListSetOps ( minusList )
28 import Maybes ( Maybe(..) )
29 import Match ( match )
31 import DsExpr ( dsExpr)
34 The matching of processors is based upon that of constructors. Given the
40 The pattern matching compiler converts the above into :
43 (|u1,..un;uy|) -> let x1 = fromDomain u_1 of
45 let xn = fromDomain u_n of
46 let y = fromDomain uy of
51 matchProcessor :: [Id]
56 matchProcessor (v:vs) eqnInfo ifFail
57 = selectMatchVars [pat] `thenDs` (\ [var] ->
58 selectMatchVars pats `thenDs` (\ vars ->
61 ifFail `thenDs` (\ body ->
62 create_lets vars pats convs body ifFail `thenDs` (\ rhs ->
67 [((mkProcessorCon podSize),vars++[var], rhs)]
71 podSize = (length pats)
72 -- Sanity checking pattern match. Product type of processors ensures
73 -- there can be only one result if the equations are properly unmixed.
74 ((ProcessorPat pats convs pat):ps,after_fun)
75 | length eqnInfo == 1 = head eqnInfo
76 | otherwise = panic "matchProcessor more than one"
88 create_lets [] _ _ body _ = returnDs (body)
89 create_lets (v:vs) (p:ps) (c:cs) body ifFail
90 = selectMatchVars [p] `thenDs` (\ var ->
91 create_lets vs ps cs body ifFail `thenDs` (\ after ->
92 dsExpr c `thenDs` (\ c' ->
95 ifFail `thenDs` (\ exp ->
96 returnDs ( CoApp (CoLam var exp) (CoApp c' (CoVar v))) ))))