1 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html xmlns=
"http://www.w3.org/1999/xhtml">
4 <meta http-equiv=
"Content-Type" content=
"text/html; charset=utf-8" />
5 <meta http-equiv=
"Content-Style-Type" content=
"text/css" />
6 <meta name=
"generator" content=
"pandoc" />
7 <title>Advent of Code
2018</title>
8 <style type=
"text/css">code{white-space: pre;}
</style>
9 <link rel=
"stylesheet" href=
"modest.css" type=
"text/css" />
13 <h1 class=
"title">Advent of Code
2018</h1>
15 <p>Code to solve the
<a href=
"http://adventofcode.com/2018/">Advent of Code
</a> puzzles. This year, I'm using the puzzles to develop my skills in
<a href=
"https://wiki.haskell.org/Haskell">Haskell
</a>.
</p>
16 <p><a href=
"http://learnyouahaskell.com/chapters">Learn you a Haskell
</a>,
<a href=
"https://www.haskell.org/tutorial/index.html">Introduction to Haskell
98</a>, and
<a href=
"https://hackage.haskell.org/">Hackage
</a> are good resources.
</p>
17 <p>The
<a href=
"https://docs.haskellstack.org/en/stable/README/">Stack documentation
</a> and
<a href=
"http://howistart.org/posts/haskell/1/">How I Start: Haskell
</a> are good sources of using the tools.
</p>
18 <h1 id=
"toolchain">Toolchain
</h1>
19 <p>I'm using the basic Haskell Platform installation, togeher with
<code>stack
</code> to manage the packages and dependencies (install with
</p>
20 <pre><code>$ sudo aptitude install haskell-platform haskell-stack
</code></pre>
22 <h2 id=
"creating-the-repository-and-project">Creating the repository and project
</h2>
23 <p>Create the repository as normal: create the project in Gitolite, clone it, and insert the
<code>.gitignore
</code> and
<code>README.md
</code> files.
</p>
24 <p>There's just one package, with the code in sub-directories of the
<code>src
</code> directory. Each day will generate one (or more) entries in the
<code>adventofcode17.cabal
</code> file.
</p>
25 <p>Create the basic
<code>stack
</code> project. This will create a new directory. Note that this new directory name can't have a hyphen-delimited word that's just digits, so the project will have to be
<code>advent-of-code
</code></p>
26 <pre><code>stack new advent-of-code --bare simple
</code></pre>
27 <p>Modify the
<code>stack.yaml
</code> file as needed, such as adding the
<code>ghc-options
</code> stanza.
</p>
28 <h2 id=
"creating-subsequent-days">Creating subsequent days
</h2>
29 <p>Each day lives in a separate directory within the
<code>src
</code> directory. It will also need it's own stanza in
<code>advent-of-code.cabal
</code>.
</p>
31 <pre><code>stack build
</code></pre>
33 <pre><code>stack build advent01
</code></pre>
35 <pre><code>stack exec advent01
</code></pre>
36 <p>If you want to pass in additional RTS parameters, do it like this:
</p>
37 <pre><code>stack exec -- advent01 +RTS -K0 -RTS
</code></pre>
38 <p>Run interactively with
</p>
39 <pre><code>stack ghci advent-of-code:exe:advent01
</code></pre>
40 <p>To profile, use
</p>
41 <pre><code>stack build --executable-profiling --library-profiling --ghc-options=
"-fprof-auto -rtsopts
"</code></pre>
43 <pre><code>stack exec -- advent01 +RTS -p -hy
</code></pre>
44 <p>Generate the profile graph with
</p>
45 <pre><code>stack exec hp2ps advent01.hp
</code></pre>
46 <h1 id=
"packages">Packages
</h1>
47 <p>Stack is using the
<a href=
"https://www.stackage.org/lts-12.20">12.20-lts resolver
</a> for packages, so make sure you read the
<a href=
"https://www.stackage.org/lts-12.20/docs">correct documentation for the packages included in it
</a>.
</p>
48 <p>When you use a new package, use
</p>
49 <pre><code>stack solver
</code></pre>
50 <p>to see how the
<code>stack.yaml
</code> file needs to change, and
</p>
51 <pre><code>stack solver --update-yaml
</code></pre>
52 <p>to implement the changes.
</p>
53 <h1 id=
"ihaskell">IHaskell
</h1>
54 <p>Install following the
<a href=
"https://github.com/gibiansky/IHaskell">IHaskell instructions
</a>.
</p>
56 <pre><code>stack exec jupyter -- notebook
</code></pre>
57 <h1 id=
"readme">Readme
</h1>
58 <p>Build this readme file wth
</p>
59 <pre><code>pandoc -s README.md
> README.html
</code></pre>
60 <p>(Using the
<a href=
"https://github.com/markdowncss/modest">Modest style
</a>.)
</p>