Gentle Introduction to Dependent Types with Idris


This book is no longer available for sale.

Gentle Introduction to Dependent Types with Idris

About the Book

You can purchase this book on Apress

Dependent types are a powerful concept that allows us to write proof-carrying code. Idris is a programming language that supports dependent types. We will learn about the mathematical foundations, and then write correct software and mathematically prove properties about it.

This book aims to be accessible to novices that have no prior experience beyond high school mathematics. Thus, this book is designed to be self-contained.

The reason for writing this book is that I could not find a book that explained how things work, so I had to do a lot of research on the internet through white-papers, forums, and example code in order to come up with a complete picture of what dependent types are and what they are good for.

The first part of this book serves as an introduction to the theory behind Idris, while the second part is a practical introduction to Idris with examples.

Contributions to the book are welcome on GitHub.

  • Share this book

  • Categories

    • Computers and Programming
    • Computer Science
    • Software Engineering
    • Functional Programming
  • Feedback

    Email the Author(s)

About the Author

Boro Sitnikovski
Boro Sitnikovski

Boro Sitnikovski has over 10 years of experience working professionally as a Software Engineer. He started programming with the Assembly programming language on an Intel x86 at the age of 10. While in high school, he has won several prizes on competitive programming, varying from 4th, 3rd, and 1st place.

He is an Informatics graduate - his Bachelor's thesis was titled "Programming in Haskell using algebraic data structures", and his Master's thesis was titled "Formal verification of Instruction Sets in Virtual Machines". He has also published a few papers on software verification. Other research interests of his include programming languages, mathematics, logic, algorithms, and writing correct software.

He is a strong believer in the open-source philosophy and contributes to various open-source projects.

In his spare time, he enjoys some time off with his family.

Table of Contents

  • Preface and acknowledgments
  • Introduction
  • 1. Formal systems
    • 1.1. MU puzzle example
  • 2. Classical mathematical logic
    • 2.1. Hierarchy of mathematical logic and definitions
      • 2.1.1. Propositional logic
      • 2.1.2. First-order logic
      • 2.1.3. Higher-order logic
    • 2.2. Set theory abstractions
    • 2.3. Substitution and mathematical proofs
      • 2.3.1. Proofs by truth tables
      • 2.3.2. Three-column proofs
      • 2.3.3. Formal proofs
      • 2.3.4. Mathematical induction
  • 3. Type theory
    • 3.1. Lambda calculus
      • 3.1.1. Term reduction
    • 3.2. Lambda calculus with types
    • 3.3. Dependent types
    • 3.4. Intuitionistic theory of types
      • 3.4.1. Intuitionistic logic
  • 4. Programming in Idris
    • 4.1. Basic syntax and definitions
      • 4.1.1. Defining functions
      • 4.1.2. Defining and inferring types
      • 4.1.3. Anonymous lambda functions
      • 4.1.4. Recursive functions
      • 4.1.5. Recursive data types
      • 4.1.6. Total and partial functions
      • 4.1.7. Higher-order functions
      • 4.1.8. Dependent types
      • 4.1.9. Implicit parameters
      • 4.1.10. Pattern matching expressions
      • 4.1.11. Interfaces and implementations
    • 4.2. Curry-Howard isomorphism
    • 4.3. Quantitative Type Theory
  • 5. Proving in Idris
    • 5.1. Weekdays
      • 5.1.1. First proof (auto-inference)
      • 5.1.2. Second proof (rewrite)
      • 5.1.3. Third proof (impossible)
    • 5.2. Natural numbers
      • 5.2.1. First proof (auto-inference and existence)
      • 5.2.2. Second proof (introduction of a new given)
      • 5.2.3. Third proof (induction)
      • 5.2.4. Ordering
      • 5.2.5. Safe division
      • 5.2.6. Maximum of two numbers
      • 5.2.7. List of even naturals
      • 5.2.8. Partial orders
    • 5.3. Computations as types
      • 5.3.1. Same elements in a list (vector)
      • 5.3.2. Evenness of numbers
    • 5.4. Trees
      • 5.4.1. Depth
      • 5.4.2. Map and size
      • 5.4.3. Length of mapped trees
  • Conclusion
  • Further reading
  • Appendices
    • Appendix A: Writing a simple type checker in Haskell
      • Evaluator
      • Type checker
      • Environments
    • Appendix B: Theorem provers
      • Metamath
      • Simple Theorem Prover
    • Appendix C: IO, Codegen targets, compilation, and FFI
      • IO
      • Codegen
      • Compilation
      • Foreign Function Interface
    • Appendix D: Implementing a formal system
  • About the author
  • Notes

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

80% Royalties. Earn $16 on a $20 book.

We pay 80% royalties. That's not a typo: you earn $16 on a $20 sale. If we sell 5000 non-refunded copies of your book or course for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earnedover $13 millionwriting, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub