A Gentle Introduction to Mercury

book cover

NOTE: This book is a work in progress.

Author: Zetian Lin (https://sebastian.graphics)

Project repository: https://github.com/bctnry/gentle-introduction-to-mercury

Latest version: Very Early Draft (October 2025)

Contact for sending comments and reviews:
zaaktin.lam {at} outlook [dot] com

You can always download the latest draft on GitHub: https://github.com/bctnry/gentle-introduction-to-mercury/blob/master/main.pdf

Table of Contents

(NOTE: very early draft; subject to change.)

  1. Introduction
    1. What is Mercury?
    2. The state of things as of now
    3. Who’s this book for
    4. The tool we will be using
    5. More importantly... why?
  2. A First Taste of Mercury
    1. Prerequisite: logic programming
    2. Writing the program
  3. Programming in Mercury
    1. Trace Goals
    2. Using the standard library
    3. Basic Datatypes
    4. If-Then-Else
    5. Fundamental concepts
    6. Defining functions
    7. User-defined types
    8. Example 1: Interpreter of a small language
    9. Using multiple modules
    10. Higher-order programming
    11. Exception handling
    12. Advanced goals
    13. Working with other people's libraries
    14. Streams & IO
    15. Generating random numbers
    16. Threads
  4. Advanced Concepts & Usage
    1. Instantiatedness
    2. Modes
    3. Multiple solutions
    4. Definite Clause Grammar
    5. Typeclasses
    6. Existential Types
    7. Purity System
  5. Parsing With Definite Clause Grammar
  6. Foreign Language Interface
    1. Calling back and forth
    2. Working with the Java grade
    3. Working with the CSharp grade
  7. Debugging Mercury Programs