This page contains instructions for how to upgrade to a new version of GHC for your project!

Depending on your current setup, your project may be built using the global ghc available on the $PATH, or you may have a GHC version pinned via the with-compiler option (this will live in either the cabal.project or cabal.project.local file).

Project Structure

For the sections below we'll assume you have a project that looks like this:

Directory Structure:

./cabal.project
./myproject.cabal
./Main.hs
./stack.yaml  # You'll have this if you're using [Stack](https://docs.haskellstack.org/en/stable/README/).

File: cabal.project

Configuration for your project where you can pin the compiler version. You may or may not have this.

with-compiler: ghc-8.4.4

File: myproject.cabal

cabal-version: 2.2
name: myproject
version: 0.1.0.0
synopsis: My project synopsis.
description: My project description.
license: BSD-3-Clause
license-file: LICENSE
build-type: Simple

executable myproject
  default-language:    Haskell2010
  main-is: Main.hs
  build-depends: base >=4.11 && <4.12

File: stack.yaml

<stuff>
resolver: lts-12.19
<more-stuff>

First: Make sure your project builds

Run either cabal v2-build or stack build and make sure everything builds fine. Once we go through the steps below we'll want to make sure everything still builds properly.

Getting a new GHC Version

Below are instructions for how to get the latest version of GHC on various operating systems. When you get the new version of GHC you can either overwrite the ghc on the $PATH, or leave ghc as is and put ghc-x.y.z on the $PATH where x.y.z is the version number.

Cabal Users

Linux - Most distros

Linux - Ubuntu/Debian

Mac/OSX

Windows

Stack Users

GHC is automatically downloaded by Stack if you've switched to a new resolved that contains a new GHC version. You can find a list of resolvers at https://www.stackage.org. Find one which has the compiler you want to use and update your stack.yaml file.

Nix Users

To use a new version of GHC from your Nix project you should update your shell.nix and set pkgs.haskell.compiler.ghcxyz in the buildInputs list of the mkDerivation.

{ pkgs ? import <nixpkgs> {}
}:

pkgs.stdenv.mkDerivation rec {
  name = "myproject";
  buildInputs = [
    pkgs.haskell.compiler.ghc862
    pkgs.cabal-install
    ...
  ]
  ...

Updating Your Project

Updating base version bounds

If you look at your myproject.cabal file in the build-depends section for the executable you'll see there are version bounds for the base package: base >=4.11 && < 4.12. The new version of GHC will likely be using a newer base version than the upper bound you have set, so you'll need to relax the upper bound, changing it to something like: base >=4.11 && < 4.13.

If your base version bounds are wrong you'll see an error like this:

Resolving dependencies...
cabal: Could not resolve dependencies:
[__0] trying: myproject-0.1.0.0 (user goal)
[__1] next goal: base (dependency of myproject)
[__1] rejecting: base-4.12.0.0/installed-4.1... (conflict: myproject =>
base>=4.11 && <4.12)
[__1] rejecting: base-4.12.0.0, base-4.11.1.0, base-4.11.0.0, base-4.10.1.0,
base-4.10.0.0, base-4.9.1.0, base-4.9.0.0, base-4.8.2.0, base-4.8.1.0,
base-4.8.0.0, base-4.7.0.2, base-4.7.0.1, base-4.7.0.0, base-4.6.0.1,
base-4.6.0.0, base-4.5.1.0, base-4.5.0.0, base-4.4.1.0, base-4.4.0.0,
base-4.3.1.0, base-4.3.0.0, base-4.2.0.2, base-4.2.0.1, base-4.2.0.0,
base-4.1.0.0, base-4.0.0.0, base-3.0.3.2, base-3.0.3.1 (constraint from
non-upgradeable package requires installed instance)
[__1] fail (backjumping, conflict set: base, myproject)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: base, myproject

The important line in here is:

[__1] rejecting: base-4.12.0.0/installed-4.1... (conflict: myproject =>
base>=4.11 && <4.12)

Which means: "I have base-4.12.0.0 available, but this conflicts with the version bound specified in myproject, namely base>=4.11 && <4.12."

Release Specific Migrations

Per-release migration guides for GHC can be found at https://ghc.haskell.org/trac/ghc/wiki/Migration.

Pinning the new GHC version

If you have the compiler pinned in cabal.project (or cabal.project.local) you'll need to update that line. For example, you'll change cabal.project to contain:

with-compiler: ghc-8.6.2

Rebuilding Your Project

Once you've completed the steps above, rebuild your project with either cabal v2-build or stack build.

edit description
or press Ctrl+Enter to savemarkdown supported