Running ghc invokes the Glasgow Haskell Compiler (GHC), and can be used to compile Haskell modules and programs into native executables and libraries.
Create a new Haskell source file named hello.hs, and write the following code in it:
main = putStrLn "Hello, Haskell!"
Now, we can compile the program by invoking ghc with the file name:
➜ ghc hello.hs [1 of 1] Compiling Main ( hello.hs, hello.o ) Linking hello ...
GHC created the following files:
hello.hi - Haskell interface file
hello.o - Object file, the output of the compiler before linking
hello (or hello.exe on Microsoft Windows) - A native runnable executable.
GHC will produce an executable when the source file satisfies both conditions:
Defines the main function in the source file
Defines the module name to be Main or does not have a module declaration
Otherwise, it will only produce the .o and .hi files.