haddock, instances and defining modules

Daniel Gorín dgorin at dc.uba.ar
Thu Oct 18 12:21:17 CEST 2012

Hi Simon,

>> The haddock page for Data.Either lists an instance Functor (Either a).
>> However, this instance doesn't get in scope when importing
>> Data.Either. E.g., the following program fails to compile:
>>> import Data.Either
>>> main = print $ fmap not $ Right "hello"
>> AFAIK, one needs to import Control.Monad.Instances instead to get such
>> an instance; but there is nothing in the haddock page of Data.Either
>> that suggests it. This can be quite frustrating for beginners!
>> It would be good if the docs could be improved here, but I'm not sure
>> what to suggest (maybe haddock should be generating something else in
>> these cases?)… Any thoughts?
> The actual issue is, that the instance definition is orphan (this has
> been fixed in base
> I think without orphan instances, this problem does not arise.  I'm not
> sure whether it's worth the effort to address a problem that only occurs
> with orphan instances in Haddock.
> It would still be nice if we had "source" links to instance definitions,
> and as a side effect they would also address this issue (you could then
> simply click on the "source" link to see where that instance is
> defined).

Thanks for your answer. I was using indeed ghc 7.4.1 (and as was pointed out in another mail, one has to replace Right by Left in the example program, sorry about that!).

I agree that without orphan instances this is a non-issue, and I'm glad that it was fixed in newer versions of base.

Source links for instance definitions would be very handy in general! For orphan instances, it would be a nice feature, perhaps, if haddock could somehow figure out whether an instance is in scope in the module defining the class and/or the type (e.g., by looking for certain paths in the module dependency graph) Then it could mark those instances that are not in scope as orphan and even list the orphan instances defined in a module, which it currently doesn't...


More information about the Libraries mailing list