Repository : ssh://darcs.haskell.org//srv/darcs/ghc On branch : master
http://hackage.haskell.org/trac/ghc/changeset/935fa10a2d9ec0bd4b0f69b3a73b62d382b19caa >--------------------------------------------------------------- commit 935fa10a2d9ec0bd4b0f69b3a73b62d382b19caa Author: Simon Peyton Jones <[email protected]> Date: Mon Oct 1 11:24:10 2012 +0100 Comments about silent superclasses >--------------------------------------------------------------- compiler/basicTypes/IdInfo.lhs | 2 +- compiler/typecheck/TcInstDcls.lhs | 12 ++++++++---- compiler/types/InstEnv.lhs | 5 +++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/compiler/basicTypes/IdInfo.lhs b/compiler/basicTypes/IdInfo.lhs index 93762ab..1d77789 100644 --- a/compiler/basicTypes/IdInfo.lhs +++ b/compiler/basicTypes/IdInfo.lhs @@ -142,7 +142,7 @@ data IdDetails -- instance C a => C [a] -- has is_silent = 1, because the dfun -- has type dfun :: (D a, C a) => C [a] - -- See the DFun Superclass Invariant in TcInstDcls + -- See Note [Silent superclass arguments] in TcInstDcls -- -- Bool = True <=> the class has only one method, so may be -- implemented with a newtype, so it might be bad diff --git a/compiler/typecheck/TcInstDcls.lhs b/compiler/typecheck/TcInstDcls.lhs index 2e62cd7..b4a27b5 100644 --- a/compiler/typecheck/TcInstDcls.lhs +++ b/compiler/typecheck/TcInstDcls.lhs @@ -947,7 +947,7 @@ immediate superclasses of the dictionary we are trying to construct. In our example: dfun :: forall a. C [a] -> D [a] -> D [a] dfun = \(dc::C [a]) (dd::D [a]) -> DOrd dc ... -Notice teh extra (dc :: C [a]) argument compared to the previous version. +Notice the extra (dc :: C [a]) argument compared to the previous version. This gives us: @@ -967,9 +967,13 @@ dictionary constructor). No superclass is hidden inside a dfun application. The extra arguments required to satisfy the DFun Superclass Invariant -always come first, and are called the "silent" arguments. DFun types -are built (only) by MkId.mkDictFunId, so that is where we decide -what silent arguments are to be added. +always come first, and are called the "silent" arguments. You can +find out how many silent arguments there are using Id.dfunNSilent; +and then you can just drop that number of arguments to see the ones +that were in the original instance declaration. + +DFun types are built (only) by MkId.mkDictFunId, so that is where we +decide what silent arguments are to be added. In our example, if we had [Wanted] dw :: D [a] we would get via the instance: dw := dfun d1 d2 diff --git a/compiler/types/InstEnv.lhs b/compiler/types/InstEnv.lhs index 388846b..f99b0a1 100644 --- a/compiler/types/InstEnv.lhs +++ b/compiler/types/InstEnv.lhs @@ -61,6 +61,10 @@ data ClsInst -- forall is_tvs. (...) => is_cls is_tys , is_dfun :: DFunId -- See Note [Haddock assumptions] + -- See Note [Silent superclass arguments] in TcInstDcls + -- for how to map the DFun's type back to the source + -- language instance decl + , is_flag :: OverlapFlag -- See detailed comments with -- the decl of BasicTypes.OverlapFlag } @@ -159,6 +163,7 @@ pprInstanceHdr (ClsInst { is_flag = flag, is_dfun = dfun }) let theta_to_print | debugStyle sty = theta | otherwise = drop (dfunNSilent dfun) theta + -- See Note [Silent superclass arguments] in TcInstDcls in ptext (sLit "instance") <+> ppr flag <+> sep [pprThetaArrowTy theta_to_print, ppr res_ty] where _______________________________________________ Cvs-ghc mailing list [email protected] http://www.haskell.org/mailman/listinfo/cvs-ghc
