summaryrefslogtreecommitdiff
path: root/compiler/types
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2012-07-14 13:12:59 +0100
committerSimon Peyton Jones <simonpj@microsoft.com>2012-07-14 13:12:59 +0100
commitbf63a08a07b0d82f494ff5f68dfef2b070a2ea0d (patch)
treeefe7cd4211842e4383f7570b868253a15e7cbfbe /compiler/types
parent3b9be226397535492a08cd4f25d5f672d245385b (diff)
downloadhaskell-bf63a08a07b0d82f494ff5f68dfef2b070a2ea0d.tar.gz
Comments about associated type tyvar naming
Diffstat (limited to 'compiler/types')
-rw-r--r--compiler/types/Class.lhs25
1 files changed, 21 insertions, 4 deletions
diff --git a/compiler/types/Class.lhs b/compiler/types/Class.lhs
index 136ecec81a..c70f16dbc6 100644
--- a/compiler/types/Class.lhs
+++ b/compiler/types/Class.lhs
@@ -96,10 +96,8 @@ data DefMeth = NoDefMeth -- No default method
| GenDefMeth Name -- A generic default method
deriving Eq
-type ClassATItem = (TyCon, [ATDefault])
- -- Default associated types from these templates. If the template list is empty,
- -- we assume that there is no default -- not that the default is to generate no
- -- instances (this only makes a difference for warnings).
+type ClassATItem = (TyCon, -- See Note [Associated type tyvar names]
+ [ATDefault]) -- Default associated types from these templates
-- We can have more than one default per type; see
-- Note [Associated type defaults] in TcTyClsDecls
@@ -149,6 +147,25 @@ mkClass tyvars fds super_classes superdict_sels at_stuff
classTyCon = tycon }
\end{code}
+Note [Associated type tyvar names]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+The TyCon of an associated type should use the same variable names as its
+parent class. Thus
+ class C a b where
+ type F b x a :: *
+We make F use the same Name for 'a' as C does, and similary 'b'.
+
+The only reason for this is when checking instances it's easier to match
+them up, to ensure they match. Eg
+ instance C Int [d] where
+ type F [d] x Int = ....
+we should make sure that the first and third args match the instance
+header.
+
+This is the reason we use the Name and TyVar from the parent declaration,
+in both class and instance decls: just to make this check easier.
+
+
%************************************************************************
%* *
\subsection[Class-selectors]{@Class@: simple selectors}