June 16, 2020

Using GHCi

GHCi is an interactive interface to the Haskell language. In the case of other languages (such as Python, ruby, Perl) I have always avoided using such things. In the case of Haskell, this is a mistake.

If you have a script you want to fiddle with, type:

ghci myscript.hs
It will load the script, but not try to run it, even if it defines the main function. You can just type main if you want to run it. Alternately, you can start ghci without any arguments and then type ":l myscript.hs" to load it into ghci.

GHCi has a bunch of single letter commands that are prefixed with a colon. Here are some of them:

:q -- quit
:l file -- load a file
:t function -- show the type of an expression
You can type the name of any function to execute it. It is smart enough to execute IO functions properly as well as non-IO functions without any help on your part.
Feedback? Questions? Drop me a line!

Tom's Computer Info / tom@mmto.org