Install Haskell with GHCup

A quick and easy way to get Haskell set up and keep it up to date is to use GHCup. Follow the link for directions. GHCup will install a few different components. Haskell has a history of what is, by modern standards, poor tooling. It's not a new language, Haskell was developed in the early 90s, and for the first couple of decades of its existence was mostly an academic programming language, and it shows.

Things are far better now, but not quite as slick as Golang or Rust's ecosystems which have the benefit of being recently developed with contemporary thinking about tooling and package management. Here's some initial guidance.

GHC - Glasgow Haskell Compiler

The open source compiler for Haskell. Technically this is just one of the Haskell compilers available, as the intent of Haskell was to be a specification and not an implementation, thereby not locking anyone into a single compiler.

The reality is that most people are using GHC, and that most experimentation and expansion of the Haskell specification is happening in GHC. It's considered the most advanced Haskell compiler and to make your life simpler, just go with GHC and forget that there are other choices, until you find a compelling reason to do so.

Cabal

The standard package system for Haskell software, and for the longest time was the way to build Haskell programs, find and download packages, and build and publish packages. Many people still use Cabal, and it's not too bad. I personally don't I use the next tool in the list.

Stack

aka The Haskell Tool Stack, it's a program for working with Haskell projects, and is a bit more modern in its approach. This is the approach I use, and while still not perfect, it's at least somewhat reasonable, and once you establish a practice it's trivial to use Stack for package and product management. Stack actually leverage Cabal internally to do the actual work of package management, so the're reasonably compatible and interchangeable.

HLS

The Haskell Language Server, an implementation of the Language Server Protocol for Haskell. The Language Server Protocol, or LSP, defines a protocol use between an editor or IDE and a language server that provides language features like auto complete, go to definition, find all references, etc.. For a long time (and this is where the poor tooling rep was spot on), you would have a hard time working with Haskell outside of Emacs. With the HLS, we get a decent language aware IDE from VSCode, and many other editors that are now LSP aware.

Using the REPL

Once you've got the Haskell tooling installed and before you get involved with setting up a full project with either Stack or Cabal, to get your feet wet you can use the REPL combined with a single Haskell file like this:

1
2
3
$ # create your source file
$ touch scratch.hs # or whatever you want to call it
$ stack repl scratch.hs

This starts the REPL. You'll see a prompt Prelude>, indicating you've got the REPL with Prelude (the standard library), and your file is loaded (even if it's empty). From here, you can use a few of these handy REPL commands:

Command Purpose Example
:? Get help on all the commands
:quit Quit the repl
:type Output the type of the term or expression Prelude> :t [1,2,3]
:kind Get the kind of a Type Prelude> :k Maybe
:edit Opens the currently loaded file (scratch.hs in our example) in the default editor. Saving and quitting the editor will reload the file in the REPL
:reload Reloads the currently loaded file. You can have an editor open on the file in the REPL, and iterate on the file, saving it each time. Then use the :r command in the REPL to load the latest save

Editing Your File

The REPL is handy of course for trying things out. But since it's only one line at a time (there's a kind of multi-line ability but it's not great), it's handy to have a file in your REPL session. You can either keep the file open in your favorite editor and iterate over it making changes, and periodically reload into the REPL with the :r command, or you can use the :e command to fire up your default editor (VIM in my case) make edits, and when you save/quit, the REPL will automatically reload your source file.

That's the basics... Happy Hacking!