Learning Haskell: Getting Setup

Get your machine setup to start learning Haskell

Grant Leadbetter
Level Up Coding

--

Photo by Juan Gomez on Unsplash

This is the first part of my series of articles on learning Haskell, I’ll be taking you through my journey learning the functional programming language.

If you’ve already got your machine setup to learn Haskell you can move onto my next post in this series, Learning Haskell: Getting Started.

Before we can start writing any Haskell we should first get it setup on our machine.

To start writing Haskell you only need a couple of things, firstly you’re going to need a text editor or IDE, feel free to use whatever you’re comfortable with, I personally use Visual Studio Code but there are plenty of options to pick from. There’s everything from Notepad to Eclipse, it really doesn’t matter at this stage what one you pick.

The next thing we’ll begin using is the Haskell Platform which is a collection of useful things for developing in Haskell, it’s described on the website as Haskell with batteries included.

Here’s a list of everything included in the Haskell Platform;

  • The Glasgow Haskell Compiler (used to compile your Haskell)
  • The Cabal build system (used to build and package Haskell libraries and programs)
  • The Stack Tool (a cross platform tool for developing Haskell projects)
  • Core Packages (A collection of packages to make Haskell development easier, think libraries used to deal with arrays, time, filepaths, etc)

I’m using Mac OS X as my operating system, if you’re using another operating system feel free to visit this site to see what the installation instructions are for your OS.

On MacOS the recommended way to install the Haskell Platform is to use the ghcup which is a general installed for Haskell, it will include the GHC (Glasgow Haskell Compiler) and cabal-install which is the command line interface for Cabal. We can install both of these with the curl command below.

curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh

Once that is completed the next step is to install the Haskell tool Stack which you can do with the curl command below.

curl -sSL https://get.haskellstack.org/ | sh

Congratulations, you’ve now taken your first step towards learning Haskell by installing the necessary tools 🥳

We can now open the GHCI, which is a REPL that allows you to interact with Haskell in your terminal, you’ll be familiar with REPLs if you’ve already used languages like Ruby.

To open the GHCI simply enter ghci in your terminal, you can also do this via stack with the command stack ghci this should launch the REPL.

From within the REPL we can now start to program in Haskell, Lets try some simple addition.

10 + 5

10 + 5 is 15, it works!

The REPL is a simple way to begin interacting with Haskell, it allows us to immediately get feedback on what’s going on and it’s a great way to start exploring the language, if you want to initialise a variable, we simply use the let keyword.

a = 10, a + 5

I’m starting to go outside the scope of this article, so I’ve only got one more thing to mention when using the REPL, if you want to quit simply type :q

We now have Haskell set up on our machine to begin writing programs, now you’re ready for my next article in this series, Learning Haskell: Getting Started

--

--