0

Sometimes, I write code to a file solely for the purpose of checking whether it compiles -- with no interest in the generated binaries.

For example, if I am doing a learning exercise and want to produce some error or see if certain code compiles without error, I'd like to see the ordinary compile output printed to the terminal but without generating the *.hi or *.o files that occur by running ghc <myprogram>.hs.

I sometimes effectively do this using runhaskell, but that is not ideal -- it requires a main function, and actually runs the program whereas I am just looking for a compilation check.

Is there some way to suppress generation when running GHC, only displaying the ordinary compilation errors and warnings?

mherzl
  • 5,624
  • 6
  • 34
  • 75

2 Answers2

1

One of the answers to this question suggested the answer that I'm looking for: ghc option -fno-code.

I.e., compile but don't generate binaries with:

$ ghc -fno-code <myprogram>.hs
mherzl
  • 5,624
  • 6
  • 34
  • 75
1

In the same spirit to the purpose of the question and in addition to the working answer by @mherzl, my answer below:

while true;do
    inotifywait -e modify myprogram.hs
    ghc -fno-code myprogram.hs
done

This only works on Linux systems having the inotifywait tool. It blocks an detects if the file is modified.

daparic
  • 3,794
  • 2
  • 36
  • 38