Using cabal sandbox libraries

Update Dec 2017: Dear reader, this post was written in a time when Stack did not exist and Haskell users had to deal with cabal directly. For most intents and purposes, you will have a much better experience using Stack.

That being said, the content of this post should still be valid.

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:

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…