#1475: Adding imports and exports with Template Haskell
-------------------------------+--------------------------------------------
Reporter: igloo | Owner:
Type: feature request | Status: new
Priority: normal | Milestone: 6.8
Component: Template Haskell | Version: 6.6.1
Severity: normal | Keywords:
Difficulty: Unknown | Os: Unknown
Testcase: | Architecture: Unknown
-------------------------------+--------------------------------------------
(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).
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/1475>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs