Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 57 ยท Getting started

Introduction to Haskell

Meet Haskell, a purely functional language with static types and lazy evaluation. See what makes it different, where it is used, and how this course runs code.

Haskell is a purely functional programming language. Programs are built from functions that take values and return values, and the compiler checks the types of everything before the program runs. It is named after the logician Haskell Curry, and its standard has been shaped by researchers and industry users since 1990.

Learning Haskell changes how you think about code, even if you keep using other languages afterwards. Ideas such as immutable data, small composable functions, Maybe instead of null and types that rule out whole classes of bugs have spread into Rust, Swift, Kotlin, TypeScript and modern Java. In Haskell you meet them in their original, most uncompromising form.

This lesson explains the three big ideas (purity, laziness and static types), shows where Haskell is used, and explains how the examples in this course work.

The three big ideas

What makes Haskell different

Pure Functions only compute results. They change nothing else.
Lazy Values are computed only when they are needed.
Statically typed The compiler checks every type before the program runs.
Inferred You rarely have to write the types yourself.

These four ideas shape every lesson that follows.

1 / 2

Purity

A pure function always returns the same result for the same arguments and has no side effects. It does not print, read files, change a global variable or look at the clock. If you call square 4 a thousand times, you get 16 a thousand times.

That sounds limiting, because real programs must print and read input. Haskell solves this by giving actions their own type, IO. An IO action is a description of something to do, and the pure core of your program stays separate from the impure shell. You will meet this in IO basics much later. For now, the useful consequence is that you can understand a function by reading it alone: nothing hidden can change what it returns.

Laziness

Haskell is lazy: an expression is evaluated only when its value is actually needed. That lets you write definitions of infinite lists, because only the part you use is ever built:

HASKELL
naturals :: [Integer]
naturals = [0 ..]          -- all the natural numbers

firstFive :: [Integer]
firstFive = take 5 naturals -- [0,1,2,3,4]

Laziness is powerful and occasionally surprising (it can cause memory build-up when misused). Two later lessons cover it properly: lazy evaluation and strictness.

Static types with inference

Every expression has a type known at compile time. If you try to add a number to a string, the program does not compile. Yet you seldom write many types, because Haskell infers them. Here is a function with its type written out, which is good style for top-level definitions:

HASKELL
double :: Int -> Int
double n = n * 2

Read Int -> Int as "takes an Int, returns an Int". We look at types closely in basic types.

A first look at the syntax

Haskell has very little punctuation. There are no parentheses around function arguments, no return keyword in most functions and no semicolons at the end of lines. A call is written as the function name followed by its arguments, separated by spaces:

HASKELL
area :: Double -> Double -> Double
area width height = width * height

main :: IO ()
main = print (area 3 4.5)   -- prints 13.5

Compare that with the JavaScript version, which is the stand-in we will use to run ideas in your browser:

JS The same idea in JavaScript

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Where Haskell is used

Haskell is not only a teaching language. Companies and projects use it where correctness matters or where code must be transformed in clever ways:

  • Compilers and tools: the Pandoc document converter, the ShellCheck script linter and the PureScript compiler are written in Haskell.
  • Finance: several banks and trading firms use it for pricing, risk and internal tools.
  • Web back ends and infrastructure: frameworks such as Servant and Yesod, and large internal systems at companies like Meta (spam filtering rules) have used it.
  • Research and education: it is a standard language for teaching functional programming and type theory.

It is a smaller ecosystem than Python or JavaScript, so you will do more reading of types and fewer copy-and-paste searches. Many learners find that trade worth making.

How this course runs code

There is a practical limit: Haskell is not installed on this site, so we cannot run real Haskell in your browser. The course handles it in two honest ways:

  1. Real Haskell code is shown read-only. These blocks are real, valid Haskell, but they are for reading. To run them yourself, install GHC as shown in the next lesson.
  2. Runnable stand-ins are written in JavaScript. A stand-in imitates the idea (a curried function, a lazy list, a Maybe value) so you can experiment. Every stand-in is labelled, and it is not the real thing: JavaScript has different evaluation rules and no static type checker.

Treat the JavaScript examples as models for understanding, and the Haskell blocks as the truth. When the two differ, the lesson will say so.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does it mean that a Haskell function is pure?

    Purity means the result depends only on the arguments and the function changes nothing outside itself, so you can reason about it in isolation.
  2. 2. What is lazy evaluation?

    Under lazy evaluation a value is computed only when something demands it, which is why infinite lists are possible.
  3. 3. Why do the lessons use JavaScript TryIt blocks?

    The site cannot run real Haskell, so runnable stand-ins model the ideas while real Haskell stays read-only.
  4. 4. In double :: Int -> Int, what does the part after :: describe?

    :: means "has type". Int -> Int is the type of a function from Int to Int.

Summary

  • Haskell is a pure, lazy, statically typed functional language with type inference.
  • Pure functions give the same output for the same input and have no side effects.
  • Lazy evaluation computes values only when needed, which allows infinite lists.
  • Haskell is used for compilers, finance, back ends and research.
  • In this course, real Haskell is read-only and JavaScript stand-ins are runnable models.

Next, set up the tools: Installing GHC and using GHCi.