Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

haskell: what are some good ways to switch between ghc (for a different base)?

I am a beginner in Haskell so I'm just wondering what are some good ways to switch between different verisons of ghc so that we can still cabal install when the dependency of some Hackage requires an older version of base, rather than running into Dependency tree exhaustively searched like this:

Resolving dependencies...
cabal: Could not resolve dependencies:
trying: bnfc-system-tests-0.1.0.0 (user goal)
next goal: base (dependency of bnfc-system-tests-0.1.0.0)
rejecting: base-4.8.0.0/installed-901... (conflict: bnfc-system-tests =>
base>=4.5 && <4.8)
rejecting: base-4.8.0.0, 4.7.0.2, 4.7.0.1, 4.7.0.0, 4.6.0.1, 4.6.0.0, 4.5.1.0,
4.5.0.0, 4.4.1.0, 4.4.0.0, 4.3.1.0, 4.3.0.0, 4.2.0.2, 4.2.0.1, 4.2.0.0,
4.1.0.0, 4.0.0.0, 3.0.3.2, 3.0.3.1 (global constraint requires installed
instance)
Dependency tree exhaustively searched.

I'm using a mac and I installed my haskell platform (with ghc-7.10.1.1) with brew (brew install ghc & cabal-install). So I went to grab an older version of haskell platform here, added an alias for the older version of ghc in my .zshenv

ghc-78 --version
The Glorious Glasgow Haskell Compilation System, version 7.8.4

and made a new config file in ~/.cabal with

-- compiler: ghc-78

But after that when I ran

cabal --config-file="./config78" install --only-dependencies --enable-tests

in the sandbox directory, I still got into the dependency problem indicating that I was still using ghc 7.10. (So after that I changed the line back to compiler: ghc and added ghc-location:

-- ghc-location: the/new/directory/ghc 

under program-locations and I was still getting the same thing.)

What did I do wrong and what are some good ways to switch between different versions of ghc? (for example in Node.js I can use n, a version control manager)


--Update:

Even after I have uncommented the line

compiler: ghc-78

cabal --config-file="./config78" install --only-dependencies --enable-tests would still give me the dependency error (even if I used --sandbox-config-file instead ). cabal sandbox hc-pkg list base would show base-4.8.0.0, even if I init sandbox with the config file:

cabal --config-file="./config78" sandbox init

However,

cabal install -w ghc-7.8.4

works as long as ghc-7.8.4 is in path, as suggested by Daniel in the comment.

like image 609
Archy Will He 何魏奇 Avatar asked Sep 01 '15 18:09

Archy Will He 何魏奇


2 Answers

I would recommend using stack for this:

  • Download: https://github.com/commercialhaskell/stack/wiki/Downloads
  • In-depth guide: https://www.fpcomplete.com/blog/2015/08/new-in-depth-guide-stack
  • Reddit post on the in-depth guide: https://www.reddit.com/r/haskell/comments/3j6ria/new_indepth_guide_to_stack/

By selecting a resolver you are also selecting a GHC version, so your code will be built with the same GHC that Stackage used. Use a resolver like lts-2.17 for GHC 7.8.4 or lts-3.3 for GHC 7.10.2, etc.

Also, I suggest using:

system-ghc: false

in your stack.yaml file so that stack always uses its own tool-chain.

like image 95
ErikR Avatar answered Oct 05 '22 09:10

ErikR


Lines that start with -- are treated as comments by Cabal's config file parser. So you should change

-- compiler: ghc-78

to

compiler: ghc-78

like image 26
Mikhail Glushenkov Avatar answered Oct 05 '22 08:10

Mikhail Glushenkov