What is the suggested way of setting up Haskell on Archlinux?
Asked Answered
E

2

16

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?
Exuviae answered 9/1, 2021 at 14:19 Comment(4)
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.Parkland
@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?Exuviae
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 haskell.org/ghcupAcidosis
@Exuviae 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 for some extra details.Puente
P
14

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.

Puente answered 9/1, 2021 at 15:24 Comment(12)
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.Exuviae
[1/2] @Exuviae (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 pulls a lot of haskell-* packages. (2) Yup, I recommend removing haskell-* packages (and ghc, stack, cabal-install, etc.) you got through pacman.Puente
[2/2] @Exuviae (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.Puente
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?Exuviae
@Exuviae Yup, that's it.Puente
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.Bouzoun
@Bouzoun 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.)Puente
@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!Exuviae
@Exuviae GHCup is very useful indeed, and a sound default way of installing the tools (even Stack can be installed through it, by the way).Puente
@duplode, since you mentioned XMonad, do you have something to say on this question?Exuviae
@Exuviae My xmonad directory from that time is in this repository. It might be a touch outdated by now, as I've not been using XMonad for a little while now -- though this is a great excuse to step back in! :D When I get the chance, I'll double-check if it all still works and makes sense; if so, I'll try to distill an answer from it.Puente
@Exuviae After reading Daniel Wagner's answer to your other question, I see the "very slightly better" method he mentions in the next-to-last paragraph is very similar to what I had been using in my XMonad setup. I'll look into writing a complementary answer over there that expands a bit on it.Puente
B
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.

Burleigh answered 9/1, 2021 at 16:7 Comment(2)
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.Exuviae
Stack uses "resolver" files listing versions of libraries, compiler etc. By default it uses the latest Long Term Support resolver. See stackage.orgBurleigh

© 2022 - 2024 — McMap. All rights reserved.