6

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!

duplode
  • 33,731
  • 7
  • 79
  • 150
user1657666
  • 351
  • 2
  • 9
  • Possible duplicate of [upgrading the ghc version being used by haskell stack](https://stackoverflow.com/questions/45533610/upgrading-the-ghc-version-being-used-by-haskell-stack) – Koterpillar Apr 27 '19 at 09:46
  • 1
    Try editing the `resolver` field in `/home/bradn/.stack/global-project/stack.yaml`. – bradrn Apr 27 '19 at 11:28

2 Answers2

7

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.

Isaac van Bakel
  • 1,772
  • 10
  • 22
1

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.