, isFamilyTyCon
, isInvisibleTyConBinder
, tyConBinders
+ , tyConFamInst_maybe
, tyConName
, tyConResKind
, tyConTuple_maybe
Just (a, b) ->
TyConApp arrowQualName [typeArg boundTvs a, typeArg boundTvs b]
Nothing -> case splitTyConApp_maybe t of
- Just (tc, args) ->
- let visArgs = visibleArgs tc args
- kids = map (typeArg boundTvs) visArgs
- in if isFamilyTyCon tc
- then FamilyApp (qualName (tyConName tc)) kids
- else TyConApp (qualName (tyConName tc)) kids
+ Just (tc, args)
+ -- Synthetic data-family-instance representation TyCon.
+ -- GHC creates one of these (`R:FooArgs`) for each
+ -- `data instance Foo Args = …` and uses it in the actual
+ -- type representation. The user wrote @Foo Args@ at source
+ -- level; that's what we want to surface. Crucially,
+ -- @parentArgs@ are the abstract family arguments (e.g.
+ -- @[Praos c]@ for @data instance ConsensusConfig (Praos
+ -- c)@), not the rep TyCon's own type variables, so we get
+ -- the right shape back without further work.
+ --
+ -- We classify the result as a 'FamilyApp' so the viewer's
+ -- chain logic ("there should be a fam-instance somewhere
+ -- that satisfies this") naturally engages — including
+ -- finding the matching @data instance@ row and connecting
+ -- it to any class instance of e.g. @NoThunks (Foo Args)@.
+ | Just (parent, parentArgs) <- tyConFamInst_maybe tc ->
+ FamilyApp (qualName (tyConName parent))
+ (map (typeArg boundTvs) parentArgs)
+ | otherwise ->
+ let visArgs = visibleArgs tc args
+ kids = map (typeArg boundTvs) visArgs
+ in if isFamilyTyCon tc
+ then FamilyApp (qualName (tyConName tc)) kids
+ else TyConApp (qualName (tyConName tc)) kids
Nothing -> case isLitTy t of
Just _ -> LitArg (pprText t)
Nothing -> OtherArg (pprText t)