Installing Diagrams

In preparation for my forthcoming series reproducing Newton’s calculation of the orbit of Kirch’s comet, I have been investigating Brent Yorgey’s Diagrams package.

After successfully running the tutorial example in https://diagrams.github.io/doc/quickstart.html#your-first-diagram once, I had difficulties using it in new projects (and even reproducing the tutorial), for possibly related reasons:

  1. I usually use stack for development, but can only install Diagrams with cabal
  2. Diagrams has been updated to use GHC 9.0, but the last LTS release in stack (as of July 2021) is still 8.8

So here is my note to self about how to install Diagrams on a new installation of Linux Mint Uma, (including usrmerge – I don’t know if this is needed on a new install as opposed to an upgrade).

Install Haskell stack from the software manager (to ensure that there will be only one instance of stack, and it will be on the path).

Get the current versions of stack and cabal:

stack upgrade
sudo apt install cabal-install
cabal update

cabal install cabal-install

(Update: This worked on my main laptop, but on the other one, the last command failed because it could not find zlib. Fixed with

sudo apt install zlib1g-dev

Create a new project

stack new comets simple
cd comets
stack setup

Create Main.lhs in comets/src (The tutorial uses Main.lhs (literate Haskell) rather than Main.hs)

Edit the stack and cabal files in the new project:

stack.yaml

resolver: nightly-2021-07-13 (Any nightly from July should work)
extra-deps:
Diagrams (WordPress won’t let me format this correctly – follow the examples in the file)

comets.cabal

main-is: Main.lhs
build-depends: base >= 4.12, diagrams-lib, diagrams-svg

Still in the new project folder:

cabal install diagrams
cabal configure
cabal build

cd dist/build/comets
./comets -o circle.svg -w 400

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: