Skip to content

Installation

The bulk of the programming will be in Haskell and Rust. For both of these languages, you will need two things to get started: some way to edit your code, and some way to compile and run your programs. To keep things simple, I recommend you use the same editor for both languages. However, you're certainly welcome to use different editors if you prefer.

Getting Started with Haskell

The following instructions are if you are using your personal machine. All needed Haskell software is already installed on the instructional machines.

Step 1: Download and install the Haskell Platform.

This includes everything you need to get started---the GHC compiler, the Cabal build system, the Stack project tool, and more.

Step 2: Pick an editor or IDE.

If you are comfortable with text-based editors, both vim and emacs work well for Haskell with a bit of configuration; please search around online. If you prefer something a bit more polished:

Step 3: Install HLint.

The HLint tool provides helpful suggestions for cleaning up your code. We expect you to run HLint before submitting your homework, and to make fixes (within reason). There are a few important things to keep in mind.

  • HLint is not perfect. In rare cases, it may make suggestions that break your program. Make sure to test afterwards to make sure your program is still OK.
  • HLint typically uncovers more suggestions after you make initial changes. Make sure to run HLint again after making your changes, until you have applied all the fixes that you want to.

If you are using your personal machine, you can install Hlint using Cabal, the Haskell package manager:

cabal v2-update
cabal v2-install hlint

Then, run hlint source-file.hs to see hints for source-file.hs. Alternatively, it may be easier to just get the HLint executable for your machine.

The Cabal Build System

We will be using the Cabal build system to build and manage Haskell programs. Cabal has excellent documentation (found here), but for our purposes we will only use a few commands:

  • cabal v2-build: This command will build the project within the current working directory. It will also install any dependencies if needed.
  • cabal v2-run projectName: This command will run the executable projectName. In general, this will be hwn where n is the homework number. If you need to pass command line arguments, you need to preface the beginning of the arguments with --. For example, cabal v2-run projectName -- arg1 arg2 ....
  • cabal v2-clean: This command will remove any temporary files and build artifacts stored in the dist-newstyle folder.
  • cabal v2-repl: This command will load all of the modules of the target into GHCi, the command-line interpreter for Haskell. You should expect to use GHCi extensively as you are programming, to check if your code is working properly. The following GHCi commands will be useful:

    • :l mod: Load a module. If you want to run functions in a particular module, you will need to load it first.
    • :r: Reload the current module. This is useful if you have changed the source file (say, in a different window).
    • :t arg: Get the type of a name.
    • :h: Full list of GHCi commands.
    • :q: Quit GHCi.

Cabal is currently undergoing a period of transition where they are changing the way that builds are handled, hence the v2 prefix of every command. For forwards-compatibility, we adopt to use the new standard.

Getting Started with Rust

You will need to download and install Rust whether you are working on your personal machine or on the instructional machine. (The instructional machines have some Rust tools, but we will need a bit more.) The installation should be fairly painless on all platforms, let us know if you are having difficulties.

Step 1: Download and install the latest version of Rust.

This will first install Rust's installation manager Rustup, which will then allow you to switch between different versions of Rust. In this course we will always stick with the stable version.

If you are on the instructional machines, you'll have to work around the system installation of Rust. Try the following:

wget https://sh.rustup.rs
sh index.html -y

You may have to log out and log back in again to set up the path correctly.

Step 2: Pick an editor or IDE.

If you are comfortable with text-based editors, both vim and emacs work well for Rust with a bit of configuration; please search around online. If you prefer something a bit more polished:

Step 3: Install Rustfmt and Clippy.

Rust includes some useful tools for cleaning up your code. Rustfmt formats your code so that the style is consistent. Clippy suggests places where your code can be improved or made more idiomatic. Again, these suggestions are almost always good but may break your code in rare cases---make sure to test!

You can install these tools through Rustup:

rustup component add rustfmt
rustup component add clippy

You can run these tools on your project with cargo fmt and cargo clippy.

The Cargo Build System

We will be using the Cargo build system to build and manage Rust programs. Cargo has excellent documentation (found here), but for our purposes we will only use a few commands:

  • cargo check: This command will check the project within the current working directory, without producing all object files. This a fast way to run the compiler, and this is the most useful when developing.
  • cargo build: This command will build the project within the current working directory. It will also install any dependencies if needed.
  • cargo run: This command will run the executable. If you need to pass command line arguments, you need to preface the beginning of the arguments with --. For example, cargo run -- arg1 arg2 ....
  • cargo test: This command will run project tests.
  • cabal clean: This command will remove any temporary files.
  • cabal package: This command will compress the project into a .crate file. You will use this command when uploading your solutions.