Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I add a library to a Stack project? (Haskell)

I know this question has probably been asked a thousand times, but I’m currently learning Haskell, and I’m making a little random number generator / guessing game. I got all the terminal input and output working, and started trying to figure out random number generation, and I can’t figure it out. First, I tried adding the random library to the .cabal file, and whenever I ran stack build, it removed it from the file. Then, I tried putting it into the stack.yaml file. After deleting the lock file, and putting it in there, it compiled without an error. So, I tried importing it with import System.Random like I’ve seen everywhere else, and it didn’t work. I tried asking a question on the Github repo, but nobody answered my question.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Do you have a package.yaml file in your directory? Stack will (re-)generate your .cabal file from it every time it runs. So:

  • Add the dependency in stack.yaml only if the library is not on Stackage or you want a different version.
  • Add the dependency in package.yaml.
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading