Code to solve the Advent of Code puzzles. This year, I’m using the puzzles to develop my skills in Haskell. I’m writing up a commentary on these puzzles and my solutions on my blog.
Learn you a Haskell, Introduction to Haskell 98, and Hackage are good resources.
The Cabal user guide and How I Start: Haskell are good sources of using the tools.
Install Ghcup following the instructions, making sure to load the updated environment with
source /home/neil/.ghcup/env
and then set the default GHC to use with
ghcup set ghc 9.0.1
.
Install Haskell Language Server for Sublime Text
Create the repository as normal: create the project in Gitolite,
clone it, and insert the .gitignore
and
README.md
files.
There’s one package per day, with the code for each package in sub-directories of the root directory.
Create the basic cabal
project.
cabal init
Modify the advent-of-code21.cabal
file as needed, such
as updating the Cabal version and writing the common
stanzas.
Each day lives in a separate directory, with code in the
src
directory.
Compile with
cabal build
or
cabal build advent01
Run with
cabal run advent01
If you want to pass in additional RTS parameters, do it like this:
cabal run advent01 -- +RTS -K0 -RTS
Run interactively with
cabal repl advent01
or
stack ghci advent01:exe:advent01
if the first form is ambiguous.
To profile, use
cabal run advent01 --enable-profiling -- +RTS -N -p -s -hT
Or, you can simplify the RTS options by adding them to a new stanza in the cabal file:
executable advent01prof
import: common-extensions, build-directives
main-is: advent01/Main.hs
build-depends: text, containers, linear, array, pqueue, mtl, lens
ghc-options: -O2
-Wall
-threaded
-eventlog
-rtsopts "-with-rtsopts=-N -p -s -hT"
Only include the -eventlog
directive if you want to use
Threadscope to investigate parallel behaviour.
then running
cabal run advent01prof --enable-profiling
Generate the profile graph with
hp2ps -M advent01.hp
Packages I used a lot:
There are somewhat decent tutorials on Megaparsec and Attoparsec.
Packages I didn’t use much, but need to remember:
Build this readme file wth
pandoc -s README.md > README.html
(Using the Modest style.)