A function to decide whether a particular diagram needs to be
regenerated. It will be passed a hash of the final assembled
source for the diagram (but with the module name set to Main
instead of something auto-generated, so that hashing the source
will produce consistent results across runs), plus any options,
local imports, and other things which could affect the result of
rendering. It can return some information (such as a hash of the
source) via the x result, which will be passed through to the
result of buildDiagram. More importantly, it decides whether
the diagram should be built: a result of Just means the diagram
should be built; Nothing means it should not. In the case
that it should be built, it returns a function for updating the
rendering options. This could be used, e.g., to request a
filename based on a hash of the source.

Two standard decision functions are provided for
convenience: alwaysRegenerate returns no extra information
and always decides to regenerate the diagram;
hashedRegenerate creates a hash of the diagram source and
looks for a file with that name in a given directory.

The diagram expression to interpret. All the given import sand
snippets will be in scope, with the given LANGUAGE pragmas
enabled. The expression may have either of the types Diagram b
v or IO (Diagram b v).

A function to apply to the interpreted diagram prior to
rendering. For example, you might wish to apply pad 1.1
. centerXY. This is preferred over directly modifying the
string expression to be interpreted, since it gives better
typechecking, and works no matter whether the expression
represents a diagram or an IO action.

Convenience function suitable to be given as the final argument
to buildDiagram. It works by converting the hash value to a
zero-padded hexadecimal string and looking in the specified
directory for any file whose base name is equal to the hash. If
there is such a file, it specifies that the diagram should not be
rebuilt. Otherwise, it specifies that the diagram should be
rebuilt, and uses the provided function to update the rendering
options based on the generated hash string. (Most likely, one
would want to set the requested output file to the hash followed
by some extension.)

Building

Build a diagram by writing the given source code to a temporary
module and interpreting the given expression, which can be of
type Diagram b v or IO (Diagram b v). Can return either a
parse error if the source does not parse, an interpreter error,
or the final result.