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.
I would recommend using stack
for this:
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With