A monitor for detecting changes to a set of files. It can be used to
efficiently test if any of a set of files (specified individually or by
glob patterns) has changed since some snapshot. In addition, it also checks
for changes in a value (of type a), and when there are no changes in
either it returns a saved value (of type b).
The main use case looks like this: suppose we have some expensive action
that depends on certain pure inputs and reads some set of files, and
produces some pure result. We want to avoid re-running this action when it
would produce the same result. So we need to monitor the files the action
looked at, the other pure input values, and we need to cache the result.
Then at some later point, if the input value didn't change, and none of the
files changed, then we can re-use the cached result rather than re-running
the action.
This can be achieved using a FileMonitor. Each FileMonitor instance
saves state in a disk file, so the file for that has to be specified,
making sure it is unique. The pattern is to use checkFileMonitorChanged
to see if there's been any change. If there is, re-run the action, keeping
track of the files, then use updateFileMonitor to record the current
set of files to monitor, the current input value for the action, and the
result of the action.
The typical occurrence of this pattern is captured by rerunIfChanged
and the Rebuild monad. More complicated cases may need to use
checkFileMonitorChanged and updateFileMonitor directly.