2011-12-19 50 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