Another DSL embedded in Haskell - a partial make replacement in less than 10 lines
Financial vs Real investment

More on Haskell DSL

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).


wren ng thornton

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

The comments to this entry are closed.