Export template haskell generated definitions

安稳与你 提交于 2019-12-10 07:00:11

问题


My module contains definitions, part of which are exported (in module clause). I want to export Template Haskell-generated declarations too. But since there is seemingly no way to modify module clause with TH, I cannot do this.

Is it possible to specify that TH-generated declarations should be exported at all? Or maybe there are other ways to do this?


回答1:


You need to export the names of the generated TH declarations. For example, if you have a TH function that generates a data B = C | D declaration, you need to simply export module Mymodule (B(C,D)) where ....

If you don't specify an export list, all declarations in that module will be exported. What you can do as a little trick is to put all of your generated TH functions in one module, and then reexport that module:

{-# LANGUAGE TemplateHaskell #-}
-- Put all of the generated stuff in one module
module Bla.Generated where

generateAFunctionCalled "foo"
generateAFunctionCalled "bar"

-- Re-export the generated module
module Bla (module Bla.Generated) where
import qualified Bla.Generated

This has the disadvantage that you can't put haddock documentation for generated functions, but that's not something you usually do anyways.



来源:https://stackoverflow.com/questions/10672981/export-template-haskell-generated-definitions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!