How to downgrade cabal version in Haskell platform? - haskell

I've installed the Haskell platform which came with the 7.10.2 version of ghc and the 1.22.6.0 version of cabal. My favorite editor is Atom, so I've installed the ide-haskell and haskell-ghc-mod. Since the ghc-mod has some problems with cabal>=1.22, I need to downgrade cabal. Haskel platform came with an activate-hs script to switch versions but I didn't understand how it works.

The ./activate-hs script only switches between different already installed platform versions. So if you don't have a prior version of the platform installed it won't help. More generally, you should not probably not downgrade cabal versions, as often compilers are coupled to particular releases of cabal.
But if you did want to, the correct way would just be to create a sandbox and then run cabal-install cabal-install-1.20.2.0 or the like. You can then take the resultant binary and move it into your path directly.

Related

How do you force Haskell's cabal-install program to ignore system libraries?

I'm trying to install the accelerate library from hackage, but it keeps giving me an error saying that my version of base package (4.15.1.0) is too new. Is there a way to force it to ignore the base package that's installed as a system-wide package, and instead download the correct version of the base package?
I'm using Manjaro Linux, ghc version 9.0.2, and cabal version 3.4.0.0. I can't seem to find any documentation on how to force it to ignore a system package. I've tried searching on https://cabal.readthedocs.io/en/3.6/ , but it doesn't seem to mention it anywhere.
The base package is always hard-fixed to the compiler version. The only way to switch base is to switch to a different GHC. That's easier with Stack than it is with Cabal-install – just select a snapshot that has a suitable base version (lts-18.24 would do), and Stack will automatically install the corresponding compiler.
But it could well be that you can actually use base-4.15, and just accelerate has conservative dependency bounds. Try installing it with --allow-newer=base. If that works, give the maintainers a PR that the version bounds can be relaxed.

How do you get the most recent version of Cabal for Haskell?

I've just spent about an hour going in circles trying to get version 2 of Cabal. Initially I found that the version that came with my LinuxMint install was version 1, so I tried cabal update, didn't do it. So I found instructions which said to use cabal install Cabal cabal-install. Did it, got an error. Found that the error apparently had to do with using the most current version of Haskell. So I installed version 7 to get Cabal. Seemed to work, looked like I finally got Cabal version 2. But I also want the most current version of Haskell so I downloaded the binaries for it and installed that again--now it seems like Cabal is set back to version 1. Is it not possible to have both version 8 of Haskell and version 2 of Cabal?
Along the lines of danidiaz's comments, I suggest directly installing cabal-install in your home directory.
Begin by making sure you are actually using the 8.x version of GHC you want (use which ghc and ghc --version if need be). Also, get rid of any other cabal-install versions you might have installed, so that there is less margin for confusion.
The [directory] ~/.cabal/bin is not in my PATH variable, should I put it in toward the front of its definition?
Exactly. ~/.cabal/bin is the default location for executables locally installed with cabal-install, which includes cabal-install itself, and so it must be in the PATH. Putting it towards the front of the PATH will give it priority over any system-wide installation of cabal-install installed with your package managers. (Note that that won't be an issue if you remove said system-wide installation beforehand.)
Once the terrain is clear, you can download a suitable binary tarball from Cabal's download page, extract the executable and put it in ~/.cabal/bin. As danidiaz notes, the binaries there aren't necessarily at the latest stable version (as I write this, the Linux binaries are 2.2.0.0 rather than 2.4.0.0), but that likely won't matter, as once you have some version of cabal-install available you can simply run...
cabal new-update # For version 2.4 or above; if not, use cabal update instead.
cabal new-install cabal-install
... which will update your cabal-install to the latest stable version.
(Note that I'm using the new-* cabal-install commands. I strongly advise you to do the same.)
Also, looking through the Cabal folder, I don't see binaries. The only folders present are Distribution, Language, tests, and doc.
It sounds like you downloaded the sources of Cabal, the library, rather than the ones of cabal-install, the tool. The cabal-install sources are also available from the download page linked above (as I write this, their version is 2.4.0.0). If you are getting them from GitHub instead, you should look into the cabal-install directory, rather than the Cabal one. Either way, once yo are in the appropriate directory, to install from source run...
./bootstrap.sh --sandbox
... which only requires GHC (as opposed to a pre-existing cabal-install). Once it finishes building cabal-install, the script will tell you the location of the executable (presumably in a .cabal-sandbox/bin subdirectory). Copy the executable to ~/.cabal/bin and proceed as before.

Switching through different versions of GHC included 7.0.4

I need to compile some code starting from the GHC version 7.0.4 until the most recent 8.0.2.
I know that using stack I can do something like:
stack init --resolver lts ...
on the local project but the lts versions don't go further than GHC 7.8.3.
How can I switch back to older version of GHC without using stack?
No, you cannot have stack use ghc 7.0.4 because it's not in their snapshot. The oldest compiler stack supports is 7.8.3.
Theoretically, stack can provide support for older compilers, but the Stackage server was announced at August, 2014 and GHC 7.0.4 was released on June, 2011. That's my educated guess of why 7.0.4 is not present.
If you want your code to have support for older compilers, I would recommend you to use a CI system like Travis. Another alternative if you are using a Ubuntu machine is to use Herber's PPA for installing the older compilers.
Do you really need stack to build the project, i.e. stack.yaml and stack build?
If it is not the case and you just want multiple ghc versions, you might want to try
nix, it have various ghc versions.
But keep in mind that older than 8.0.2 is not officially support but it might still working.
docker, use it to setup any version you want
travis, as previous answer suggested.

Haskell Platform through Macports

I have installed the Haskell Platform through MacPorts. Although many Haskell libraries are available as MacPorts packages, some are not. What is the proper way to install them? (without inconsistencies or duplications)
Use cabal
cabal install <packagename>
One nice thing about cabal is, by default, it puts stuff in ~/.cabal/, so you won't have to worry about it conflicting with your system files.

What is the "officially" recommended way of installing Haskell from source?

How does one install Haskell from source (on Red Hat) now?
The current page has broken links and conflicting advice.
From http://www.haskell.org/platform/linux.html
Get and install GHC 7.6.3 prior to building the platform
From http://www.haskell.org/ghc/download_ghc_7_6_3
For most users, we recommend installing the Haskell Platform instead of GHC. The current Haskell Platform release includes a recent GHC release as well as some other tools (such as cabal), and a larger set of libraries that are known to work together.
(the link to cabal-install is broken).
The broken link should be pointing to http://www.haskell.org/haskellwiki/Cabal-Install instead. If you want to install from source, you're first going to have to compile and install GHC from source, then you can install the Haskell Platform from its source.
I'm not really sure what conflicting information you're seeing, if you want to build from source you have to install GHC first. Alternatively, you can just install the Haskell Platform from the distributable (might not be possible on Red Hat) and it'll install GHC for you. Both are pretty straightforward.

Resources