Skip to content

Lab 01: Getting Connected and Running Haskell

This first lab is intentionally short. The goal is to make sure you can use the basic tools we will rely on throughout CS 131:

  • connect to the CS 131 programming server from a terminal,
  • connect to the same server through VS Code,
  • open a terminal that is actually running on the server,
  • start ghci,
  • evaluate a few simple Haskell expressions,
  • create a Haskell source file, and
  • load that file into ghci.

There is no programming challenge to solve today. If something does not work, ask for help immediately. Getting your environment working is the point of the lab.

Gradescope

As you work, complete the corresponding Lab 01 assignment on Gradescope.

Most questions are simple completion checks. A few ask you to paste output or briefly describe what happened.


Part 1: First Login from a Terminal

For your first connection to the server, use a plain terminal rather than VS Code's Remote-SSH extension.

Open a terminal and run:

ssh <your-username>@cs131.cs.hmc.edu

Replace <your-username> with the username provided to you for the course.

The first time you connect:

  1. You may be asked whether you trust the host. Answer yes.
  2. Enter the temporary password provided by the instructors.
  3. You should immediately be prompted to choose a new password.
  4. When typing a password, nothing appears on the screen. This is normal.

Once you are connected, try:

pwd

and:

ls

pwd shows your current directory. ls shows the files and directories there.

Gradescope check: terminal connection

Complete the terminal-connection question on Gradescope.

If you cannot connect, stop here and ask for help before moving on.


Part 2: Install VS Code Remote-SSH

Most of our work will be easiest through VS Code while connected remotely to the server.

Open VS Code and install Microsoft's Remote - SSH extension:

  1. Open the Extensions panel with Ctrl+Shift+X or Cmd+Shift+X.
  2. Search for Remote - SSH.
  3. Install the extension published by Microsoft with identifier:
ms-vscode-remote.remote-ssh

You only need to install this extension once.

After installation, VS Code should show a remote-connection control in the bottom-left corner of the window.

Gradescope check: Remote-SSH installed

Complete the Remote-SSH installation question on Gradescope.


Part 3: Connect with VS Code

Now connect VS Code to the same server.

You can either:

  • click the remote-connection control in the bottom-left corner and choose Connect to Host..., or
  • open the Command Palette with Ctrl+Shift+P / Cmd+Shift+P and run:
Remote-SSH: Connect to Host...

Enter:

<your-username>@cs131.cs.hmc.edu

Use the new password you created during your terminal login.

The first connection may take a little while because VS Code installs some support software on the remote server.

Once connected, the bottom-left status area should indicate that you are connected to:

cs131.cs.hmc.edu

Open the file explorer and choose Open Folder. Open your home directory.

You may be asked whether you trust the folder. Say yes.

Gradescope check: VS Code connection

Complete the VS Code connection question on Gradescope.


Part 4: Open a Terminal on the Server

Inside the remote VS Code window, open a terminal:

Ctrl+`

or use Terminal → New Terminal.

This terminal is now running on the CS 131 server, not on your own computer.

Confirm by running:

hostname

and:

pwd

You should see the server's hostname and a path inside your home directory.

Gradescope: confirm the remote terminal

Paste your hostname and pwd output into the corresponding Gradescope question.


Part 5: Start ghci

In the terminal, run:

ghci

This starts the Glasgow Haskell Compiler Interactive environment, usually called ghci.

It is a REPL:

  • Read an expression,
  • Evaluate it,
  • Print the result,
  • Loop back for another expression.

Try these:

1 + 41
2 * 3 + 4
sqrt 49
max 12 19
"hello" ++ " world"

Then try one expression of your own.

Before pressing Enter each time, make a quick prediction about the result.

Gradescope: a GHCi result

Paste the expression you invented and the output ghci produced.

To leave ghci, type:

:q

or press Ctrl+D.


Part 6: Create a Haskell File

Now create a small Haskell source file.

In your terminal, make a directory for this lab:

mkdir -p ~/cs131/lab01
cd ~/cs131/lab01

Confirm where you are:

pwd

In the VS Code file explorer, open the cs131/lab01 directory if necessary.

Create a file called:

lab01.hs

Put this code inside:

x = 1 + 2

y = x + 3

double n = n * 2

Save the file.


Part 7: Load the File into ghci

Back in the terminal, make sure you are still inside the lab01 directory:

pwd

Start ghci again:

ghci

Then load the file:

:load lab01.hs

You should see a message indicating that the file loaded successfully.

Now try:

x
y
double 10
double y

If you change the file in VS Code and save it, you can reload the file from inside ghci with:

:r

Try changing:

double n = n * 2

to:

double n = n * 3

Save the file, run :r, and try double 10 again.

Gradescope: loading a Haskell file

Paste a short transcript showing that you successfully loaded lab01.hs and evaluated at least one of its definitions.


Wrap Up

At this point you should be able to:

  • connect to the server using ssh,
  • connect using VS Code Remote-SSH,
  • open a terminal running on the server,
  • start and exit ghci,
  • evaluate Haskell expressions,
  • create and save a .hs file,
  • load that file with :load, and
  • reload it after editing with :r.

Those steps form the basic workflow we will use repeatedly throughout the course.

Gradescope: wrap-up

Complete the final short reflection on Gradescope. If anything still does not work, say what happened so we can help get it fixed.