How to stop GHC from generating intermediate files?

Viewed 7675

When compiling a haskell source file via ghc --make foo.hs GHC always leaves behind a variety of intermediate files other than foo.exe. These are foo.hi and foo.o.

I often end up having to delete the .hi and .o files to avoid cluttering up the folders.

Is there a command line option for GHC not to leave behind its intermediate files? (When asked on #haskell, the best answer I got was ghc --make foo.hs && rm foo.hi foo.o.

6 Answers

2 cents to improve the workflow a bit:
We can put the following alias into the .bashrc (or similar) config file:

alias hsc='_hsc(){ ghc -no-keep-hi-files -no-keep-o-files "$@";}; _hsc'

And then just call

$ hsc compose.hs 
[1 of 1] Compiling Main             ( compose.hs, compose.o )
Linking compose ...
$ ls
compose  compose.hs
Related