Book Image

Haskell Cookbook

Book Image

Haskell Cookbook

Overview of this book

Haskell is a purely functional language that has the great ability to develop large and difficult, but easily maintainable software. Haskell Cookbook provides recipes that start by illustrating the principles of functional programming in Haskell, and then gradually build up your expertise in creating industrial-strength programs to accomplish any goal. The book covers topics such as Functors, Applicatives, Monads, and Transformers. You will learn various ways to handle state in your application and explore advanced topics such as Generalized Algebraic Data Types, higher kind types, existential types, and type families. The book will discuss the association of lenses with type classes such as Functor, Foldable, and Traversable to help you manage deep data structures. With the help of the wide selection of examples in this book, you will be able to upgrade your Haskell programming skills and develop scalable software idiomatically.
Table of Contents (13 chapters)

Introduction

We have worked on functions, higher order functions, and also worked with data types in Haskell. We have looked at functions such as map and filter in the context of the data type list. In many of these examples, we have taken a function that operates on data of type a and applied them in the context of the list of type a. Look at the following definition of map:

    map :: (a -> b ) -> [a] -> [b]

You can clearly see that we have taken a function that operates on data type a and produces b, and we converted it to a function that takes a list of a and produces a list of b (map :: (a -> b) -> ([a] -> [b])). Instead of the list of a, we can think of some parametric data type T a. Now, we can rewrite the declaration of map as follows:

    map :: (a -> b) -> T a -> T b

In short, the preceding definition of map applies to any data type T a, given...