2011-12-19 54 views
1

对给定包中的所有模块(文件)进行迭代的最佳方式是什么?具体而言,假设我有如何遍历Cabal包中的模块

  1. 称为 “runThis”
  2. 一个小集团的包装物P与文件F1.hs可执行文件,F2.hs,...,Fn.hs

请告诉我最简单的执行方式:

runThis F1.hs 
runThis F2.hs 
... 
runThis Fn.hs 

我想我可能会尝试--with编译但失败

cabal: The program ghc version >=6.4 is required but the version of runThis 

(另一个选项看起来像扭捏Setup.lhs - 但最好我想劫持构建过程和使用“runThis”而不是,比如ghc)

谢谢!

+0

此邮件列表消息看起来相关:http://www.opensubscriber.com/message/[email protected]/12911379.html – 2011-12-19 23:24:56

+1

什么样的程序是'runThis'?会像'$ for file in * .hs;做runThis $文件;做完了;'做你想做的事? – 2011-12-19 23:27:53

+0

谢谢@DanielWagner,这就是诀窍。虽然它忽略了.cabal中没有提到的隐藏模块(我也想这么做),但它实际上更容易实现Daniel Fischer所建议的功能(再加上使用filemanip递归查找所有* .hs文件。 ..) – 2011-12-20 00:09:21

回答

1

从邓肯·库茨email

  1. 问:如何添加预处理器?我曾尝试

    main = 
        defaultMainWithHooks 
          simpleUserHooks{hookedPreProcessors=[("foo",transformation)]} 
    
    transformation :: BuildInfo -> LocalBuildInfo -> PreProcessor 
    

这看起来正确的。以下是如何完成它(例如,从 惊天动地黑线鳕文档采取预处理模块):

transformation _ _ = 
    PreProcessor { 
    platformIndependent = True, 
    runPreProcessor = 
     mkSimplePreProcessor $ \inFile outFile verbosity -> do 
     fail $ "transformation: " ++ inFile ++ " " ++ outFile 
    } 

,它工作正常:

runghc Setup.hs build 
Preprocessing library foo-1.0... 
Setup.hs: transformation: Abc.foo dist/build/Abc.hs 

但在何种情况下将这个函数被调用?到目前为止
我还没有成功打造这个功能。

当它并查找模块Abc它调用它(即Abc.hs.lhs),并且因为如果没有找到它,它会检查通过 预处理器列表,并去寻找相应的文件,即Abc.foo