-
Notifications
You must be signed in to change notification settings - Fork 237
Types appear as duplicates because of defaulting #1048
Description
Haddock can show multiple types for an expression, more or less specific (e.g. id
in id 'a'
is Char -> Char
or a -> a
). Sometimes, the same type is shown twice because of RuntimeRep
defaulting. Example:
{-# LANGUAGE ExplicitForAll, GADTs, KindSignatures, PolyKinds, DataKinds #-}
module M where
import GHC.Types
data Foo :: forall (k :: *). k -> * where
R :: forall (r :: RuntimeRep). Foo r
z :: Foo 'LiftedRep
z = R
With haddock M.hs --hyperlinked-source --html
, the last R
in the source is given type Foo 'LiftedRep
twice. There are two possible fixes:
-
Display both versions correctly. In
recoverFullIfaceTypes
we useshowSDoc df . pprIfaceType
to show the type. Fix: definedf' = gopt_set df Opt_PrintExplicitRuntimeReps
and useshowSDoc df' . pprIfaceType
. -
Don't display duplicates. Fix: in
Haddock/Backends/Hyperlinker/Renderer.hs
@@ -162,7 +168,7 @@ annotate ni content =
Html.thespan (Html.toHtml annotation) ! [ Html.theclass "annottext" ]
| otherwise = mempty
annotation = typ ++ identTyps
- typ = unlines (nodeType ni)
+ typ = unlines (nub (nodeType ni))
typedIdents = [ (n,t) | (n, identType -> Just t) <- Map.toList $ nodeIdentifiers ni ]
identTyps
| length typedIdents > 1 || null (nodeType ni)
This issue becomes important for linear types. In linear types, every data constructor with at least one argument has Multiplicity arguments (which, like RuntimeReps, are hidden, and cause duplicates).
Using GHC master, haddock commit 65bbdfb.