I have a standalone Haskell file I am editing in Visual Studio Code. I’m learning Haskell and simply using ghci
to run my code in the integrated terminal.
However, the VS Code editor is complaining that it Could not find module...
for one of my import
statements (e.g., import System.Random
).
Question: If I don’t want to create a full project with a dependencies list, what can I do?
2
Answers
This seems to work, says the newbie:
cabal install --lib random
(for example)Developer: Reload Window
The
cabal install --help
says:You can make a very light-weight cabal-package-alike inline in Haskell source files like this:
Then you can load ghci by running
cabal repl foo.hs
(wherefoo.hs
is the name of the file with this content). I’m not sure how to configure VS Code to runcabal repl
instead ofghci
but perhaps you can poke around and find it yourself now that you know about this feature of cabal. As a bonus, this gives you machine-checkable documentation of what packages you installed along your way to creating your toys.