Long story short, 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!).
cons
", ahah) about each of those packages?Run the command "$ sudo apt-get install haskell-platform" and press Enter. It will automatically start downloading Haskell on your system after authenticating you with the root password. After installing, you will receive a confirmation message.
stack is unable to share the caches of extra-deps or git sources, whereas cabal treats everything equally and can share builds between projects . Both stack and cabal can be used to create reproducible builds, with a caveat: ghc is non-deterministic and can produce different binary outputs for the same input.
If you have installed the Haskell Platform, open a terminal and type ghci (the name of the executable of the GHC interpreter) at the command prompt. Alternatively, if you are on Windows, you may choose WinGHCi in the Start menu. And you are presented with a prompt. The Haskell system now attentively awaits your input.
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.
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.
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