Book Image

Learn Type-Driven Development

By : Yawar Amin, Kamon Ayeva
Book Image

Learn Type-Driven Development

By: Yawar Amin, Kamon Ayeva

Overview of this book

Type-driven development is an approach that uses a static type system to achieve results including safety and efficiency. Types are used to express relationships and other assumptions directly in the code, and these assumptions are enforced by the compiler before the code is run. Learn Type-Driven Development covers how to use these type systems to check the logical consistency of your code. This book begins with the basic idea behind type-driven development. You’ll learn about values (or terms) and how they contrast with types. As you progress through the chapters, you’ll cover how to combine types and values inside modules and build structured types out of simpler ones. You’ll then understand how to express choices or alternatives directly in the type system using variants, polymorphic variants, and generalized algebraic data types. You’ll also get to grips with sum types, build sophisticated data types from generics, and explore functions that express change in the types of values. In the concluding chapters, you’ll cover advanced techniques for code reuse, such as parametric polymorphism and subtyping. By end of this book, you will have learned how to iterate through a type-driven process of solving coding problems using static types, together with dynamic behavior, to obtain more safety and speed.
Table of Contents (12 chapters)

What this book covers

Chapter 1, Starting Type-Driven Development, introduces type-driven development and its primary benefits. It gets you started with the ReasonML language and its tooling, it sets up a tutorial project that we will use throughout this book, and it shows where to go for further help and resources.

Chapter 2, Programming with Types and Values, sets up an edit-compile workflow for fast development, and introduces a number of foundational concepts, such as types and values. It also covers how a static typing compiler works and how it is different from dynamic typing.

Chapter 3, Packaging Types and Values Together, shows how to write modular code and take advantage of Reason's first-class module support to achieve abstraction, information hiding, and API documentation.

Chapter 4, Grouping Values Together in Types, covers types that may contain multiple values of different types at once, the various ways to construct these product types, and how best to use them.

Chapter 5, Putting Alternative Values in Types, covers types that may contain only one value at a time of possibly many different types. We cover how these sum types are different from product types, and how and when to use them.

Chapter 6, Making Types that Can Slot into Any Other Type, covers generics, type parameters, how to make sum and product types generic, and the restrictions of working with generics.

Chapter 7, Making Types that Represent Operations, covers functions and what their desirable properties are in type-driven development, how to create functions and how they work, and how to use them with achieve techniques such as dependency injection and inversion of control.

Chapter 8, Reusing Code with Many Different Types, covers parametric polymorphism, a powerful technique in type-driven development for writing code that can be extended and reused without the old and new code having to know about each other's implementation details.

Chapter 9, Extending Types with New Behavior, covers techniques that can be used to improve code reuse and extend parts of an implementation.

Chapter 10, Bringing It All Together, explains how to tie together many different techniques to explore an implementation when trying to solve a problem in a type-driven way.