Skip to content

[Template Haskell] Additional information in ModuleInfo

Motivation

I want to write a TemplateHaskell function that accepts a module name and a prefix and generates new identifiers for every exported term with the prefix. This would allow me to mimic qualified re-exports:

import qualified Data.Map as Map

mkReexportFriendly ''Map

-- =====>

_Map_lookup :: (Ord k) => k -> Map.Map k v -> Maybe v
_Map_lookup = Map.lookup

I can't currently do this. There's no way to determine what items are imported/exported by a module in Template Haskell. The only way to (reliably) get a Module is with thisModule, and then using reifyModule, you can figure out the import lists of a given module.

Proposal(s)

This need could be satisfied with one of the following ideas:

  • Extend the ModuleInfo datatype to include the imported items from that module.
  • Add another function reifyImports :: ModName -> Q ImportInfo that provides the information.

I'm sure there are other possible solutions, too.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information