How do I use stack to install locally authored Haskell modules for global usage?

487 Views Asked by At

I have a locally authored Haskell project, which produces both:

  1. a binary executable, and
  2. several new Haskell modules, which I'd like made accessible to my other, Haskell based, executables.

After:

stack build
stack install

I'm finding that:

  1. the binary executable (#1, above) runs just fine from any directory.
  2. But, the new Haskell modules (#2, above) are only found when I'm running from within my project directory! (That is, for any executable other than #1, above.)

I need to be able to find the new modules from anywhere. How can I achieve this?

1

There are 1 best solutions below

4
On BEST ANSWER

Each stack project is in its own sandbox, so the compiled modules can only be used within that project. Compiled dependencies (which come from a stackage snapshot) sometimes get shared between projects.

Note that you can list a relative path in the packages list, and point to this package. It will get built again, but it can be directly used in another project this way. Why the extra building? Stack has a different model of projects than cabal-install - it does not allow mutations to the package DB to affect how your other projects build.

One option for sharing such a package is to have it in a git repo and use https://docs.haskellstack.org/en/stable/custom_snapshot/ , but that stuff is still a bit new.