12

I'd like some guidance on what's the (best) way to have Haskell work on Archlinux.

By work I mean all, in terms of the ghci command line tool, installing packages I don't have - such as vector-space, which this answer to a question of mine refers to -, and any other thing that could be necessary to a Haskell obstinate learner.

Archlinux wikipage on Haskell lists three (alternative?) packages for making Haskell work on the system, namely ghc, cabal-install, and stack. I have the first and the third installed on my system, but I think I must have installed the latter later (unless it's a dependency to ghc) while tampering around (probably in relation to Vim as a Haskell IDE). Furthermore, I have a huge amount of haskell-* packages installed (why? Who knows? As a learner I must have come multiple times to the point of say uh, let's try this!).

  • Are there any pros and cons ("cons", ahah) about each of those packages?
  • Can they all be used with/without conflicts?
  • Does any of them make any other superfluous?
  • Is there anything else I should be aware of which I seem apparently ignorant about based of what I've written?
Enlico
  • 23,259
  • 6
  • 48
  • 102
  • 2
    `ghc` is just the compiler; `cabal` is a build tool, and `stack` is tool built around `cabal` that includes a curated package repository. They are not mutually exclusive. – chepner Jan 09 '21 at 14:25
  • @chepner, from your comment I'd deduce that `cabal` is a dependecy of `stack`, but I have the latter installed on my system, and not the former. Am I missing something? – Enlico Jan 09 '21 at 14:27
  • The standard Haskell packages for many distributions are often a bit old. If you are ok with not using the standard package manager, perhaps you could give ghcup a try https://www.haskell.org/ghcup/ – danidiaz Jan 09 '21 at 14:28
  • @Enlico Stack depends on Cabal (the library) but not on cabal-install (the command-line tool, which is often referred to as just "Cabal"). See [this answer of mine](https://stackoverflow.com/a/42601219/2751851) for some extra details. – duplode Jan 09 '21 at 15:43

2 Answers2

12

Arch Linux's choice of providing dynamically linked libraries in their packages tends to get in the way if you are looking to develop Haskell code. As an Arch user myself, my default advice would be to not use Arch's Haskell packages at all, and instead to install whatever you need through ghcup or Stack, starting from the guidance in their respective project pages.

duplode
  • 33,731
  • 7
  • 79
  • 150
  • So your suggestion is to use `pacman` just to install `stack` or anything fulfilling the same role, and than use that to install haskell packages. And probably I should also uninstall all `haskell-*` packages? Based on the answer you linked in the comment to my question (and also because it looks like `stack` downloads an older version of `ghci` than the one I install with `pacman`), I'd go for `cabal-install` instead of `stack`. In relation to this, why did you write _ghcup/Cabal or Stack_ instead of _cabal-install or stack_? I think I'm still missing something. – Enlico Jan 09 '21 at 17:29
  • [1/2] @Enlico (1) My suggestion is not using `pacman` at all, and instead getting the tools through the instructions in their project pages. Even the [`stack` package from the Community repository](https://archlinux.org/packages/community/x86_64/stack/) pulls a lot of `haskell-*` packages. (2) Yup, I recommend removing `haskell-*` packages (and `ghc`, `stack`, `cabal-install`, etc.) you got through `pacman`. – duplode Jan 09 '21 at 18:04
  • [2/2] @Enlico (3) I said "ghcup [...] or Stack" because with either you can quickly set up a working Haskell environment with GHC plus a build tool. Unlike Stack, cabal-install doesn't manage GHC versions for you, so the alternative would be using ghcup for that, and also for installing cabal-install. Note that if you choose ghcup you can also get Stack later with `cabal install stack`. (4) With "ghcup/Cabal" I had really meant "ghcup/cabal-install". I wouldn't have mentioned the Cabal vs. cabal-install difference weren't it for chepner's comment. – duplode Jan 09 '21 at 18:05
  • 1
    Ok, so your suggestion (or one of the suggestions) is to just install `ghcup` and then use _it_ to install `ghi` and `cabal-install` (and then, when I want/need, other `haskell-*` packages and, why not, also `stack`). However you suggest to install `ghcup` not via `pacman`. Is this summary correct? – Enlico Jan 09 '21 at 18:16
  • 1
    @Enlico Yup, that's it. – duplode Jan 09 '21 at 19:00
  • Confirming that as an archlinux user of many years my _current_ preference is using ghcup to get the basics and not using *any* of the archlinux haskell packages. Whether you decide to use stack or cabal-install (my choice) after that to get various packages is really a matter of taste. This is how I got my current xmonad set up working. – brittAnderson Jan 10 '21 at 20:34
  • 1
    @brittAnderson Indeed, this arrangement works fine with XMonad. (In my case, I have a Cabal project in my `~/.xmonad` so that XMonad's `build` script can call `cabal exec ghc` on my `xmonad.hs`.) – duplode Jan 10 '21 at 21:26
  • @duplode, after more than 1 year, I've not coded much Haskell, but I have to say that your suggestion of using `ghcup` is really working, for those few times that I play around with Haskell and want to be sure everything is up to date. `ghcup tui` is so convenient! – Enlico May 09 '22 at 08:33
  • @Enlico GHCup is very useful indeed, and a sound default way of installing the tools (even Stack can be installed through it, by the way). – duplode May 09 '22 at 22:37
2

You are basically there. Try the following:

  • ghci: If you get the Haskell REPL then it works.

  • stack ghci: Again you should get the Haskell REPL. There are a lot of versions of GHC, and stack manages these along with the libraries. Whenever you use a new version of GHC stack will download it and create a local installation for you.

stack is independent of your Linux package manager. The trouble is that your distro will only have the Haskell libraries it actually needs for any applications it has integrated, and once you step outside of those you are in dependency hell with no support. So I recommend that you avoid your distro Haskell packages. stack does everything you need.

If you installed stack from your Linux package manager then you might want to uninstall it and use a personal copy (i.e. in your ~/.local directory) instead. Then you can always say stack update to check you have the latest version.

Once you have stack going, create a project by saying stack new my-project simple. Then go into the project folder and start editing. You can work with just a .hs file and GHC if you really want, but its painful; you will do much better with stack, even if you are just messing around.

You'll also need an editor. Basic functionality like syntax highlighting is available in pretty much everything, but once you get past Towers of Hanoi you are going to want something better. I use Atom with ide-haskell-ghcide. This uses the Haskell Language Server under the hood, so you will need to install that too. I know a bunch of other editors have HLS support, but I don't have experience with them.

Paul Johnson
  • 17,438
  • 3
  • 42
  • 59
  • _will download it and create a local installation_ I guess this is the download that happend as soon as I run `stack ghci` a few minutes ago for the first time. FWIW, I see that `ghci` tells me `GHCi, version 8.10.3`, whereas `stack ghci` tells `8.8.4` (`stack --version` is 2.5.1), so it seems that Arch is downloading a more recent version of the compiler than `stack` does. – Enlico Jan 09 '21 at 17:25
  • 1
    Stack uses "resolver" files listing versions of libraries, compiler etc. By default it uses the latest Long Term Support resolver. See https://www.stackage.org/ – Paul Johnson Jan 09 '21 at 20:41