\begin{code}
mkDataTypeEqn orig gla_exts tvs cls cls_tys tycon tc_args rep_tc rep_tc_args
| Just err <- checkSideConditions gla_exts cls cls_tys rep_tc
+ -- NB: pass the *representation* tycon to checkSideConditions
= baleOut (derivingThingErr cls cls_tys (mkTyConApp tycon tc_args) err)
| otherwise
(dataClassKey, cond_glaExts `andCond` cond_std)
]
-type Condition = (Bool, TyCon) -> Maybe SDoc -- Nothing => OK
+type Condition = (Bool, TyCon) -> Maybe SDoc
+ -- Bool is gla-exts flag
+ -- TyCon is the *representation* tycon if the
+ -- data type is an indexed one
+ -- Nothing => OK
orCond :: Condition -> Condition -> Condition
orCond c1 c2 tc
-- using the isomorphism trick *even if no -fglasgow-exts*
= classKey clas `elem` [eqClassKey, ordClassKey, ixClassKey, boundedClassKey]
-- Not Read/Show because they respect the type
- -- Not Enum, becuase newtypes are never in Enum
+ -- Not Enum, because newtypes are never in Enum
new_dfun_name clas tycon -- Just a simple wrapper
; setGblEnv env' thing_inside }
\end{code}
+Note [Deriving context]
+~~~~~~~~~~~~~~~~~~~~~~~
+With -fglasgow-exts, we allow things like (C Int a) in the simplified
+context for a derived instance declaration, because at a use of this
+instance, we might know that a=Bool, and have an instance for (C Int
+Bool)
+
+We nevertheless insist that each predicate meets the termination
+conditions. If not, the deriving mechanism generates larger and larger
+constraints. Example:
+ data Succ a = S a
+ data Seq a = Cons a (Seq (Succ a)) | Nil deriving Show
+
+Note the lack of a Show instance for Succ. First we'll generate
+ instance (Show (Succ a), Show a) => Show (Seq a)
+and then
+ instance (Show (Succ (Succ a)), Show (Succ a), Show a) => Show (Seq a)
+and so on. Instead we want to complain of no instance for (Show (Succ a)).
+
+
%************************************************************************
%* *
\subsection[TcDeriv-normal-binds]{Bindings for the various classes}