-
Notifications
You must be signed in to change notification settings - Fork 4
0026 Email Tutorials Haskell For Beginners ‐ Lambda (λ) Calculus Primer
Video: https://youtu.be/9MtE5ONrQyk?si=yOZVmPRse1zKuDsF
- Why Learn the Lambda Calculus?
- What Is the Lambda Calculus?
- Variants of the Lambda Calculus
- Lambda Abstraction vs Ordinary Functions
- The General Form:
λx. expression - Anonymous Functions and Naming
- Function Application by Juxtaposition
- Prefix Application (e.g.
+ x 1) - Lambda Calculus as “Assembly Language” for FP
- Summary of the Primer
- Glossary
- Multiple Choice Questions (with Answers)
The goal of this primer is to give you a basic understanding of the theoretical foundations of functional programming.
Why it helps:
- It shows you how functions and computation can be described with a tiny core language.
- It gives intuition for what’s happening under the hood when you write Haskell or other functional code.
- Students who see lambda calculus before diving deep into functional programming often find the later material easier.
In later videos/modules you’ll see more about:
- Evaluation rules (β-reduction, etc.)
- Reduction orders (normal order, applicative order)
- Church–Rosser theorems (about confluence)
This video focuses on the core idea: what the lambda calculus is and how lambda abstractions and applications work.
The Lambda Calculus is a formal system for expressing computation, originally developed by Alonzo Church.
Key points:
- It’s formal: Everything is defined via precise syntax and rules.
- It’s about computation: It shows how to compute purely via functions.
- It uses the Greek letter λ (lambda) to introduce functions, hence the name.
Historically and practically:
- Many functional languages (Haskell, OCaml, etc.) can be understood as “fancy front ends” that eventually compile down to some form of lambda calculus.
- You can think of lambda calculus as a kind of “assembly language for functional languages”.
There are many variants, each adding more structure (especially types):
- Simple untyped lambda calculus – Just terms and functions, no types. (This is what we focus on here.)
- Simply typed lambda calculus – Adds basic types and type annotations.
- System F (polymorphic lambda calculus) – Adds universal quantification / polymorphism.
- System Fω (F-omega) – Extends System F with type operators (types of types).
For this course:
-
We only need the simple untyped lambda calculus.
-
If you want to go deeper later, look up:
- Hindley–Milner type system
- System F
You do not need those to follow this course; they’re just pointers for the curious.
Let’s start with a familiar, mathematical-style function:
- Function name:
f - Parameter:
x - Body:
x + 1
We might write:
( f(x) = x + 1 )
Examples:
- ( f(1) = 2 )
- ( f(2) = 3 )
Here:
-
fhas a name, which we use to call it:f(1),f(2).
In lambda calculus, we write the same idea as a lambda abstraction:
λx. x + 1
This has three main pieces:
-
λ– introduces a lambda abstraction (a function). -
x– the formal parameter (the variable bound by the lambda). -
.– separates the parameter(s) from the body. -
x + 1– the function body (expression to compute).
This lambda abstraction means:
“A function which, given an
x, returnsx + 1.”
Important distinction:
- The mathematical version
f(x) = x + 1gives the function a name (f). - The lambda version
λx. x + 1has no name; it is an anonymous function.
Every lambda abstraction in the simple untyped lambda calculus looks like this:
λ variable . expression
For example:
-
λx. x– the identity function (returns whatever you give it). -
λx. x + 1– increment function. -
λy. y y– appliesyto itself (not type-safe in the typed world, but valid in untyped lambda calculus).
You can think of it as:
λx. E= a function that takes an argumentxand produces the result of expressionE.
In pure lambda calculus, functions are anonymous:
- The lambda abstraction
λx. x + 1is itself the function. - There is no built-in mechanism for names like
f. Names are an extra layer we add when we embed lambda calculus into a programming language.
In practice (in actual languages):
-
We do usually bind lambda abstractions to names for convenience:
f = \x -> x + 1
-
But in the pure calculus itself, the basic building blocks are variable names and lambda abstractions, not named functions like
f.
Variables:
- The function itself is unnamed.
- The parameter (like
x) does have a name inside the function body – we call it a bound variable in that context.
In normal math notation, we apply functions like:
f(1)f(2)
In lambda calculus, we apply a lambda abstraction to an argument by placing them next to each other (this is called juxtaposition):
(λx. x + 1) 1
Read as:
“Apply the lambda function
λx. x + 1to the argument1.”
This corresponds to:
-
f(1)in the usual style. - Result:
1 + 1 = 2.
Similarly:
(λx. x + 1) 2 -- corresponds to f(2)
Result:
-
2 + 1 = 3.
We often add parentheses around the lambda abstraction to remove ambiguity:
(λx. x + 1) 1(λx. x + 1) 2
This “just put them next to each other” style is what “application by juxtaposition” means.
You can even apply lambdas to other lambdas, e.g.:
(λx. x x) (λy. y)
…but that’s for later; the video keeps it simple at this stage.
In the lambda calculus, function application is always written in prefix form:
- Instead of
x + 1(infix), - You use something like
+ x 1(prefix).
The key idea:
-
+is just another function. - In prefix notation, the function comes first, followed by its arguments.
So, in a more “pure lambda calculus” style, the body might be something like:
+ x 1
instead of:
x + 1
The position of the operator (+) is just a convention:
- Infix:
x + 1 - Prefix:
+ x 1 - Postfix:
x 1 +
The lambda calculus chooses prefix for uniformity: every function application looks like:
f arg1 arg2
regardless of whether f is “+” or any other function.
One of the most useful mental models from this video:
Think of the lambda calculus as a kind of assembly language for functional programming languages.
- Languages like Haskell, OCaml, etc. often compile to some intermediate representation that’s based on a variant of the lambda calculus.
- High-level constructs (let bindings, pattern matching, etc.) can be lowered down to lambda abstractions and applications.
So, by understanding the lambda calculus, you:
- Gain insight into how functional languages implement functions and expressions.
- Get intuition for what’s going on when your code is evaluated and optimized.
From this primer, you should now understand:
-
What the lambda calculus is: A formal system developed by Alonzo Church to express computation via functions.
-
Why it matters:
- It underpins many functional languages.
- It provides a minimal “core” to reason about programs.
-
Basic syntax:
- Lambda abstraction:
λx. expression - Function application: by juxtaposition –
(λx. x + 1) 1
- Lambda abstraction:
-
Anonymous functions:
- Functions themselves are unnamed (anonymous); only variables are named.
-
Prefix application:
- Function symbol first, then arguments — e.g.
+ x 1.
- Function symbol first, then arguments — e.g.
Later modules will build on this:
- Defining the simple untyped lambda calculus rigorously.
- Evaluation rules (especially β-reduction).
- Different reduction orders.
- The Church–Rosser theorems, which say (roughly) that evaluation order doesn’t affect the final result if it exists.
-
Lambda Calculus A formal system for expressing computation using functions, developed by Alonzo Church.
-
Lambda Abstraction (
λx. expression) A function definition in lambda calculus: givenx, computeexpression. -
Formal Parameter The variable introduced by a lambda (
xinλx. x + 1). -
Function Body The expression after the dot in a lambda abstraction (
x + 1inλx. x + 1). -
Anonymous Function A function with no name; in lambda calculus, every function is a lambda abstraction like
λx. ...rather than a namedf. -
Application / Function Application Using a function on an argument; written as juxtaposition in lambda calculus, e.g.
(λx. x + 1) 3. -
Juxtaposition Placing expressions next to each other to denote application:
f xmeans “applyftox”. -
Prefix Notation Notation where the function/operator appears before its arguments:
+ x 1instead ofx + 1. -
Simple Untyped Lambda Calculus The variant of lambda calculus without types; terms can be combined freely.
-
System F / System Fω More advanced typed lambda calculi adding polymorphism and type operators.
Use these to test your understanding of Part 26.
1. What is the lambda calculus primarily used for?
A. Rendering graphics on a screen B. Formally expressing computation using functions C. Managing operating system processes D. Defining SQL queries
Answer: B
2. Who developed the lambda calculus?
A. Alan Turing B. Alonzo Church C. John von Neumann D. Haskell Curry
Answer: B
3. Why is it called the “lambda” calculus?
A. It was invented in a lab named LAMBDA. B. It uses the Greek letter λ to define functions. C. It only works with exponential growth functions. D. It is an acronym.
Answer: B
4. Which of the following is a correct lambda abstraction?
A. λ. x + 1
B. x. λx + 1
C. λx. x + 1
D. x λ. x + 1
Answer: C
5. In the lambda abstraction λx. x + 1, what is x?
A. A constant B. A function name C. The formal parameter (bound variable) D. The result of the function
Answer: C
6. How is function application written in the lambda calculus?
A. f(x)
B. x f
C. (λx. x + 1) 3
D. apply(λx. x + 1, 3)
Answer: C (Option C is the lambda calculus style: juxtaposition of function and argument.)
7. In the expression (λx. x + 1) 2, what does this correspond to in ordinary math notation?
A. 2(λx. x + 1)
B. x + 1(2)
C. f(λx. 2)
D. f(2) where f(x) = x + 1
Answer: D
8. What does “juxtaposition” mean in the context of lambda calculus?
A. Placing a type annotation next to a term B. Placing the argument next to the function to indicate application C. Putting two lambdas side by side to form a pair D. Writing multiple function definitions on the same line
Answer: B
9. In the lambda calculus, functions are:
A. Always named (like f, g)
B. Always recursive
C. Anonymous lambda abstractions like λx. ...
D. Only allowed to have numeric parameters
Answer: C
10. Why can we think of the lambda calculus as an “assembly language” for functional programming?
A. Because it is compiled directly to machine code. B. Because it handles memory management. C. Because high-level functional languages can be translated to lambda-calculus-like intermediate forms. D. Because it uses registers and jumps.
Answer: C
COMPLETE TWO QUIZZES BELOW:
Bernard Sibanda is a global Technology Entrepreneur, Web3 and Software Consultant with a deep focus on Cardano Blockchain, Midnight and Community building.
Key Positions:
- Founder, CTO, Developer Advocate cohort #1, Fullstake Developer, Cardano Ambassador, Catalyst Project Manager, DREP-WIMS:
- Co-founder of ABL Tech and Cardano Africa Live
- EBU-certified Plutus Pioneer (Plutus/Haskell)
- Cohort #1 Plutus Pioneer Developer
- Catalyst Community Reviewer & Funded Projects Manager
-
DRep for WIMS-Cardano (ID:
drep1yguj8zu48n99pv70yl6ckzt9hdgjy8yjnlqs2uyzcpafnjgu4vkul) - Intersect Developer Advocate
- Intersect Committe Member 2025-2026
- Cardano Marketer,Promoter and blogger
- Cardano Open Source Contributor
- Cardano communities and events organizer and builder
- Cardano Ambassador for South Africa
Official links:
- Stablecoins Dex
- Coxygen Global Universities
- WIMS Cardano Global
- Cardano Africa Live
- WIMS Cardano Videos
- Cardano Smart Contract Videos
- Fullstack IT Consulting
Social links: