X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2FdeSugar%2FMatchCon.lhs;h=ed9f2c12047264a35a9817b3bc2c528dd8905f3f;hb=8a2809c29de9f23eba7ca682b48390033a9d40f6;hp=2612b503db616415768d768e8346694acf05a16a;hpb=37507b3a4342773030ef538599363a5aff8b666a;p=ghc-hetmet.git diff --git a/compiler/deSugar/MatchCon.lhs b/compiler/deSugar/MatchCon.lhs index 2612b50..ed9f2c1 100644 --- a/compiler/deSugar/MatchCon.lhs +++ b/compiler/deSugar/MatchCon.lhs @@ -1,7 +1,9 @@ - +% +% (c) The University of Glasgow 2006 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998 % -\section[MatchCon]{Pattern-matching constructors} + +Pattern-matching constructors \begin{code} module MatchCon ( matchConFamily ) where @@ -10,19 +12,17 @@ module MatchCon ( matchConFamily ) where import {-# SOURCE #-} Match ( match ) -import HsSyn ( Pat(..), LPat, HsConDetails(..) ) -import DsBinds ( dsLHsBinds ) -import DataCon ( DataCon, dataConInstOrigArgTys, - dataConFieldLabels, dataConSourceArity ) -import TcType ( tcTyConAppArgs ) -import Type ( mkTyVarTys ) +import HsSyn +import DsBinds +import DataCon +import TcType +import Type import CoreSyn import DsMonad import DsUtils - -import Id ( Id, idName ) -import Type ( Type ) -import SrcLoc ( unLoc, Located(..) ) +import Util ( takeList ) +import Id +import SrcLoc import Outputable \end{code} @@ -88,20 +88,23 @@ matchConFamily (var:vars) ty groups 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 - inst_tys = tcTyConAppArgs pat_ty1 ++ 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 @@ -110,15 +113,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 (RecCon (HsRecFields rpats _)) | null rpats = -- Special case for C {}, which can be used for -- a constructor that isn't declared to have @@ -131,7 +136,7 @@ conArgPats data_con arg_tys (RecCon rpats) -- mk_pat picks a WildPat of the appropriate type for absent fields, -- and the specified pattern for present fields mk_pat lbl arg_ty - = case [ pat | (sel_id,pat) <- rpats, idName (unLoc sel_id) == lbl] of + = case [ pat | HsRecField sel_id pat _ <- rpats, idName (unLoc sel_id) == lbl ] of (pat:pats) -> ASSERT( null pats ) unLoc pat [] -> WildPat arg_ty \end{code}