Automatically add package to cabal file

GHC will often give a message like

Foo.hs:16:18:
    Could not find module `System.Directory'
    It is a member of the hidden package `directory-1.1.0.2'.
    Perhaps you need to add `directory' to the build-depends in your .cabal file.
    Use -v to see a list of the files searched for.

when you use a module that belongs to a package that isn't in your
cabal file. The haskell process can now prompt you to begin a
process that will add the package to your .cabal file.

Foo.hs:16:18: Could not find module `System.Directory' [ It is a me
.. ]

Add `directory' to some-package.cabal? (y or n)  y

That process can also manually be started with M-x haskell-process-add-dependency

It goes thus:

Package entry: directory >= 1.1.0.2

(that is a prompt, you can edit the package entry there)

Then it switches to the cabal file, and jumps to each build target in
the file, prompting first the library--if there is a library entry:

Add to library? (y or n)  y

And then executables:

Add to executable `some-executable'? (y or n)  y

It will insert the dependency at the top of the build-depends list,
and try to re-indent the item that it knocked off back into the same
level of indentation.

Once all targets are done, it saves the .cabal file and switches back
to the buffer you were originally in.

@hvr might be of interest.