[Haskell-cafe] embedded build language?

Tomasz Zielonka tomasz.zielonka at gmail.com
Tue Jun 19 03:54:02 EDT 2007

[I hope you don't mind that I send this letter to haskell-cafe too.
I thought someone else might be interested.]

On Mon, Jun 18, 2007 at 10:52:40AM -0700, Greg Fitzgerald wrote:
> >first let's see if anybody likes the general idea
> Would you mind describing the role of Depends.hs in your architecture?

After parsing the target file name, you have to list the files
this target depends on. This list is used by the engine to
check if a rebuild is neccesary, or if some required files
are missing.

To add a file to the dependency list, you call "require" in Depends
monad. "require" returns the file name it was given, so you can do
things like:

    matchExact "prog" $ do
        o_files <- sequence
            [ require "a.o"
            , require "b.o"
            , require "c.o"
        return $ do
            system ("gcc -o prog " ++ unwords o_files)

The Writer part of the Depends is used to gather the list. In the
example above, you could also use listen:
    listen :: (MonadWriter w m) => m a -> m (a, w)
but I'm not sure if it's good to expose the MonadWriter interface.
I think I will provide my version of listen in Depends anyway.

The Reader part is currently used for a very simple thing - it supplies
the target name as a hidden parameter. This allows for an easy way to
get the target name regardless of the matching mechanism used.

> How did you decide on using the Reader and Writer monads?

This was the most natural, and the easiest, choice.

> If you have multiple matching rules, should one take precedence?

Right now in such situation an error will be raised. This of course may
be insufficient in some cases. Depending on the circumstances, you may
want to:
- raise an error (like now)
- choose one of the rules, perhaps based on some priorities or policies,
  like "most specific first"
- merge the rules, somehow
I haven't thought about those issues too much, but I would prefer to
allow the rule author to decide.

Best regards

More information about the Haskell-Cafe mailing list