The first thing to mention is that if you call getDirectoryFiles
multiple times with the same arguments it will only calculate once, in the same way that if you call need
multiple times on the same file it will only build once. One approach would be:
"out/*.fwd" *> \out -> do
res <- getDirectoryFiles "src" ["*.txt"]
let match = [(takeBaseName out ++ "-") `isPrefixOf` takeBaseName x | x <- res]
when (length match /= 1) $ error "fail, because wrong number of matches"
writeFileChanged out $ head match
"out/*.html" *> \out -> do
src <- readFile' (out -<.> "fwd")
txt <- readFile' ("src" </> src)
...
Here the idea is that the file out/123.txt
contain the contents 123-some-title.txt
. By using writeFileChanged
we only change the .fwd
file when the relevant part of the directory changes.
If you want to avoid the .fwd
files, you can use the Oracle
mechanism. If you want to avoid a linear scan of the getDirectoryFiles
result you can use the newCache
function. In practice, neither is likely to be problematic, and going with the files is probably simplest.