haskell / haddock

Haskell Documentation Tool

Home Page:www.haskell.org/haddock/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to tell from Haddocks whether a data type is a re-export?

runeksvendsen opened this issue · comments

I asked the below question in the Haskell subreddit and did not find a solution. Therefore I'm asking the same question here. Also, if the answer (as I expect) is "it's not possible", I hope someone can give an overview of the changes required to make it possible.


I'm trying to figure out whether it's possible to tell from Haddock documentation whether a given data type is a distinct type with the same name or a re-export of a type defined in another module.

For example, if I search for IO on Hoogle, the result for data IO a points to many different modules, e.g. the Hedgehog.Internal.Prelude module from the hedgehog package: https://hackage.haskell.org/package/hedgehog-1.2/docs/Hedgehog-Internal-Prelude.html#t:IO. As far as I can see, there is no way to tell, from the docs alone, that this type is a re-export of Prelude.IO. However, this must be the case since the following code typechecks:

import qualified Hedgehog.Internal.Prelude

test1 :: Hedgehog.Internal.Prelude.IO ()
test1 = (pure () :: Prelude.IO ())

If I, on the other hand, search for e.g. Query on Hoogle, I will get lots of data types called Query that are not the same, ie. not re-exports. For example:

  1. https://hackage.haskell.org/package/postgresql-simple-0.6.5/docs/Database-PostgreSQL-Simple.html#t:Query
  2. https://hackage.haskell.org/package/aws-0.24/docs/Aws-DynamoDb-Commands-Query.html#t:Query

Which means that the following will not typecheck:

import qualified Aws.DynamoDb.Commands.Query
import qualified Database.PostgreSQL.Simple

test2 :: Aws.DynamoDb.Commands.Query.Query
test2 = (undefined :: Database.PostgreSQL.Simple.Query)

Hence my question: given the Haddocks for two datatypes with the same name, is there a way to tell if they're the same?

commented

Neither of these is perfect, but a rule of thumb is that if something is a re-export from some other package it will not have a "source" link, while haddocks within a package will have a source link. Further, one can open the instance of datatypes, should any instances be defined, and note those instances are defined in base which likely means the datatype itself is also defined there.

Neither of these is perfect, but a rule of thumb is that if something is a re-export from some other package it will not have a "source" link, while haddocks within a package will have a source link.

I should probably have noted that I'm interested in not just determining whether or not something is a re-export, but also what it is a re-export of — ie. in which module it was originally defined.

In essence, I'm looking for the ability to construct a set of "equivalent types", where all members of this set are considered "the same type" by GHC when doing type checking. For the IO type this would include (but not necessarily be limited to) the following fully qualified identifiers:

Notably, this set includes both the newtype GHC.Types.IO and the data type Prelude.IO (which GHC apparently considers equivalent). I wonder if GHC is somehow hardcoded to consider these two (seemingly distinct, since one is newtype IO a and the other is data IO a) types as equivalent.

Further, one can open the instance of datatypes, should any instances be defined, and note those instances are defined in base which likely means the datatype itself is also defined there.

This seems very promising. However, when I open the Haddocks for e.g. Hedgehog.Internal.Prelude.IO there are no "Source" links for any of the instance declarations. Is this because it's a re-export?

commented

Right. That's what I said above. "if something is a re-export from some other package it will not have a "source" link, while haddocks within a package will have a source link."

Note if you click to open the instances you can see where those are defined.

image