8

I am trying to set an enverionment for Haskell and I installed stack. After the installation I realized the GHC 8.6.4 version is not the one that I need (8.0.2).

compiler-exe: /home/manny/.stack/programs/x86_64-linux/ghc-tinfo6- 
8.6.4/bin/ghc
compiler-bin: /home/manny/.stack/programs/x86_64-linux/ghc-tinfo6- 
8.6.4/bin
compiler-tools-bin: /home/manny/.stack/compiler-tools/x86_64-linux- 
tinfo6/ghc-8.6.4/bin

So I installed the GHC 8.0.2. I know if I change the global-config file I could resolve the problem indication the right compiler that I want but what is the proper command to make such change avoiding editing the configuration files ?

I tried:

stack config set --compiler ghc-8.0.2

without success. My compiler is still 8.6.4.

~/.stack$ stack ghc -- --version
The Glorious Glasgow Haskell Compilation System, version 8.6.4

Thank you!

2

2 Answers 2

9

You've misunderstood the stack config command. Wherever you use --compiler, you are telling Stack which compiler version it should use for the current command - but since editing the config doesn't use any kind of compiler, this doesn't really change anything.

Just running stack config set gives you

Missing: COMMAND

Usage: stack config set COMMAND [--help]
  Sets a field in the project's stack.yaml to value

which explains the problem better. If you ask for help, Stack tells you that the only valid COMMAND values are resolver, system-ghc, and install-ghc.

So you can set the resolver to a particular compiler version, with

stack config set resolver ghc-8.0.2

But you can't set the compiler from the command line, because it's not a supported command for stack config set.

Sign up to request clarification or add additional context in comments.

Comments

2

I tried the method above, but failed to run ghci. The error message is shown below:

Error: [S-6602]
       Stack could not load and parse /root/.stack/global-project/stack.yaml as a YAML configuraton file.

       While loading and parsing, Stack encountered the following error:

       YAML parse exception at line 7, column 18:
       mapping values are not allowed in this context

       For help about the content of Stack's YAML configuration files, see (for the most recent release of Stack)
       http://docs.haskellstack.org/en/stable/yaml_configuration/.

So here's an another approach.

If your ghc version is, say 9.2.7, then its corresponding LTS version is 20.18. So you may just change the file /root/.stack/global-project/stack.yaml to:

# This is the implicit global project's config file, which is only used when
# 'stack' is run outside of a real project.  Settings here do _not_ act as
# defaults for all projects.  To change stack's default settings, edit
# '/root/.stack/config.yaml' instead.
#
# For more information about stack's configuration, see
# http://docs.haskellstack.org/en/stable/yaml_configuration/
packages: []
resolver: lts-20.18

Note: different ghc version corresponds to different LTS version. So if you are not using ghc-9.2.7, then your LTS version is certainly not 20.18.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.