Ghcid and cabal common stanzas

Cabal’s common stanzas feature can be used to allow ghcid to reload when the sources for a dependent library changes.

A common pattern used in Haskell projects is to have two build targets—library and executable. Ghcid is then used to launch the executable, as well as recompile and restart it when the executable sources change:

ghcid -c "cabal new-repl exe" -T :main

This works. But when the library sources themselves change, nothing would happen with the above ghcid instance. Ideally we would like ghcid to recompile and restart even if the library changes. This can be achieved by including the entire library stanza as-is in the executable stanza, which is a bit of cheating but it works fine. Cabal’s common stanza feature just makes this less painful.