Question

I’m trying to write a project with the Hakyll library. In order to avoid messing up with my system, I’d install it in a cabal sandbox in the same folder where my Hakyll project lives.

Being more or less a beginner, I’m still struggling with getting the pest practices right. A simple approach would be to just do

$ cabal sandbox init
$ cabal install hakyll
$ cabal exec ghc -- --make site.hs

where the last line compiles my Hakyll generator using the libraries in the sandbox. The obvious disadvantage is that this is not reproducible. The main version of Hakyll could have change when I try to run it again from a clean checkout.

Another approach would be to write a proper project.cabal file (For example like this: chromaticleaves.cabal) and then do cabal install or cabal run.

However, I feel that this may be a bit too much information. As I do not intend to publish this project any more than needed, I’m not really convinced I need to put a project name and version number in there. (For example, in a Ruby Gemfile, I would also only specify the libraries and nothing else unless I wanted to publish a gem myself.)

So, eventually I figured that with a file like

$ cat project.cabal
cabal-version: >= 1.2
library
  build-depends: base   >=4.6
               , containers
               , process
               , hakyll >=4.5
               , pandoc
               , pandoc-types

I can type

$ cabal sandbox init
$ cabal install --only-dependencies
$ cabal exec ghc -- --make site.hs

and it seems to download all dependencies and is able to compile the file.

Is this a reasonable approach or is the best practice really to give a full specification with name, version and executable sections in the cabal file?

Edit: Apparently, my approach does not let me do cabal repl. So either there exists a completely different way of doing it or it seems I have to go with a fuller specification.

Was it helpful?

Solution

I use your first approach myself for my Hakyll-based webpage. You don't need to create a .cabal file to pin the Hakyll version, you only need to add the following line to cabal.config:

constraints: hakyll == 4.5

I think that cabal repl will work with this approach, but you will need to load site.hs manually (:l site.hs). Or you can use cabal exec ghci -- site.hs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top