Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

Course Introduction: Two New Ways of Thinking About Programs

Lesson 1 of 17 in the free Functional & Logic Programming notes on Siksha Sarovar, written by Rohit Jangra.

Welcome to Functional & Logic Programming

Until now, almost every program you have written has been imperative — a sequence of commands that change variables step by step. This course introduces two radically different paradigms:

  • Functional programming (Haskell): a program is a collection of mathematical functions. There are no assignment statements, no loops, and no changing state — only expressions that are evaluated.
  • Logic programming (Prolog): a program is a collection of facts and rules. You don't tell the computer how to compute an answer — you describe what is true, ask a question, and the system searches for the answer itself.

The paradigm map

How this course is organised

Syllabus blockLessons that cover it
Intro to FP, Haskell & GHCi, basic types, designing programsUnit 1 → "The Functional Paradigm" and "Basic Types & Definitions"
Data types, tuples, lists, input/output, control structuresUnit 1 → "Tuples, Lists, I/O & Control Structures"
Lambda calculus: syntax, conversions, normal forms, Church–Rosser, combinatorsUnit 1 → "The Lambda Calculus"
Graph reduction, Three Instruction MachineUnit 1 → "How Haskell Runs: Graph Reduction & the TIM"
Programming with lists, building vocabulary, functions over listsUnit 2 → "Programming with Lists"
Pattern matching and recursionUnit 2 → "Pattern Matching & Recursion"
Overloading, type classes, type checkingUnit 2 → "Overloading, Type Classes & Type Checking"
Algebraic typesUnit 2 → "Algebraic Data Types"
Intro to logic programming, basic constructsUnit 3 → "Introduction to Logic Programming"
Database & recursive programmingUnit 3 → "Database & Recursive Programming"
Computation model, theory & applications of logic programsUnit 3 → "The Computation Model of Logic Programs"
Prolog: introduction, programming, arithmetic, structure inspectionUnit 4 → "Programming in Prolog" and "Structure Inspection"
Second-order programming, logic grammars, search techniquesUnit 4 → "Second-Order Programming" and "Logic Grammars & Search"
Lab experiments (Haskell + Prolog)"Lab Practicals" lesson at the end

Why learn paradigms you may never "use at work"?

  1. They change how you think. Recursion, immutability and pattern matching — once they click in Haskell — make you a better Java/Python programmer too.
  2. Mainstream languages are absorbing them. Lambdas in Java, list comprehensions in Python, Option/Result types in Rust, LINQ in C# — all came from functional programming.
  3. They power real systems. Haskell runs in banking and compilers; Prolog-style logic powers SQL query planners, type checkers, expert systems and parts of AI reasoning.
  4. Exams love them. The questions are predictable — evaluate a lambda expression, write a recursive list function, trace a Prolog query — and every one of them is practised in these lessons.

How to study this course

  1. Install GHC (Haskell) and SWI-Prolog in week one. Both are free; both run on Windows/Linux/Mac. Every concept sticks 10× better after you type it into the REPL yourself.
  2. Evaluate by hand first. Lambda-calculus reductions and Prolog query traces are pen-and-paper skills; the interpreter is only there to confirm your manual answer.
  3. Do the lab experiments alongside the theory units — the lab lesson at the end of this course maps each experiment to the unit that explains it.
  4. Trace every diagram. The Mermaid diagrams in this course show evaluation orders and search trees step by step — walk through them before moving on.

The three paradigms side by side (a favourite exam comparison)

AspectImperative (C, Java)Functional (Haskell)Logic (Prolog)
A program is...a sequence of commandsa set of function definitionsa set of facts and rules
Basic computation stepassignment / state changeexpression evaluation (reduction)unification + resolution
Repetitionloops (for, while)recursionrecursive rules + backtracking
"Variable" meansa mutable memory cella name bound once to a valuea logical unknown, bound by unification
Control flowwritten by the programmerfollows the structure of expressionssupplied by the search strategy
Result of a runthe final machine statethe value of an expressionanswer substitution(s) for the query
Typical exam tasktrace these statementsevaluate this expressiontrace this query

A 5-mark "compare the programming paradigms" question is answered perfectly by reproducing this table and adding one two-line code sample per paradigm (e.g. factorial as a loop, as a recursive equation, and as a pair of clauses).

How the end-term exam typically samples this course

Question styleTypical weightWhere it is practised here
Define / differentiate (referential transparency, currying, MGU, cut...)2–3 marks each"exam definition" boxes inside every lesson
Evaluate / reduce by hand (Haskell trace, β-reduction, fold expansion)5 marksworked traces in Units 1 & 2
Write a small program (list function, ADT + interpreter, Prolog predicate)5–8 marksclassic-code sections in Units 2–4
Trace a Prolog query / draw the SLD search tree5–8 marksUnit 3 computation model + Unit 4
State a theorem / explain a model (Church–Rosser, TIM, negation as failure)5 marksUnit 1 & Unit 3 theory lessons

Two habits pay the most: always show every intermediate step in a trace (markers are awarded per step), and always give the type signature before a Haskell definition — both signal mastery instantly.

Self-check before you begin

  1. Can you name two differences between declarative and imperative programming?
  2. Which two language families sit under the declarative branch of the paradigm map above?
  3. What does each unit of this course cover, in one phrase per unit?
  4. Which tools should be installed in week one, and what are their REPL commands called?