I can partially answer the first question (why?); not sure if this is a bug or desired behavior.
When a haddock resolves links in LexParseRn.rename , it tries to find the identifier in the environment (via lookupGRE_RdrName ). This should fail. What looks like next (using dataTcOccs from GHCs RnEnv ). Matching lines:
dataTcOccs :: RdrName -> [RdrName] -- Return both the given name and the same name promoted to the TcClsName -- namespace. This is useful when we aren't sure which we are looking at. dataTcOccs rdr_name [...] | isDataOcc occ || isVarOcc occ = [rdr_name, rdr_name_tc] [...] where occ = rdrNameOcc rdr_name rdr_name_tc = setRdrNameSpace rdr_name tcName
therefore, it returns a name that is first interpreted as it was before (probably a reference to a value), and then interpreted as a type constructor. How can a regular name be a type constructor? I assume this was added when TypeOperators were converted to GHC 7.6, which now share the namespace with value-level operators.
Then, a result match is written: if the first one is a type constructor, use it, otherwise use the second. One way or another, it was a type constructor, then it is used. Or it is not, but then a modified version generated by dataTcOccs should be used.
It seems to me that haddock should always use the first option here, and the code is just a misleading copy of how several results are used when they can really be resolved.
source share