Haskell in Depth
Vitaly Bragilevsky
  • MEAP began June 2018
  • Publication in Spring 2021 (estimated)
  • ISBN 9781617295409
  • 360 pages (estimated)
  • printed in black & white

Finally, a truly great book for Haskell programming in the real-world.

William E. Wheeler
Turn the corner from “Haskell student” to “Haskell developer.” Haskell in Depth explores the important language features and programming skills you’ll need to build production-quality software using Haskell. And along the way, you’ll pick up some interesting insights into why Haskell looks and works the way it does. Get ready to go deep!

About the Technology

As software becomes more complex, it’s essential to program efficiently using tools and techniques that guarantee your applications will run correctly, grow easily, and last a long time. Haskell is a functional programming language that blends a mathematically-rigorous approach to software design with a tested ecosystem of tools and libraries you can use to build deployable applications.

About the book

Haskell in Depth is the perfect second book on Haskell. After a quick refresher on Haskell basics, this hands-on guide dives into examples and application scenarios designed to teach how Haskell works and how to apply it correctly. You’ll learn about managing projects with Cabal and Stack, tackle error-handling and testing, and package programs and libraries for production deployment.

You’ll appreciate coverage of advanced Haskell features including programming polymorphically, working effectively with types, concurrent programming, data processing, web services, and more. Because it’s organized to make specific topics easy to find, you’ll return to this book again and again as your go-to Haskell reference.

Table of Contents detailed table of contents

0 Haskell in Depth: How to work with the source code examples

0.1 Getting the sources

0.2 Using Stack

0.2.1 Building

0.2.2 Running

0.2.3 Exploring in GHCi

0.3 Using Cabal sandbox

0.3.1 Building

0.3.2 Running

0.3.3 Exploring in GHCi

0.4 Using Cabal new-*

0.4.1 Building

1 Functions and types

1.1 Solving problems in GHCi REPL with functions

1.2 From GHCi and String to GHC and Text

1.3 Functional program as a set of IO actions

1.4 Embracing pure functions

1.4.1 Putting I/O apart with pure functions

1.4.2 Computing the most frequent words by sorting them

1.4.3 Formatting reports

1.4.4 Rule them all with IO actions

1.5 Summary

Part 1: Core Haskell

2 Type classes

2.1 Manipulating a radar antenna with type classes

2.1.1 The problem at hand

2.1.2 Rotating a radar antenna with Eq, Enum, and Bounded

2.1.3 Combining turns with Semigroup and Monoid

2.1.4 Printing and reading data with Show, Read, and beyond

2.1.5 Testing functions with Ord and Random

2.2 Issues with numbers and texts

2.2.1 Numeric types and type classes

2.2.2 Numeric conversions

2.2.3 Computing with fixed precision

2.2.4 More about Show and Read

2.2.5 Converting recursive types to strings

2.3 Abstracting computations with type classes

2.3.1 An idea of a computational context and a common behavior

2.3.2 Exploring different contexts in parallel

2.3.3 The do notation

2.3.4 Folding and traversing

2.4 Summary

3 Developing an application: stock quotes

3.1 Setting the scene

3.1.1 Inputs

3.1.2 Outputs

3.1.3 Project structure

3.2 Exploring design space

3.2.1 Designing user interface

3.2.2 Dealing with input data

3.2.3 Reporting results

3.2.4 Project dependencies overview

3.3 Implementation details

3.3.1 Describing data

3.3.2 Plotting charts

3.3.3 Preparing reports

3.3.4 Implementing user interface

3.3.5 Connecting parts

3.4 Summary

Part 2: Developing Projects in Haskell

4 Haskell development with modules, packages, and projects

4.1 Organizing Haskell code with modules

4.1.1 Module structure, imports and exports, module hierarchy

4.1.2 Custom Preludes

4.1.3 Example: containers-mini

4.2 Understanding Haskell packages

4.2.1 Packages at the GHC level

4.2.2 Cabal packages and Hackage

4.3 Tools for project development

4.3.1 Dependency management

4.3.2 Haskell project as a collection of packages

4.3.3 Common project management activities and tools

4.4 Summary

5 Monads as practical functionality providers

5.1 Basic monads in use: Maybe, Reader, Writer

5.1.1 Maybe monad as a line saver

5.1.2 Carrying configuration all over the program with Reader

5.1.3 Writing logs via Writer

5.2 Maintaining state via the State monad

5.2.1 Basic examples with the State monad

5.2.2 Parsing arithmetic expressions with State

5.2.3 RWS monad to rule them all: the game of dices

5.3 Other approaches to mutability

5.3.1 Mutable references in the IO monad

5.3.2 Mutable references in the ST monad

5.4 Summary

6 Structuring programs with monad transformers

6.1 The problem of combining monads

6.1.1 Evaluating expressions in the reversed polish notation

6.1.2 Introducing monad transformers and monad stacks

6.2 IO-based monad transformer stacks

6.2.1 Describing monad stack

6.2.2 Exploiting a monad stack functionality

6.2.3 Running an application

6.2.4 Can we do it without RWST?

6.3 What is a monad transformer

6.3.1 Step 0: defining a type for a transformer

6.3.2 Step 1: turning a monad stack into a monad

6.3.3 Step 2: implementing the full monad stack functionality

6.3.4 Step 3: supplying additional functionality

6.3.5 Using a transformer

6.4 Monad transformers in the Haskell libraries

6.4.1 Identity is where it all starts

6.4.2 An overview of the most common monad transformers

6.5 Summary

7 Error handling and logging

7.1 Overview of error handling mechanisms in Haskell

7.1.1 An idea of exceptions

7.1.2 To use or not to use

7.1.3 Programmable exceptions vs GHC runtime exceptions

7.2 Programmable exceptions in monad stacks

7.2.1 The ExceptT monad transformer

7.2.2 Example: evaluating RPN expressions

7.3 GHC runtime exceptions

7.3.1 An idea of extensible exceptions

7.3.2 Throwing exceptions

7.3.3 Catching exceptions

7.4 Example: Accessing web APIs and GHC exceptions

7.4.1 Application components

7.4.2 Exceptions handling strategies

7.5 Logging

7.5.1 An overview of the monad-logger library

7.5.2 Introducing logging with monad-logger into the suntimes project

7.6 Summary

8 Writing tests

8.1 Setting a scene: IPv4 filtering application

8.1.1 Development process overview

8.1.2 Initial implementation

8.2 Testing the IPv4 filtering application

8.2.1 Overview of approaches to testing

8.2.2 Testing Cabal-projects with tasty

8.2.3 Specifications writing and checking with Hspec

8.2.4 Property-based testing with Hedgehog

8.2.5 Golden tests with tasty-golden

8.3 Other approaches to testing

8.3.1 Testing functions a-la REPL with doctest

8.3.2 Lightweight verification with Liquid Haskell

8.3.3 Code quality with hlint

8.4 Summary

9 Haskell data and code at runtime

9.1 Mental model for Haskell memory usage at runtime

9.1.1 General memory structure and closures

9.1.2 Primitive unboxed data types

9.1.3 Representing data and code in memory with closures

9.1.4 A detour: Lifted types and the concept of strictness

9.2 Control over evaluation and memory usage

9.2.1 Controlling strictness and laziness

9.2.2 Defining data types with unboxed values

9.3 Exploring compiler optimizations by example

9.3.1 Optimizing code manually

9.3.2 Looking at GHC Core

9.4 Summary

10 Benchmarking and profiling

10.1 Benchmarking functions with criterion

10.1.1 Benchmarking implementations of a simple function

10.1.2 Benchmarking IPv4 filtering application

10.2 Profiling execution time and memory usage

10.2.1 Simulating iplookup usage in the real world

10.2.2 Analyzing execution time and memory allocation

10.2.3 Analyzing memory usage

10.3 Tuning performance of the IPv4 filtering application

10.3.1 Choosing the right data structure

10.3.2 Squeezing parseIP performance

10.4 Summary

Part 3: Advanced Haskell

11 Type system advances

11.1 Haskell types 101

11.1.1 Terms, types, and kinds

11.1.2 Delivering information with types

11.1.3 Type operators

11.2 Data kinds and type-level literals

11.2.1 Promoting types to kinds

11.2.2 Type-level literals

11.3 Computations over types with type families

11.3.1 Open and closed type synonym families

11.3.2 Example: avoid Char-escaping in GHCi

11.3.3 Data families

11.3.4 Associated families

11.4 Generalised algebraic datatypes

11.4.1 Example: Representing dynamically-typed values with GADTs

11.4.2 Example: Representing arithmetic expressions with GADTs

11.5 Arbitrary-rank polymorphism

11.5.1 The meaning

11.5.2 Use cases

11.6 Advice on dealing with type errors

11.6.1 Be explicit about types

11.6.2 Ask the compiler

11.6.3 Be helpful to others

11.7 Summary

12 Metaprogramming in Haskell

12.1 Deriving instances

12.1.1 Basic deriving strategies

12.1.2 The problem of type safety and generalized newtype deriving

12.1.3 Deriving by an example with DerivingVia

12.2 Datatype generic programming

12.2.1 Generic datatype representation

12.2.2 Example: Generating SQL queries

12.3 Template Haskell and QuasiQuotes

12.3.1 A tutorial on Template Haskell

12.3.2 Example: Generating remote functions calls

12.4 Summary

Part 4: Haskell Toolkit

13 More about types

13.1 Types as a workforce

13.1.1 Implementing Web API from scratch

13.1.2 Implementing a web-service with servant

13.2 Towards dependent types with singletons

13.2.1 Safety in Haskell programs

13.2.2 Example: unsafe interface for elevators

13.2.3 Dependent types and substituting them with singletons

13.2.4 Example: safe interface for elevators

13.3 Summary

14 Data processing pipelines

14.1 Streaming data

14.1.1 General components and naive implementation

14.1.2 The streaming package

14.2 Implementing pipeline stages

14.2.1 Reading and writing data efficiently

14.2.2 Parsing data with parser combinators

14.2.3 Accessing data with lenses

14.3 Example: Processing COVID-19 data

14.3.1 The task

14.3.2 Processing data

14.3.3 Organizing the pipeline

14.4 Summary

15 Working with relational databases

16 Implementing web services

What's inside

  • Organizing your projects with Cabal and Stack
  • Testing and profiling
  • Working with data
  • Building web services and networking apps
  • Using the sophisticated libraries like lens, vinyl, and servant

About the reader

Written for developers familiar with Haskell basics.

About the author

Since 2008, Vitaly Bragilevsky has been teaching Haskell and functional programming to undergraduate students at the Southern Federal University located in Rostov-on-Don, Russia. He is a member of the Haskell 2020 Committee, and has worked on the source code of the Glasgow Haskell Compiler (GHC) and the Idris compiler, both of which are implemented in Haskell.

placing your order...

Don't refresh or navigate away from the page.
Manning Early Access Program (MEAP) Read chapters as they are written, get the finished eBook as soon as it’s ready, and receive the pBook long before it's in bookstores.
print book $35.99 $59.99 pBook + eBook + liveBook
Additional shipping charges may apply
Haskell in Depth (print book) added to cart
continue shopping
go to cart

eBook $38.39 $47.99 3 formats + liveBook
Haskell in Depth (eBook) added to cart
continue shopping
go to cart

Prices displayed in rupees will be charged in USD when you check out.
customers also reading

This book 1-hop 2-hops 3-hops

FREE domestic shipping on three or more pBooks