Skip to content
This repository was archived by the owner on Aug 3, 2024. It is now read-only.

Fix #548 by rendering datatype kinds more carefully #702

Merged
merged 1 commit into from
Nov 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,7 @@ TAGS
.cabal-sandbox
.ghc.environment.*
cabal.sandbox.config
cabal.project.local
cabal.project.local~

.stack-work/
27 changes: 24 additions & 3 deletions haddock-api/src/Haddock/Convert.hs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ synifyTyCon _coax tc
-- algebraic data nor newtype:
, dd_ctxt = noLoc []
, dd_cType = Nothing
, dd_kindSig = Just (synifyKindSig (tyConKind tc))
, dd_kindSig = synifyDataTyConReturnKind tc
-- we have their kind accurately:
, dd_cons = [] -- No constructors
, dd_derivs = noLoc [] }
Expand Down Expand Up @@ -210,7 +210,7 @@ synifyTyCon coax tc
-- CoAxioms, not their TyCons
_ -> synifyName tc
tyvars = synifyTyVars (tyConTyVars tc)
kindSig = Just (tyConKind tc)
kindSig = synifyDataTyConReturnKind tc
-- The data constructors.
--
-- Any data-constructors not exported from the module that *defines* the
Expand All @@ -235,7 +235,7 @@ synifyTyCon coax tc
defn = HsDataDefn { dd_ND = alg_nd
, dd_ctxt = alg_ctx
, dd_cType = Nothing
, dd_kindSig = fmap synifyKindSig kindSig
, dd_kindSig = kindSig
, dd_cons = cons
, dd_derivs = alg_deriv }
in case lefts consRaw of
Expand All @@ -245,6 +245,27 @@ synifyTyCon coax tc
, tcdDataCusk = False, tcdFVs = placeHolderNamesTc }
dataConErrs -> Left $ unlines dataConErrs

-- In this module, every TyCon being considered has come from an interface
-- file. This means that when considering a data type constructor such as:
--
-- data Foo (w :: *) (m :: * -> *) (a :: *)
--
-- Then its tyConKind will be (* -> (* -> *) -> * -> *). But beware! We are
-- also rendering the type variables of Foo, so if we synify the tyConKind of
-- Foo in full, we will end up displaying this in Haddock:
--
-- data Foo (w :: *) (m :: * -> *) (a :: *)
-- :: * -> (* -> *) -> * -> *
--
-- Which is entirely wrong (#548). We only want to display the *return* kind,
-- which this function obtains.
synifyDataTyConReturnKind :: TyCon -> Maybe (LHsKind Name)
synifyDataTyConReturnKind tc
= case splitFunTys (tyConKind tc) of
(_, ret_kind)
| isLiftedTypeKind ret_kind -> Nothing -- Don't bother displaying :: *
| otherwise -> Just (synifyKindSig ret_kind)

synifyInjectivityAnn :: Maybe Name -> [TyVar] -> Injectivity
-> Maybe (LInjectivityAnn Name)
synifyInjectivityAnn Nothing _ _ = Nothing
Expand Down
Loading