Skip to main content

GHCI

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:

ghci 

Executing 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.hs

Alternatively, you can start GHCI first, and then import your module main.hs:

ghci 
:load main

No, 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:

:reload 
main

Compiling your Haskell file to an executeable:

ghc main.hs

./main.o

Instead of compiling to run it, you can also use "runhaskell" to run your program instantly.

runhaskell main.hs

Getting the function signature of something:

:type head 
---head :: [a] -> a

To quit GHCI:

:quit