liveBook · Manning

Chapter 10: Chapter 10. Views: extending pattern matching

What you will learn in chapter 10 of Type-Driven Development with Idris

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

After this chapter you will be able to

What it builds on

Section by section

Introduction

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

Key terms: case split, data constructors, pattern matching, List, views, dependent types, abstract interface

10.1 Defining and using views

This section motivates views by contrasting ordinary list patterns with the desired ability to match a list’s final element.

Key terms: (x :: xs), tail, initial segment, last element, ++, pattern-match, views, informative data types

10.1.1 Matching the last item in a list

This section uses the ListLast view and dependent pattern matching to describe a list by its final element.

Key terms: ListLast, view, initial portion, final element, dependent pattern matching, case-split, describeHelper, Empty, NonEmpty

10.1.2 Building views: covering functions

This section introduces covering functions through a view that exposes the last element of a list.

Key terms: covering function, ListLast, view, view type

10.1.3 with blocks: syntax for extended pattern matching

This section shows how with blocks support concise dependent pattern matching on intermediate results and explains which patterns Idris permits.

Key terms: with construct, with block, with_pat, listLast, dependent pattern matching, Empty, NonEmpty, case block, data constructor, valid pattern

10.1.4 Example: reversing a list using a view

This section implements list reversal using the ListLast view and explains its efficiency and totality-checking limitations.

Key terms: ListLast, with block, Empty, NonEmpty, myReverse, recursive call, linear time, totality, decreasing argument, data constructor

10.1.5 Example: merge sort

This section develops merge sort using a list-splitting view and examines its guarantees and termination limitations.

Key terms: mergeSort, SplitList, SplitNil, SplitOne, SplitPair, merge, pattern, concatenation, covering function, total

10.2 Recursive views: termination and efficiency

This section recaps how views extend pattern matching and identifies totality and efficiency problems in earlier examples.

Key terms: view, covering function, with construct, dependent pattern matching, total, recursive call

10.2.1 “Snoc” lists: traversing a list in reverse

This section uses a recursive SnocList view to reverse a list and explains its termination and linear-time construction.

Key terms: SnocList, recursive view, Snoc, List, myReverseHelper, myReverse, Empty, total, covering function, accumulator

10.2.2 Recursive views and the with construct

This section rewrites list reversal using a recursive SnocList view and the with construct, preserving totality and linear-time traversal.

Key terms: with construct, SnocList, Empty, Snoc, case splitting, recursive view, with block, total, linear time, myReverseHelper

10.2.3 Traversing multiple arguments: nested with blocks

This section uses a suffix test to show how nested with blocks traverse multiple lists using recursive views.

Key terms: with blocks, snocList, Empty, Snoc, isSuffix, suffix, recursive view arguments, xsrec, ysrec

10.2.4 More traversals: Data.List.Views

This section introduces library views for traversing lists and uses SplitRec to implement a total merge sort.

Key terms: SplitRec, SplitRecNil, SplitRecOne, SplitRecPair, with block, mergeSort, Lazy, Delay, Force, VList

10.3 Data abstraction: hiding the structure of data using views

This section explains how views provide alternative ways to inspect data and support programming against hidden representations.

Key terms: views, SnocList, SplitRec, pattern matching, data abstraction, module, case splitting, type-driven development

10.3.1 Digression: modules in Idris

This section explains Idris module export modifiers and how they control visibility and data abstraction.

Key terms: private, export, public export, data constructors, type constructor, type synonyms, type-level functions, abstract data type, export modifiers, pattern-match

10.3.2 The data store, revisited

This section revisits the data store as an abstract module with a fixed schema and motivates a view for traversing its contents.

Key terms: DataStore, schema, parameterized record, export, size, items, empty, addToStore, view

10.3.3 Traversing the store’s contents with a view

This section uses a view to traverse and filter an abstract data store without exposing its internal representation.

Key terms: StoreView, covering function, empty, addToStore, internal representation, filterKeys, SchemaType, SString, val_schema, SNil

10.4 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 9: Chapter 9. Predicates: expressing assumptions and contracts in types Chapter 11: Chapter 11. Streams and processes: working with infinite data →

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.