Introduction

Haskell is a purely functional programming language. In imperative languages (C, C++, Java, Python...) you get things done by giving the computer a sequence of tasks and then it executes them. While executing them, it can change state.

function add(a, b) {
    return a + b;
}

There are control flow structures for doing some action several times. In purely functional programming, you don't tell the computer what to do as such but rather you tell it what stuff is. The factorial of a number is the product of all the numbers from 1 to that number, the sum of a list of numbers is the first number plus the sum of all the other numbers, and so on. Those operations are expressed in the form of functions.

Unless specifically told, Haskell won't execute functions until it is absolutely has to return a result. That goes well with referential transparency and it allows you to think of programs as a series of transformations on data.

Haskell is elegant and concise. Because it uses a lot of high level concepts, Haskell programs are usually shorter than imperative equivalents. And shorter programs are easier to maintain than longer ones and have less bugs.

The interactive REPL can be invoked in the terminal by running ghci. Defined functions can be run from files ending in .hs. If you have a file myFunctions.hs, the contents can be run by typing :l myFunctions as long as the file is located in the direcory that ghci was invoked from. To recomplile the functions after changes, run :r.

ghci can be used to perform simple arithmetic operations as well as to run more complex functions. See Starting Out.

results matching ""

    No results matching ""