Adding imports and exports with Template Haskell
|Reported by:||igloo||Owned by:|
|Keywords:||Cc:||ganesh.sittampalam@…, alfonso.acosta@…, mjm2002@…, Deewiant, merehap, ivan.perez@…, hackage.haskell.org@…, campersander@…, silvio.frischi@…|
|Type of failure:||None/Unknown||Test Case:|
|Related Tickets:||Differential Rev(s):|
(wished for by Adrian Hey in http://www.haskell.org/pipermail/template-haskell/2007-June/000598.html)
It would be useful to be able to add module exports with TH, although I'm not sure exactly how it would be done. Perhaps something like
$( do n <- newName "foo" let d = funD n ... addExport (varE n) return [d]
but at the point we call addExport the typechecker doesn't know that there will be a declaration for the name.
Less useful, as TH names include the package and module of the name's definition, is the ability to add module imports. However, this can still be used to get a kind of dynamic binding effect, either with mkName's names or plain Haskell code, e.g.:
$( addImport (if ... then '''Data.ByteString else '''Data.ByteString.Lazy) (mkName "BS") ) foo :: BS.ByteString foo = BS.append ...
(we'd actually probably want a datatype that mirrors Haskell import decls more closely).