Using the Glasgow Haskell Compiler
GHCI stands for “Glasgow Haskell Compiler”. This compiler is the go-to solution for compiling your Haskell code. It can be seen as the pendant to GCC, actually compiling your code to C under the hood. Here is quick tour of running, testing and building your code with GHCI.
Starting it:
ghciExecuting a hello-world file (main.hs):
main :: IO ()main = putStrLn "Hello World"When you saved your file, we can open it in GHCI like this:
ghci main.hsAlternatively, you can start GHCI first, and then import your module main.hs:
ghci:load mainNo, your file won’t execute right now - opening like this kind of loads your file into GHCI, so that you can now play around with it. To execute it, type “main” and press enter, and you should see the output.
If you change something in the file, and want to run it again with GHCI opened, run:
:reloadmainCompiling your Haskell file to an executeable:
ghc main.hs
./main.oInstead of compiling to run it, you can also use “runhaskell” to run your program instantly.
runhaskell main.hsGetting the function signature of something:
:type head---head :: [a] -> aTo quit GHCI:
:quit