Generally, I use VSC Code Run Code extension. I have the following command configured:
runhaskell -- -fno-max-relevant-binds -Wincomplete-patterns -isrc
Whenever I am looking at a particular Main.hs file inside my Haskell project.
However, if I need to add the line:
import System.Random
Then, I won’t be able to run it since that dependency is not available in base, I think.
I could, in principle, every time change the command to include a package, like:
runhaskell -- -fno-max-relevant-binds -Wincomplete-patterns -isrc -package=random
However, that seems to be a slow process. Some people suggested cabal repl
for trying function available in my library (src
directory), though seems slow to save, move to the terminal, reload the file, go back to the file and continue.
What’s the fastest way to quickly test haskell code haskellers here think ?
Thank you for any guidance
1 Like
You can use Haskell Language Server and the inline evaluation plugin (automatically enabled): hls-eval-plugin: Eval plugin for Haskell Language Server
I think this link explains how to get VS Code and HLS set up: GitHub - haskell/vscode-haskell: VS Code extension for Haskell, powered by haskell-language-server
3 Likes
What does “test” mean here? Just run the code?
Can’t you open cabal repl
in VSC? It has an in-editor terminal, right? fwiw, using cabal is the correct way to declare dependencies like random
(vs what you’ve done in the OP).
2 Likes
Yes, sorry. I meant just run the code.
I have a hotkey. If I use cabal repl
, I can’t use a hotkey to execute my code. I have to save, move to the in-editor terminal, reload the file write the expression, and then go back. Does that make sense ?
1 Like
Thank you for this. I’ll take a look. Does this take into account external dependencies declared in .cabal file ?
Yes, if you have a correctly configured project with cabal repl working then HLS should too!
1 Like
Thank you for this, I managed to install it !
One question, I get constantly this stderr error:
-- >>> splitMember 1 (Bin Tip 2 (Bin Tip 3 Tip))
-- <stderr>: hPutChar: invalid argument (cannot encode character '\8226')
Do you know if there is some problem with my line of code ?
Tried adding (on macOS):
export GHC_CHARENC=GHC_NO_UNICODE
this line to my ~/.zshrc
file but no luck.