Haskell Course - Lesson 1 - Introduction and GHCi

Some courses start by explaining all the properties of Haskell. Others by dedicating entire lessons/chapters to the theory behind the language, Category theory (a branch of mathematics), lambda calculus (more maths), etc. Don't worry β€” I can hear you hyperventilate β€” we won't do that here. πŸ™ƒ

Those approaches have nothing wrong, but they are designed to teach people with previous knowledge of mathematics and computer science β€” which most don't have.

This course is geared to people that do NOT code The lecture will be written as if the person already knows basic computing skills (like installing programs and searching over the internet β€” πŸ§“πŸΌ will have a hard time, but they are welcome! πŸ˜ƒ) but nothing about programming. And further explanations will be provided by clicking on highlights like

this one
.

Ok. Are you ready? Let's go! πŸ”₯

GHCi (Glasgow Haskell Compiler Interactive)

A

compiler
is a
program
that translates code written in one
programming language
into another language. In our case, the compiler will translate Haskell into something our computer can understand. We need compilers and
interpreters
because computers don't understand our language and we don't want to write code in the computer's language like in the old days (trust me πŸ™ˆ).

The cool thing is that it doesn't matter if you have Windows, macOS, Linux, or whatever. Write Haskell, and the compiler will manage the rest. Cool right?

GHC (Glasgow Haskell Compiler) is a compiler and interactive environment for Haskell. Using GHC we can:

  • Compile programs and execute them like any other app.
  • Evaluate Haskell expressions on the fly using the interactive environment provided by the GHC (the GHCi).

For now, we'll use the GHCi. This interactive environment allows us to write code, hit enter, and get the result instantly! ⚑️⚑️ Allowing us to verify hypotheses faster than a 90' movie hacker.

The Terminal/Console/Shell

We'll use the GHCi through our terminal. The terminal is a text-only window through which we can interact with our computer. You write text, hit enter, stuff happen, and you get text as response (most of the time).

Terminal, shell, and command-line are technically different things. But many use those terms interchangeably β€” especially in programming tutorials. πŸ™„ So, keep in mind that if someone says "go to the command-line" or "open the shell," they talk about the terminal app πŸ˜‰.

Here's how it looks:

Screenshot of a Linux terminal

All operating systems have a Terminal app already installed.

We won't learn to use the terminal here because we'll only need a single

command
for this course. But, if you want to learn to code, you'll eventually need to comfortably use your terminal.

Installing GHCi

GHCi is usually installed with other tools (like Cabal, Stack, and a language server), but we don't need them for now, so we'll only install GHC. You can install the other tools later when you need them.

Each operating system has its own steps. I'll show you the most common ways. Select your OS (operating system) and follow the instructions:

Installing GHC in Linux

If you rock Linux, you know how this goes:

Ubuntu

sudo apt-get ghc

Fedora

sudo dnf install ghc

Other package-managers:

Follow the official documentation

Using distribution packages:

Follow the official instructions

Let's test if everything is OK. Open your terminal, type ghci and hit Enter. You should see a line saying your GHCi version and another line with Prelude> waiting for you to write something.

The first thing that we'll learn is how to quit using GHCi. On Prelude> type :q and hit enter. It'll quit GHCi and return you to your terminal. To close your terminal, just close it like any other program.

Awesome! You already took your first steps to become a programmer! πŸŽ‰ We're ready to start our Haskell journey! πŸ˜ƒ

Homework

I'll provide some homework and the solution to the previous lesson's homework in each lesson. In this case, though, there isn't much to ask. So I'll give you some tasks that will help you level up your programming knowledge in general:

  • Search and learn the difference between source code and machine code. (Searching and finding information is a crucial skill for programmers. We can't β€” and don't β€” remember everything about every technology we use. So, if you want to be a great coder, you have to be an expert searcher.)
  • Search and learn the difference between a compiler and an interpreter.
  • Familiarize yourself with the terminal: Search how to use the cd and ls commands.

Don't worry if you don't understand everything. If you "kind of" understand, that's good enough. Each time you encounter the concept, you'll gain a little bit more insight πŸ’ͺ.

That's it! πŸ˜„ In the next lesson, we'll learn about Haskell Types! 🀩 See you there!!

PD: If you find this course valuable, please share it so more people can learn! πŸ˜„