Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Tobias Decking
GHC
Commits
3c85beaf
Commit
3c85beaf
authored
Apr 22, 2003
by
simonpj
Browse files
[project @ 2003-04-22 11:44:17 by simonpj]
Fix the context for derived Typeable instances
parent
fcda69ed
Changes
1
Hide whitespace changes
Inline
Side-by-side
ghc/compiler/typecheck/TcDeriv.lhs
View file @
3c85beaf
...
...
@@ -46,7 +46,8 @@ import TyCon ( tyConTyVars, tyConDataCons, tyConArity,
tyConTheta, maybeTyConSingleCon, isDataTyCon,
isEnumerationTyCon, isRecursiveTyCon, TyCon
)
import TcType ( TcType, ThetaType, mkTyVarTys, mkTyConApp, getClassPredTys_maybe,
import TcType ( TcType, ThetaType, mkTyVarTy, mkTyVarTys, mkTyConApp,
getClassPredTys_maybe,
isUnLiftedType, mkClassPred, tyVarsOfTypes, tcSplitFunTys, isTypeKind,
tcEqTypes, tcSplitAppTys, mkAppTys, tcSplitDFunTy )
import Var ( TyVar, tyVarKind, idType, varName )
...
...
@@ -340,19 +341,29 @@ makeDerivEqns tycl_decls
where
tyvars = tyConTyVars tycon
data_cons = tyConDataCons tycon
constraints = extra_constraints ++
[ mkClassPred clas [arg_ty]
| data_con <- tyConDataCons tycon,
arg_ty <- dataConOrigArgTys data_con,
-- Use the same type variables
-- as the type constructor,
-- hence no need to instantiate
not (isUnLiftedType arg_ty) -- No constraints for unlifted types?
]
-- "extra_constraints": see note [Data decl contexts] above
constraints = extra_constraints ++ ordinary_constraints
-- "extra_constraints": see note [Data decl contexts] above
extra_constraints = tyConTheta tycon
ordinary_constraints
| clas `hasKey` typeableClassKey -- For the Typeable class, the constraints
-- don't involve the constructor ags, only
-- the tycon tyvars
-- e.g. data T a b = ...
-- we want
-- instance (Typeable a, Typable b)
-- => Typeable (T a b) where
= [mkClassPred clas [mkTyVarTy tv] | tv <- tyvars]
| otherwise
= [ mkClassPred clas [arg_ty]
| data_con <- tyConDataCons tycon,
arg_ty <- dataConOrigArgTys data_con,
-- Use the same type variables
-- as the type constructor,
-- hence no need to instantiate
not (isUnLiftedType arg_ty) -- No constraints for unlifted types?
]
mk_eqn_help gla_exts NewType tycon clas tys
| can_derive_via_isomorphism && (gla_exts || standard_class gla_exts clas)
= -- Go ahead and use the isomorphism
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment