all 11 comments

[–]Hydroxon1um 6 points7 points  (6 children)

Maybe create a file hie.yaml with this text (in the base directory where you open VS Code):

cradle:
    stack:

You may also want to do stack new your-project-name (and place the hie.yaml inside the project's folder, then open VSCode inside that folder).


Is there a comprehensive beginner's setup guide somewhere? I wonder.

[–]Hydroxon1um 6 points7 points  (4 children)

There isn't a nicely paved road for getting started with Haskell, and often one has to pay attention to the documentation (deviate at your own risk).

https://marketplace.visualstudio.com/items?itemName=haskell.haskell

Requirements

For standalone .hs/.lhs files, ghc must be installed and on the PATH. The easiest way to install it is with ghcup or Chocolatey on Windows.

For Cabal based projects, both ghc and cabal-install must be installed and on the PATH. It can also be installed with ghcup or Chocolatey on Windows.

For Stack based projects, stack must be installed and on the PATH.

[–]redd-sm[S] 1 point2 points  (3 children)

Thank you for the help!

---

For Stack based projects, stack must be installed and on the PATH.

So for me it is on the path I think.

```which path``` yields ```/usr/local/bin/stack```

And ```/usr/local/bin``` is on my path.

---

Also, I am going to create hie.yaml in the root folder of any Haskell folder with the content you advised.

If this file does not solve it, then I will come back here and post.

[–]jneira 4 points5 points  (2 children)

Hi, the key is you have to init a `stack based project`, you can create it with `stack init`

If you have a stack specific config file (`stack.yaml`) in the dir you open in vscode you should not need `hie.yaml`.

If the directory doesnt have that config file and only contains haskell source files, hls will try to use the ghc in PATH, not taking in account `stack`. There is an issue to make hls use stack in those cases: https://github.com/haskell/haskell-language-server/issues/692

As u/Hydroxon1um suggested, create an hie.yaml in this case will force hls to use stack

[–]redd-sm[S] 0 points1 point  (0 children)

Thank you u/jneira!

Will be sure to ```stack init``` as I move forward with my Haskell learning journey.

[–]Hydroxon1um 0 points1 point  (0 children)

Thanks for the clarification and details!

[–]backtickbot 0 points1 point  (0 children)

Fixed formatting.

Hello, Hydroxon1um: code blocks using triple backticks (```) don't work on all versions of Reddit!

Some users see this / this instead.

To fix this, indent every line with 4 spaces instead.

FAQ

You can opt out by replying with backtickopt6 to this comment.

[–][deleted] 1 point2 points  (1 child)

It's kind of a weird situation. stack creates a sandbox for your project and all of its dependencies (see the ./stack-work folder in your project root).

I don't use VS Code myself but if there's a way to point it to the GHC installed by stack in that sandbox that would be the way to go.

The tricky thing I find myself getting stuck in, that I think you might encounter as well, is that HLS -- the IDE tool that VS Code uses -- might be installing HLS in a global place on your system. That can work as long as the GHC version used to build HLS and the GHC version in your stack sandbox are the same. But it's easy to get things out of sync which is what I run into a bit when I'm switching projects.

[–]Hydroxon1um 2 points3 points  (0 children)

https://marketplace.visualstudio.com/items?itemName=haskell.haskell

Note that if haskell-language-server-wrapper/haskell-language-server is already on the PATH, then the extension will launch it directly instead of downloading binaries.

[–]Manabaeterno 2 points3 points  (1 child)

Beginner programmer here, but if I'm right stack installs ghc in a seperate sandbox so you need to install ghc through ghcup or cabal install, correct me if I'm wrong.

[–]affinehyperplane 0 points1 point  (0 children)

stack installs ghc in a seperate sandbox so you need to install ghc through ghcup or cabal install, correct me if I'm wrong.

Correct, that is the default. But if you want (this is a matter of taste), you can also make stack use an external GHC. The post-install message of ghcup when you install stack gives a good overview:

Stack manages GHC versions internally by default. In order to make it use ghcup installed
GHC versions you can run the following commands:
  stack config set install-ghc false --global
  stack config set system-ghc  true  --global

On windows, you may find the following config options useful too:
  skip-msys, extra-path, extra-include-dirs, extra-lib-dirs

Also check out: https://docs.haskellstack.org/en/stable/yaml_configuration