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

Simon Peyton-Jones simonpj at microsoft.com
Wed Oct 21 07:40:21 EDT 2009

| -- 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 reproducible 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 package that is transitively visible from the current module.  Instead it relies 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 thereby loaded their instances. (Except for orphan instances, which *are* loaded eagerly.)

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

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 API, not the customers.

Any volunteeers?


More information about the Glasgow-haskell-users mailing list