TLDR: Could we have a per-project file that GHCup and editor plugins could use as a single source of truth for the expected toolchain version?
I’ve been trying to find a simple setup for GHC, Cabal, HLS with VSCode support. I want it to be useful for beginners and intermediate Haskell developers. I have something that I find acceptable but I would like to improve it while keeping it simple. This setup is used by students.
I want a setup that is able to specify which version of GHC, cabal, HLS use
per project. This, I think, would help intermediate people to have multiple projects and not need to worry about environment setup that much.
So far I am suggesting students a setup that only needs to have GHCup and VSCode with a minimal config. Thanks to GHCup they not even need to install GHC, HLS, cabal manually.
This is the VSCode configuration for haskell.haskell we use.
{
"haskell.manageHLS": "GHCup",
"haskell.upgradeGHCup": false,
"haskell.toolchain": {
"ghc": "recommended",
"hls": "recommended",
"cabal": "recommended",
"stack": null
},
"editor.formatOnSave": true
}
A Makefile, given in a template offers convenient wrappers to run, repl or test the code. Again, it only requires GHCup to be installed.
GHC_VERSION=recommended
CABAL_VERSION=recommended
GHCUP_ENV=ghcup run --ghc $(GHC_VERSION) --cabal $(CABAL_VERSION)
.PHONY: run
run:
$(GHCUP_ENV) -- cabal run
.PHONY: test
test:
$(GHCUP_ENV) -- cabal test --test-show-details=direct
.PHONY: repl
repl:
$(GHCUP_ENV) -- cabal repl
.PHONY: clean
clean:
rm -rf dist-newstyle
rm -rf bin
One of the challenges is that there is no single source of truth for what are the expected version of the toolchain. What is the recommended version could change any time during the course, not ideal. It’s easy to pin the version in the Makefile.
GHC_VERSION=9.6.7
CABAL_VERSION=3.12.1.0
But the editor might use a different version.
The workaround for this in VSCode would be to setup a profile with custom settings or use workspaces. So we would be left out of the simple “open the directory” use case.
I think that having some .ghcup or maybe more agnostic .haskell file where the expected versions of GHC, Cabal, HLS could be stated would be beneficial.
VSCode haskell.haskell plugin could pick that information. A ghcup run could do the same. Other tools could also benefit from a simpler declaration.
I am relaying heavily on ghcup. I know it’s not the only option to setup an
environment and there are many supporters of using Nix to have a full environment setup per project. But I believe ghcup is better for beginners and even intermediate.
- Would you think is beneficial this per project ability to setup Haskell tooling?
- Do you think there is value on designing it beyond GHC up so other tools can leverage it?
I am also aware of asdf but that is yet another dependency to impose, I would like to minimize the setup needed.
Thanks!