13

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?
4
  • 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 9, 2021 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 9, 2021 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 haskell.org/ghcup
    – danidiaz
    Jan 9, 2021 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 for some extra details.
    – duplode
    Jan 9, 2021 at 15:43

2 Answers 2

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.

9
  • 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 9, 2021 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 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 9, 2021 at 18:04
  • 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 9, 2021 at 18:16
  • 1
    @Enlico Yup, that's it.
    – duplode
    Jan 9, 2021 at 19:00
  • 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, 2021 at 21:26
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.

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.
    – Enlico
    Jan 9, 2021 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 stackage.org Jan 9, 2021 at 20:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.