X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2FdeSugar%2FMatchCon.lhs;h=4e9ee8e3f7c567895b0cc861cdb751e29a2d1190;hb=a385f0af5ea320a18d580f6a36c59c55b3516efd;hp=5233d590373c50488132b36a07232505a35a5c09;hpb=49c98d143c382a1341e1046f5ca00819a25691ba;p=ghc-hetmet.git diff --git a/compiler/deSugar/MatchCon.lhs b/compiler/deSugar/MatchCon.lhs index 5233d59..4e9ee8e 100644 --- a/compiler/deSugar/MatchCon.lhs +++ b/compiler/deSugar/MatchCon.lhs @@ -6,6 +6,13 @@ Pattern-matching constructors \begin{code} +{-# OPTIONS -fno-warn-incomplete-patterns #-} +-- The above warning supression flag is a temporary kludge. +-- While working on this module you are encouraged to remove it and fix +-- any warnings in the module. See +-- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings +-- for details + module MatchCon ( matchConFamily ) where #include "HsVersions.h" @@ -20,8 +27,9 @@ import Type import CoreSyn import DsMonad import DsUtils - +import Util ( takeList ) import Id +import Var (TyVar) import SrcLoc import Outputable \end{code} @@ -86,23 +94,29 @@ matchConFamily (var:vars) ty groups = do { alts <- mapM (matchOneCon vars ty) groups ; return (mkCoAlgCaseMatchResult var ty alts) } +matchOneCon :: [Id] + -> Type + -> [EquationInfo] + -> DsM (DataCon, [TyVar], MatchResult) matchOneCon vars ty (eqn1 : eqns) -- All eqns for a single constructor = do { (wraps, eqns') <- mapAndUnzipM shift (eqn1:eqns) - ; arg_vars <- selectMatchVars (take (dataConSourceArity con) + ; arg_vars <- selectMatchVars (take (dataConSourceArity con1) (eqn_pats (head eqns'))) -- Use the new arugment patterns as a source of -- suggestions for the new variables ; match_result <- match (arg_vars ++ vars) ty eqns' - ; return (con, tvs1 ++ dicts1 ++ arg_vars, + ; return (con1, tvs1 ++ dicts1 ++ arg_vars, adjustMatchResult (foldr1 (.) wraps) match_result) } where - ConPatOut { pat_con = L _ con, pat_ty = pat_ty1, + ConPatOut { pat_con = L _ con1, pat_ty = pat_ty1, pat_tvs = tvs1, pat_dicts = dicts1 } = firstPat eqn1 - arg_tys = dataConInstOrigArgTys con inst_tys - n_co_args = length (dataConEqSpec con) - inst_tys = tcTyConAppArgs pat_ty1 ++ (drop n_co_args $ mkTyVarTys tvs1) + arg_tys = dataConInstOrigArgTys con1 inst_tys + inst_tys = tcTyConAppArgs pat_ty1 ++ + mkTyVarTys (takeList (dataConExTyVars con1) tvs1) -- Newtypes opaque, hence tcTyConAppArgs + -- dataConInstOrigArgTys takes the univ and existential tyvars + -- and returns the types of the *value* args, which is what we want shift eqn@(EqnInfo { eqn_pats = ConPatOut{ pat_tvs = tvs, pat_dicts = ds, pat_binds = bind, pat_args = args @@ -111,15 +125,17 @@ matchOneCon vars ty (eqn1 : eqns) -- All eqns for a single constructor ; return (wrapBinds (tvs `zip` tvs1) . wrapBinds (ds `zip` dicts1) . mkDsLet (Rec prs), - eqn { eqn_pats = conArgPats con arg_tys args ++ pats }) } + eqn { eqn_pats = conArgPats con1 arg_tys args ++ pats }) } conArgPats :: DataCon -> [Type] -- Instantiated argument types - -> HsConDetails Id (LPat Id) + -- Used only to fill in the types of WildPats, which + -- are probably never looked at anyway + -> HsConDetails (LPat Id) (HsRecFields Id (LPat Id)) -> [Pat Id] -conArgPats data_con arg_tys (PrefixCon ps) = map unLoc ps -conArgPats data_con arg_tys (InfixCon p1 p2) = [unLoc p1, unLoc p2] -conArgPats data_con arg_tys (RecCon rpats) +conArgPats _data_con _arg_tys (PrefixCon ps) = map unLoc ps +conArgPats _data_con _arg_tys (InfixCon p1 p2) = [unLoc p1, unLoc p2] +conArgPats data_con arg_tys (RecCon (HsRecFields rpats _)) | null rpats = -- Special case for C {}, which can be used for -- a constructor that isn't declared to have