Notes about getting and using GHCi

(revised Fall 2017)

There's basically three steps:

Things will go a bit differently depending on which OS you're using. If you're not experienced with using a Linux-style terminal, Windows is probably the easiest OS to use. If you like using the terminal, Linux and Mac OS are both a bit nicer than Windows.

1: Download & install GHCi

Download the "Core" package here: https://www.haskell.org/platform/. This is a fairly large download.

Then find the installer you downloaded, and click through the steps to install it.

extra step for Mac OS

You may be prompted to install "Command Line Tools for Xcode" which is a free (but pretty big) download from Apple. Do it!

You may have to open Xcode once just to agree to the usage terms. Find it in your "Applications" folder, and open it. Click "Agree" on the legal nonsense, and then let it install components. Then you can quit Xcode once it launches fully. You won't ever actually use Xcode when writing your Haskell programs.

2: Get a good code editor

Generally you can use any text editor you like to write your programs. You should not try to use a full-featured word processor (like Microsoft Word). An editor designed for writing computer code will be best. Here's some suggestions if you don't already have a favorite.

Windows

A good free code editor for Windows is Notepad++, which will color your code nicely when you're writing in Haskell.

Mac OS X

A good free code editor for MacOS is Textmate 2, which will color your code nicely when you're writing in Haskell.

3: Start using GHCi

Windows

Run the program "WinGHCi" which will appear in the Haskell directory that gets created during installation. From WinGHCi you can load your code files using the menus or by clicking the buttons at the top.

Mac OS X

On Mac OS, you will run GHCi from the terminal. In Mac OS, the terminal is an Application found in "Utilities" folder inside the "Applications" folder. There are lots of complicated and great things you can do with the terminal, but we won't need to do anything fancy. If you want, you can find lots of guides online. The Mac OS terminal engine is called "bash", which is exactly the same terminal that is typically used in Linux. So any guide for using the linux terminal will work exactly the same in Mac OS.

The only terminal command you'll really need to use is "cd". When you launch the terminal you'll start in your home user folder (a folder is also called a "directory"). Type "ls" and hit return to see a listing of what's in that folder. Use "cd" to change directory. So if you have a folder called "haskell" inside your home folder, type "cd haskell" to switch into that directory. You can press Tab after typing part of a folder name to complete it.

After launching the terminal use "cd" to switch to the directory where your haskell programs are. Once you get to that directory, type "ghci" to launch GHCi. Inside GHCi, load your files using ":l". So if you have a file called "project1.hs", load it into GHCi by typing ":l project1.hs" inside GHCi.

4: Get some packages

Much later on in the course, we'll be doing some stuff using a random number generator, and a reader for images, which are not built in to GHCi by default, so you need to get them separately. It's not hard, and you only have to do this once.

Windows

Open the Windows Command Prompt (google if you don't know how to do this- it depends on which Windows version you have). Then run the command: "cabal update" (no quotes). Once that's done, run "cabal install random". Once that's done, run "cabal install JuicyPixels". (JuicyPixels might take a long time to install.) Then inside GHCi, try to run "import System.Random". If you don't get any errors, then it worked! To test JuicyPixels, try "import Codec.Picture"

Mac OS X

In the terminal (not inside GHCi), run the command: "sudo cabal update" (no quotes). You'll need to type your computer password. Once that finishes, run the command: "sudo cabal install random". Once that's done, run "sudo cabal install JuicyPixels". (JuicyPixels might take a long time to install.) Then inside GHCi, try to run "import System.Random". If you don't get any errors, then it worked! To test JuicyPixels, try "import Codec.Picture"