假设我有一个名为的模块Item
,其中包含:
module Item
( routes ) where
routes = ["test1","test2","test3"]
在Main
模块中我有:
import qualified Item as I
routes = I.routes ++ ["test4", "test5"]
我想知道是否有可能在编译时ghc
动态遍历所有导入的模块,如果它们导出一个名为 routes 的变量,请将其附加到Main
模块中的 routes 变量中。所以基本上是这样的:
import qualified Item as I
import qualified User as U --this one exports routes also
import qualified NoRoutes as NR --this one doesn't have any routes
routes = ["test4","test5"]
编译后,最终结果将是routes = I.routes ++ U.routes ++ ["test4","test5"]
我不确定 Template Haskell 是否会这样做。谢谢你的帮助!