Using cabal sandbox libraries

30 Nov 2013, by Pang Yan Han

This was a finding from me trying out the Yesod Web Framework and reading the book here.

I installed yesod in a sandbox (located at /home/yh/yesod), by executing the following commands from $HOME:

mkdir yesod
cd yesod
cabal sandbox init
cabal update
cabal install yesod
cabal install yesod-bin

After that, I prepended $HOME/yesod/.cabal-sandbox/bin to $PATH, cd back to $HOME, and ran:

yesod init

I named the project yosog, so yesod init created a directory named yosog, located at $HOME/yosog. Essentially, the yesod binary (installed above through cabal install yesod-bin) provides a scaffolding for developing web applications using yesod. More details can be found here.

Thereafter, I proceeded to type this example and save it into $HOME/yosog/helloworld.hs, and ran:

runhaskell helloworld.hs

only to get:

helloworld.hs:5:8:
Could not find module `Yesod'
Use -v to see a list of the files searched for.

But, yesod was obviously installed earlier at $HOME/yesod. I just needed a way to make use of it…

After some googling, I ran into the following stack overflow question

And proceeded to run:

runhaskell -package-conf=$HOME/yesod/.cabal-sandbox/x86_64-linux-ghc-7.4.1-packages.conf.d helloworld.hs

And voila! The program ran!

comments powered by Disqus