Notes about getting and using GHCi

(revised Fall 2016)

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 the software

Mac OS X

Download the "Minimal" package here: https://www.haskell.org/platform/mac.html

Windows

Download the "Minimal" package here: https://www.haskell.org/platform/windows.html

You'll have to choose 64 or 32 bit, which will depend on what kind of processor you have in your computer. If you don't know or care, you can choose 32 and it'll work fine either way. If you really want to use 64 but don't know if you can, see here to check which kind of Windows you have. (If you choose 64 but you only have a 32-bit computer, you'll get some error later on, and you'll have to come back to this step and download the 32 bit version and reinstall.)

2: Install the software

Windows

Open the installer that you downloaded and click through. You can tweak the settings if you understand any of them, or just accept all the defaults.

Mac OS X

Open the installer that you downloaded and click through. 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.

3: Get a good text 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 (now in beta, but works great), which will color your code nicely when you're writing in Haskell.

4: 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 two terminal commands you'll need to use are "ls" and "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.

5: (For much later) Get the System.Random package

Much later on in the course, we'll be doing some stuff using a random number generator, which is not built in to GHCi by default, so you need to get it 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". Inside GHCi, try to run "import System.Random". If you don't get any errors, then it worked!

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". Now start GHCi, and try to run "import System.Random". If you don't get any errors, then it worked!