Book Image

Haskell Design Patterns

By : Tikhon Jelvis, Ryan Lemmer
Book Image

Haskell Design Patterns

By: Tikhon Jelvis, Ryan Lemmer

Overview of this book

Design patterns and idioms can widen our perspective by showing us where to look, what to look at, and ultimately how to see what we are looking at. At their best, patterns are a shorthand method of communicating better ways to code (writing less, more maintainable, and more efficient code) This book starts with Haskell 98 and through the lens of patterns and idioms investigates the key advances and programming styles that together make "modern Haskell". Your journey begins with the three pillars of Haskell. Then you'll experience the problem with Lazy I/O, together with a solution. You'll also trace the hierarchy formed by Functor, Applicative, Arrow, and Monad. Next you'll explore how Fold and Map are generalized by Foldable and Traversable, which in turn is unified in a broader context by functional Lenses. You'll delve more deeply into the Type system, which will prepare you for an overview of Generic programming. In conclusion you go to the edge of Haskell by investigating the Kind system and how this relates to Dependently-typed programming
Table of Contents (14 chapters)

Summary


This chapter started with a high-level discussion of the patterns of generic programming.

In the remainder of the chapter, we explored three variations of datatype-generic programming, that is, three techniques of parameterizing generic functions by data shape rather than by contents.

Underlying these varied approaches were some common threads:

  • To achieve generic functions, we need "generic data" (in the form of a universal type representation)

  • Datatype-generic programming mixes well with more rudimentary meta-programming (for example, when we autoderived Typeable instances in the process of writing generic functions)

  • using "shallow recursion" on a lower layer allows us to express all manner of recursive functions on the higher level

Generic Programming relies on extensions to the Haskell Type system. In the following Chapter 7, Patterns of Kind Abstraction we will see that we can raise the level of abstraction even further via extensions to the Kind system!