Haskell/Getting set up
This chapter will explore how to install the programs you'll need to start coding in Haskell.
Haskell is a programming language, i.e. a language in which humans can express how computers should behave. It's like writing a cooking recipe: you write the recipe and the computer cooks it.
To write Haskell programs, you need a program called a Haskell compiler. A compiler is a program that takes code written in Haskell and translates it into machine code, a second, more primitive language which only computers can understand. Using the above analogy, the compiler is the oven that bakes your batter (code) into a cookie (executable file), and you can't get the recipe from the cookie afterward.
Anyway, to start learning Haskell, download and install the Haskell platform. It will contain the "Glasgow Haskell Compiler", GHC for short, and everything else you need.
Very first steps
After you have installed the Haskell Platform, it's now time to write your first Haskell code.
For that, you will use the program called GHCi (the 'i' stands for 'interactive'). Depending on your operating system, perform the following steps:
- On Windows: Click Start, then Run, then type 'cmd' and hit Enter, then type
ghciand hit Enter once more.
- On MacOS: Open the application "Terminal" found in the "Applications/Utilities" folder, type the letters
ghciinto the window that appears and hit the Enter key.
- On Linux: Open a terminal and run the
You should get output that looks something like the following:
___ ___ _ / _ \ /\ /\/ __(_) / /_\// /_/ / / | | GHC Interactive, version 6.6, for Haskell 98. / /_\\/ __ / /___| | http://www.haskell.org/ghc/ \____/\/ /_/\____/|_| Type :? for help. Loading package base ... linking ... done. Prelude>
The first bit is GHCi's logo. It then informs you it's loading the base package, so you'll have access to most of the built-in functions and modules that come with GHC. Finally, the
Prelude> bit is known as the prompt. This is where you enter commands, and GHCi will respond with what they evaluate to.
Now you're ready to write your first Haskell code. In particular, let's try some basic arithmetic:
Prelude> 2 + 2 4 Prelude> 5 * 4 + 3 23 Prelude> 2 ^ 5 32
The operators are similar to what they are in other languages:
+ is addition,
* is multiplication, and
^ is exponentiation (raising to the power of, or ).
Now you know how to use Haskell as a calculator. A key idea of the Haskell language is that it will always be like a calculator, except that it will become really powerful when we calculate not only with numbers, but also with other objects like characters, lists, functions, trees and even other programs (if you aren't familiar with these yet, don't worry).
GHCi is a very powerful development environment. As we progress through the course, we'll learn how we can load source files into GHCi, and evaluate different bits of them.
The next chapter will introduce some of the basic concepts of Haskell. Let's dive into that and have a look at our first Haskell functions.
Read in another language
This page is available in 1 language