liveBook · Manning

What you will learn in Type-Driven Development with Idris

by Edwin Brady

Chapter by chapter

Chapter 1: Chapter 1. Overview

Introduces type-driven development, contrasts types with tests, and outlines the capabilities of first-class types in Idris.

1.1 What is a type? · 1.2 Introducing type-driven development · 1.2.1 Matrix arithmetic · 1.2.2 An automated teller machine · 1.2.3 Concurrent programming · 1.2.4 Type, define, refine: the process of type-driven development · 1.2.5 Dependent types · 1.3 Pure functional programming · 1.3.1 Purity and referential transparency · 1.3.2 Side-effecting programs · 1.3.3 Partial and total functions · 1.4 A quick tour of Idris · 1.4.1 The interactive environment · 1.4.2 Checking types · 1.4.3 Compiling and running Idris programs · 1.4.4 Incomplete definitions: working with holes · 1.4.5 First-class types · 1.5 Summary

What you learn in chapter 1 →

Chapter 2: Chapter 2. Getting started with Idris

This introduction previews Idris fundamentals and a simple program for calculating average word length.

2.1 Basic types · 2.1.1 Numeric types and values · 2.1.2 Type conversions using cast · 2.1.3 Characters and strings · 2.1.4 Booleans · 2.2 Functions: the building blocks of Idris programs · 2.2.1 Function types and definitions · 2.2.2 Partially applying functions · 2.2.3 Writing generic functions: variables in types · 2.2.4 Writing generic functions with constrained types · 2.2.5 Higher-order function types · 2.2.6 Anonymous functions · 2.2.7 Local definitions: let and where · 2.3 Composite types · 2.3.1 Tuples · 2.3.2 Lists · 2.3.3 Functions with lists · 2.4 A complete Idris program · 2.4.1 Whitespace significance: the layout rule · 2.4.2 Documentation comments · 2.4.3 Interactive programs · 2.5 Summary

What you learn in chapter 2 →

Chapter 3: Chapter 3. Interactive development with types

This introduction explains the type, define, refine workflow and how Idris-powered editor features support it.

3.1 Interactive editing in Atom · 3.1.1 Interactive command summary · 3.1.2 Defining functions by pattern matching · 3.1.3 Data types and patterns · 3.2 Adding precision to types: working with vectors · 3.2.1 Refining the type of allLengths · 3.2.2 Type-directed search: automatic refining · 3.2.3 Type, define, refine: sorting a vector · 3.3 Example: type-driven development of matrix functions · 3.3.1 Matrix operations and their types · 3.3.2 Transposing a matrix · 3.4 Implicit arguments: type-level variables · 3.4.1 The need for implicit arguments · 3.4.2 Bound and unbound implicits · 3.4.3 Using implicit arguments in functions · 3.5 Summary

What you learn in chapter 3 →

Chapter 4: Chapter 4. User-defined data types

This introduction explains why precise, problem-specific data types are valuable in type-driven development.

4.1 Defining data types · 4.1.1 Enumerations · 4.1.2 Union types · 4.1.3 Recursive types · 4.1.4 Generic data types · 4.2 Defining dependent data types · 4.2.1 A first example: classifying vehicles by power source · 4.2.2 Defining vectors · 4.2.3 Indexing vectors with bounded numbers using Fin · 4.3 Type-driven implementation of an interactive data store · 4.3.1 Representing the store · 4.3.2 Interactively maintaining state in main · 4.3.3 Commands: parsing user input · 4.3.4 Processing commands · 4.4 Summary

What you learn in chapter 4 →

Chapter 5: Chapter 5. Interactive programs: input and output processing

This introduction explains how Idris combines pure functions with interactive programs described using IO and executed by the runtime.

5.1 Interactive programming with IO · 5.1.1 Evaluating and executing interactive programs · 5.1.2 Actions and sequencing: the >>= operator · 5.1.3 Syntactic sugar for sequencing with do notation · 5.2 Interactive programs and control flow · 5.2.1 Producing pure values in interactive definitions · 5.2.2 Pattern-matching bindings · 5.2.3 Writing interactive definitions with loops · 5.3 Reading and validating dependent types · 5.3.1 Reading a Vect from the console · 5.3.2 Reading a Vect of unknown length · 5.3.3 Dependent pairs · 5.3.4 Validating Vect lengths · 5.4 Summary

What you learn in chapter 5 →

Chapter 6: Chapter 6. Programming with first-class types

This introduction explains first-class types in Idris and illustrates calculating types from data.

6.1 Type-level functions: calculating types · 6.1.1 Type synonyms: giving informative names to complex types · 6.1.2 Type-level functions with pattern matching · 6.1.3 Using case expressions in types · 6.2 Defining functions with variable numbers of arguments · 6.2.1 An addition function · 6.2.2 Formatted output: a type-safe printf function · 6.3 Enhancing the interactive data store with schemas · 6.3.1 Refining the DataStore type · 6.3.2 Using a record for the DataStore · 6.3.3 Correcting compilation errors using holes · 6.3.4 Displaying entries in the store · 6.3.5 Parsing entries according to the schema · 6.3.6 Updating the schema · 6.3.7 Sequencing expressions with Maybe using do notation · 6.4 Summary

What you learn in chapter 6 →

Chapter 7: Chapter 7. Interfaces: using constrained generic types

This introduction explains how interface constraints make generic types more precise and how interfaces describe operations implemented for different types.

7.1 Generic comparisons with Eq and Ord · 7.1.1 Testing for equality with Eq · 7.1.2 Defining the Eq constraint using interfaces and implementations · 7.1.3 Default method definitions · 7.1.4 Constrained implementations · 7.1.5 Constrained interfaces: defining orderings with Ord · 7.2 Interfaces defined in the Prelude · 7.2.1 Converting to String with Show · 7.2.2 Defining numeric types · 7.2.3 Converting between types with Cast · 7.3 Interfaces parameterized by Type -> Type · 7.3.1 Applying a function across a structure with Functor · 7.3.2 Reducing a structure using Foldable · 7.3.3 Generic do notation using Monad and Applicative · 7.4 Summary

What you learn in chapter 7 →

Chapter 8: Chapter 8. Equality: expressing relationships between data

This introduction explains how types can express relationships between data and why a compiler may need help establishing them.

8.1 Guaranteeing equivalence of data with equality types · 8.1.1 Implementing exactLength, first attempt · 8.1.2 Expressing equality of Nats as a type · 8.1.3 Testing for equality of Nats · 8.1.4 Functions as proofs: manipulating equalities · 8.1.5 Implementing exactLength, second attempt · 8.1.6 Equality in general: the = type · 8.2 Equality in practice: types and reasoning · 8.2.1 Reversing a vector · 8.2.2 Type checking and evaluation · 8.2.3 The rewrite construct: rewriting a type using equality · 8.2.4 Delegating proofs and rewriting to holes · 8.2.5 Appending vectors, revisited · 8.3 The empty type and decidability · 8.3.1 Void: a type with no values · 8.3.2 Decidability: checking properties with precision · 8.3.3 DecEq: an interface for decidable equality · 8.4 Summary

What you learn in chapter 8 →

Chapter 9: Chapter 9. Predicates: expressing assumptions and contracts in types

This introduction explains predicates as types expressing properties and shows how assumptions in types serve as checked function contracts.

9.1 Membership tests: the Elem predicate · 9.1.1 Removing an element from a Vect · 9.1.2 The Elem type: guaranteeing a value is in a vector · 9.1.3 Removing an element from a Vect: types as contracts · 9.1.4 auto-implicit arguments: automatically constructing proofs · 9.1.5 Decidable predicates: deciding membership of a vector · 9.2 Expressing program state in types: a guessing game · 9.2.1 Representing the game’s state · 9.2.2 A top-level game function · 9.2.3 A predicate for validating user input: ValidInput · 9.2.4 Processing a guess · 9.2.5 Deciding input validity: checking ValidInput · 9.2.6 Completing the top-level game implementation · 9.3 Summary

What you learn in chapter 9 →

Chapter 10: Chapter 10. Views: extending pattern matching

This section introduces views as dependent types that offer alternative ways to pattern-match and observe data.

10.1 Defining and using views · 10.1.1 Matching the last item in a list · 10.1.2 Building views: covering functions · 10.1.3 with blocks: syntax for extended pattern matching · 10.1.4 Example: reversing a list using a view · 10.1.5 Example: merge sort · 10.2 Recursive views: termination and efficiency · 10.2.1 “Snoc” lists: traversing a list in reverse · 10.2.2 Recursive views and the with construct · 10.2.3 Traversing multiple arguments: nested with blocks · 10.2.4 More traversals: Data.List.Views · 10.3 Data abstraction: hiding the structure of data using views · 10.3.1 Digression: modules in Idris · 10.3.2 The data store, revisited · 10.3.3 Traversing the store’s contents with a view · 10.4 Summary

What you learn in chapter 10 →

Chapter 11: Chapter 11. Streams and processes: working with infinite data

This introduction contrasts batch processing with streams and explains how production, consumption, termination, and productivity relate in programs that run indefinitely.

11.1 Streams: generating and processing infinite lists · 11.1.1 Labeling elements in a List · 11.1.2 Producing an infinite list of numbers · 11.1.3 Digression: what does it mean for a function to be total? · 11.1.4 Processing infinite lists · 11.1.5 The Stream data type · 11.1.6 An arithmetic quiz using streams of random numbers · 11.2 Infinite processes: writing interactive total programs · 11.2.1 Describing infinite processes · 11.2.2 Executing infinite processes · 11.2.3 Executing infinite processes as total functions · 11.2.4 Generating infinite structures using Lazy types · 11.2.5 Extending do notation for InfIO · 11.2.6 A total arithmetic quiz · 11.3 Interactive programs with termination · 11.3.1 Refining InfIO: introducing termination · 11.3.2 Domain-specific commands · 11.3.3 Sequencing Commands with do notation · 11.4 Summary

What you learn in chapter 11 →

Chapter 12: Chapter 12. Writing programs with state

This introduction explains how Idris programs can work with state despite immutable variables, and distinguishes application-wide state from state local to an algorithm.

12.1 Working with mutable state · 12.1.1 The tree-traversal example · 12.1.2 Representing mutable state using a pair · 12.1.3 State, a type for describing stateful operations · 12.1.4 Tree traversal with State · 12.2 A custom implementation of State · 12.2.1 Defining State and runState · 12.2.2 Defining Functor, Applicative, and Monad implementations for State · 12.3 A complete program with state: working with records · 12.3.1 Interactive programs with state: the arithmetic quiz revisited · 12.3.2 Complex state: defining nested records · 12.3.3 Updating record field values · 12.3.4 Updating record fields by applying functions · 12.3.5 Implementing the quiz · 12.3.6 Running interactive and stateful programs: executing the quiz · 12.4 Summary

What you learn in chapter 12 →

Chapter 13: Chapter 13. State machines: verifying protocols in types

This introduction explains how separate operation descriptions and state-machine models can help express and enforce protocols in types.

13.1 State machines: tracking state in types · 13.1.1 Finite state machines: modeling a door as a type · 13.1.2 Interactive development of sequences of door operations · 13.1.3 Infinite states: modeling a vending machine · 13.1.4 A verified vending machine description · 13.2 Dependent types in state: implementing a stack · 13.2.1 Representing stack operations in a state machine · 13.2.2 Implementing the stack using Vect · 13.2.3 Using a stack interactively: a stack-based calculator · 13.3 Summary

What you learn in chapter 13 →

Chapter 14: Chapter 14. Dependent state machines: handling feedback and errors

This introduction reviews typed state-transition guarantees and explains why realistic state machines must account for failures and environmental responses.

14.1 Dealing with errors in state transitions · 14.1.1 Refining the door model: representing failure · 14.1.2 A verified, error-checking, door-protocol description · 14.2 Security properties in types: modeling an ATM · 14.2.1 Defining states for the ATM · 14.2.2 Defining a type for the ATM · 14.2.3 Simulating an ATM at the console: executing ATMCmd · 14.2.4 Refining preconditions using auto-implicits · 14.3 A verified guessing game: describing rules in types · 14.3.1 Defining an abstract game state and operations · 14.3.2 Defining a type for the game state · 14.3.3 Implementing the game · 14.3.4 Defining a concrete game state · 14.3.5 Running the game: executing GameLoop · 14.4 Summary

What you learn in chapter 14 →

Chapter 15: Chapter 15. Type-safe concurrent programming

This introduction explains processes, message-passing concurrency, and reasons to run processes concurrently.

15.1 Primitives for concurrent programming in Idris · 15.1.1 Defining concurrent processes · 15.1.2 The Channels library: primitive message passing · 15.1.3 Problems with channels: type errors and blocking · 15.2 Defining a type for safe message passing · 15.2.1 Describing message-passing processes in a type · 15.2.2 Making processes total using Inf · 15.2.3 Guaranteeing responses using a state machine and Inf · 15.2.4 Generic message-passing processes · 15.2.5 Defining a module for Process · 15.2.6 Example 1: List processing · 15.2.7 Example 2: A word-counting process · 15.3 Summary

What you learn in chapter 15 →

Concepts explained in this book

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.