RE: [Template-haskell] How to extract name and type of exported functions in modules

Simon Peyton-Jones <[email protected]> Wed, 21 Oct 2009 11:40:21 +0000
Newsgroups gmane.comp.lang.haskell.glasgow.user,gmane.comp.lang.haskell.template
Message-ID <59543203684B2244980D7E4057D5FBC1061B6B91@DB3EX14MBXC310.europe.corp.microsoft.com>
| -- If it exports any prelude indentifiers (not only the Prelude itself,
|    but also for example Data.List), I have no idea how to get at
|    their types --- lookupGlobalName does not find them.

Well, it claims that it should find them.   Would you like to make a reprod=
ucible test case and file a Trac bug report?

| -- I cannot find any re-exported instances. The ``package InstEnv''
|    obtained from tcGetInstEnvs after loading a library module interface
|    (via findAndReadIface) seems to contain only the module's own exported
|    instances, which are the same instances I also find via mi_insts.
|    (For source modules, where I use typeCheckModule,
|     I've only been able to find the module's own exported instances via
|     hptInstances).

Hmm.  GHC does not read every interface file for every module in every pack=
age that is transitively visible from the current module.  Instead it relie=
s on the fact that before an instance (C T) is useful, you must have a hold=
 of Class C and TyCon T.  So you'll have loaded *their* interfaces, and the=
reby loaded their instances. (Except for orphan instances, which *are* load=
ed eagerly.)

I can see that this is inconvenient; on the other hand, do you really want =
ALL the instances of Ord, say? =20

Perhaps there should be an interface for
	load instances that relate to the following Names
Indeed, there is: LoadIface.loadInterfaceForName.

Does that help?  What's the desired behaviour?


I really wish there was someone who took ownership for the GHC API, as seen=
 by "customers" of the API.  At the moment it grows incrementally, without =
proper design.  Maybe no one feels able to, because they think GHC HQ will =
do it, but (a) we are too busy and (b) we represent the suppliers of the AP=
I, not the customers.

Any volunteeers?

Simon