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

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Your comment could not be posted. Error type:
Your comment has been saved. Comments are moderated and will not appear until approved by the author. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.


Post a comment

Comments are moderated, and will not appear until the author has approved them.

Your Information

(Name and email address are required. Email address will not be displayed with the comment.)