Safe Haskell | None |
---|---|
Language | GHC2021 |
The deriving code for the Functor, Foldable, and Traversable classes
Synopsis
- data FFoldType a = FT {}
- functorLikeTraverse :: TyVar -> FFoldType a -> Type -> a
- deepSubtypesContaining :: TyVar -> Type -> [TcType]
- foldDataConArgs :: FFoldType a -> DataCon -> DerivInstTys -> [a]
- gen_Functor_binds :: SrcSpan -> DerivInstTys -> (LHsBinds GhcPs, Bag AuxBindSpec)
- gen_Foldable_binds :: SrcSpan -> DerivInstTys -> (LHsBinds GhcPs, Bag AuxBindSpec)
- gen_Traversable_binds :: SrcSpan -> DerivInstTys -> (LHsBinds GhcPs, Bag AuxBindSpec)
Documentation
FT | |
|
deepSubtypesContaining :: TyVar -> Type -> [TcType] Source #
Return all syntactic subterms of a Type
that are applied to the TyVar
argument. This determines what constraints should be inferred for derived
Functor
, Foldable
, and Traversable
instances in GHC.Tc.Deriv.Infer.
For instance, if we have:
data Foo a = MkFoo Int a (Maybe a) (Either Int (Maybe a))
Then the following would hold:
would returndeepSubtypesContaining
a Int[]
, sinceInt
does not contain the type variablea
at all.
would returndeepSubtypesContaining
a a[]
. Although the typea
contains the type variablea
, it is not applied toa
, which is the criterion thatdeepSubtypesContaining
checks for.
would returndeepSubtypesContaining
a (Maybe a)[Maybe]
, asMaybe
is applied toa
.
would returndeepSubtypesContaining
a (Either Int (Maybe a))[Either Int, Maybe]
. Both of these types are applied toa
through composition.
As used in GHC.Tc.Deriv.Infer, the Type
argument will always come from
derivDataConInstArgTys
, so it is important that the TyVar
comes from
dataConUnivTyVars
to match. Make sure not to take the TyVar
from
tyConTyVars
, as these differ from the dataConUnivTyVars
when the data
type is a GADT. (See #22167 for what goes wrong if tyConTyVars
is used.)
foldDataConArgs :: FFoldType a -> DataCon -> DerivInstTys -> [a] Source #
gen_Functor_binds :: SrcSpan -> DerivInstTys -> (LHsBinds GhcPs, Bag AuxBindSpec) Source #
gen_Foldable_binds :: SrcSpan -> DerivInstTys -> (LHsBinds GhcPs, Bag AuxBindSpec) Source #
gen_Traversable_binds :: SrcSpan -> DerivInstTys -> (LHsBinds GhcPs, Bag AuxBindSpec) Source #