Haskell Cookbook

Book description

Save time and build fast, functional, and concurrent application using Haskell

About This Book

  • Comprehensive guide for establishing a strong foundation in Haskell and developing pragmatic code
  • Create a full fledged web application using Haskell
  • Work with Lens, Haskell Extensions, and write code for concurrent and distributed applications

Who This Book Is For

This book is targeted at readers who wish to learn the Haskell language. If you are a beginner, Haskell Cookbook will get you started. If you are experienced, it will expand your knowledge base. A basic knowledge of programming will be helpful.

What You Will Learn

  • Use functional data structures and algorithms to solve problems
  • Understand the intricacies of the type system
  • Create a simple parser for integer expressions with additions
  • Build high-performance web services with Haskell
  • Master mechanisms for concurrency and parallelism in Haskell
  • Perform parsing and handle scarce resources such as filesystem handles
  • Organize your programs by creating your own types and type classes

In Detail

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.

Style and approach

The book follows a recipe-based approach. Each recipe addresses specific problems and issues. The recipes provide discussions and insights to explain these problems.

Table of contents

  1. Preface
    1. What this book covers
    2. What you need for this book
    3. Who this book is for
    4. Sections
      1. Getting ready
      2. How to do it…
      3. How it works…
      4. There's more…
      5. See also
    5. Conventions
    6. Reader feedback
    7. Customer support
      1. Downloading the example code
      2. Errata
      3. Piracy
      4. Questions
  2. Foundations of Haskell
    1. Introduction
    2. Getting started with Haskell
      1. How to do it...
      2. How it works…
        1. Dissecting Hello World
      3. There's more…
    3. Working with data types
      1. How to do it…
      2. How it works...
      3. There's more…
    4. Working with pure functions and user-defined data types
      1. Getting ready
      2. How to do it...
      3. How it works...
        1. Source formatting
    5. Working with list functions
      1. Getting ready
      2. How to do it...
      3. How it works...
        1. List creation
        2. Enumerated list
        3. Head and tail of a list
        4. Operations on a list
        5. Indexed access
        6. Checking whether an element is present
        7. Pattern matching on list
        8. List concatenation
        9. Strings are lists
      4. There's more…
  3. Getting Functional
    1. Introduction
    2. Working with recursive functions
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    3. Reversing a list - Recursive worker function pattern
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    4. Creating maps and filters
      1. Getting ready
      2. How to do it...
      3. How it works...
        1. Map function
        2. Filter function
      4. There's more...
    5. Working with laziness and recursion
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Working with folds
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    7. Sorting a list
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
    8. Implementing merge sort
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Implementing Eratosthenes Sieve
      1. Getting ready
      2. How to do it...
      3. How it works...
      4. There's more...
  4. Defining Data
    1. Introduction
    2. Defining a product type
      1. Getting ready
      2. How to do it...
      3. How it works...
    3. Defining a sum type
      1. Getting ready
      2. How to do it...
      3. How it works...
    4. Defining a binary tree and traversing it
      1. Getting ready
      2. How to do it...
      3. How it works...
    5. Defining data with functions
      1. Getting ready
      2. How to do it...
      3. How it works...
    6. Using Maybe
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Using Either
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Working with type classes
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Working with Monoid
      1. Getting ready
      2. How to do it...
      3. How it works...
  5. Working with Functors, Applicatives, and Monads
    1. Introduction
    2. Working with Functors
      1. How to do it...
      2. How it works...
    3. Binary tree as Functor
      1. How to do it...
      2. How it works...
    4. Working with Applicatives
      1. How to do it...
      2. How it works...
    5. Binary tree as Applicative
      1. How to do it...
      2. How it works...
    6. Working with monad
      1. How to do it...
      2. How it works...
      3. There's more...
    7. List as monad
      1. How to do it...
      2. How it works...
    8. Working with IO monad
      1. How to do it...
      2. How it works...
    9. Writing INI parser
      1. How to do it...
      2. How it works...
    10. Errors and exception handling
      1. How to do it...
      2. How it works...
  6. More about Monads
    1. Introduction
    2. Writing a State Monad
      1. How to do it...
      2. How it works...
    3. Computing a fibonacci number with State Monad
      1. How to do it...
      2. How it works...
    4. Writing a State Monad transformer
      1. How to do it...
      2. How it works...
    5. Working with the Reader monad transformer
      1. How to do it...
      2. How it works...
    6. Working with the Writer monad transformer
      1. Getting ready
      2. How to do it...
      3. How it works...
    7. Combining monad transformers
      1. How to do it...
      2. How it works...
  7. Working with Common Containers and Strings
    1. Introduction
    2. Working with sets
      1. How to do it...
      2. How it works...
    3. Shopping cart as a set
      1. How to do it...
      2. How it works...
    4. Working with maps
      1. How to do it...
      2. How it works...
    5. Log analysis with map
      1. How to do it...
      2. How it works...
    6. Working with vector
      1. How to do it...
      2. How it works...
    7. Working with text and bytestring
      1. How to do it...
      2. How it works...
    8. Creating and testing a priority queue
      1. Getting ready
      2. How to do it...
      3. How it works...
    9. Working with Foldable and Traversable
      1. How to do it...
      2. How it works...
  8. Working with Relational and NoSQL Databases
    1. Introduction
    2. Working with Persistent
      1. How to do it...
      2. How it works...
    3. Managing migrations
      1. How to do it...
      2. How it works...
    4. Creating custom data types
      1. How to do it...
      2. How it works...
    5. Using Esqueleto to do advanced SQL queries
      1. How to do it...
      2. How it works...
    6. Using hedis to work with redis (key-value, list and hash)
      1. Getting ready...
      2. How to do it...
      3. How it works...
    7. Using hashsets and sorted sets in redis to create a Trie
      1. Getting ready
      2. How to do it...
      3. How it works...
  9. Working with HTML and Templates
    1. Introduction
    2. Using blaze to create an HTML template
      1. How to do it...
      2. How it works...
    3. Using blaze to reverse engineer an HTML page
      1. How to do it...
      2. How it works...
    4. Use blaze-html with Bootstrap to create HTML template
      1. How to do it... 
      2. How it works...
    5. Using heist as a template engine
      1. How to do it...
      2. How it works...
    6. Working with splice in Heist
      1. How to do it...
      2. How it works...
  10. Working with Snap Framework
    1. Introduction
    2. Getting started with Snap
      1. How to do it...
      2. How it works...
    3. Routing in Snap
      1. How to do it...
      2. How it works...
    4. Serving static contents in Snap
      1. How to do it...
      2. How it works...
    5. Form handling in Snap
      1. How to do it...
      2. How it works...
    6. Creating and composing snaplets
      1. How to do it...
      2. How it works...
    7. Session handling in Snap
      1. How to do it...
      2. How it works...
    8. Authentication in Snap
      1. How to do it...
      2. How it works...
    9. File upload with Snap
      1. How to do it...
      2. How it works...
  11. Working with Advanced Haskell
    1. Introduction
    2. Working with existentially quantified type
      1. How to do it...
      2. How it works...
    3. Working with Rank-N type
      1. How to do it...
      2. How it works...
    4. Working with type family
      1. How to do it...
      2. How it works...
    5. Working with GADTs
      1. How to do it...
      2. How it works...
  12. Working with Lens and Prism
    1. Introduction
    2. Creating lenses
      1. How to do it...
      2. How it works...
    3. Working with lenses
      1. How to do it...
      2. How it works...
    4. Working with Traversal
      1. How to do it...
      2. How it works...
    5. Working with Iso
      1. How to do it...
      2. How it works...
    6. Working with Prism
      1. How to do it...
      2. How it works...
    7. Working with predefined lenses
      1. Getting ready
      2. How to do it...
      3. How it works...
  13. Concurrent and Distributed Programming in Haskell
    1. Introduction
    2. Working with IORef
      1. How to do it...
      2. How it works...
    3. Working with MVar
      1. How to do it...
      2. How it works...
    4. Working with STM
      1. How it works...
      2. How it works...
    5. Working with strategies
      1. How to do it...
      2. How it works...
    6. Working with monad-par
      1. How to do it...
      2. How it works...
    7. Working with Cloud Haskell
      1. Getting ready
      2. How to do it...
      3. How it works...
    8. Using Cloud Haskell to start master and slave nodes
      1. How to do it...
      2. How it works...
    9. Using closure to communicate between nodes
      1. How to do it...
      2. How it works...

Product information

  • Title: Haskell Cookbook
  • Author(s): Yogesh Sajanikar
  • Release date: September 2017
  • Publisher(s): Packt Publishing
  • ISBN: 9781786461353