More on Haskell DSL
September 09, 2007
In an earlier post, partial make replacement, I developed a small Haskell based DSL to express GNU make like rules. In this post, I take the idea further to support multiple dependencies per target.
testO = (return ["test.c", "test.h"]) ->> ccompile >>- "test.o"
testExe = testO ->> link >>- "test.exe"
main = testExe
The above example, expresses in a simple way, that test.o depends on test.c and test.h and can be "made" using ccompile (C compilation). Similarly, test.exe depends on test.o and can be generated by linking test.o. Checkout the Hmake module (30 lines, including the definition of ccompile and link) and try it out yourself. It now properly checks if a target is out of date with its dependency before trying to build to the target.
Compare the above with the elaborate topological sort based ermake implementation (232 lines) using erlang.
With the Haskell module above, one can even build multiple targets in parallel by using forkIO (part of the Concurrent Haskell).
You can use liftM (from Control.Monad) and mapM to simplify things.
mapM f xs == sequence (map f xs)
liftM f mx == mx >>= return . f
Posted by: wren ng thornton | November 22, 2008 at 10:09 PM