Haskell in Depth
Haskell in Depth unlocks a new level of skill with this challenging language. Going beyond the basics of syntax and structure, this book opens up critical topics like advanced types, concurrency, and data processing.

Summary

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!

Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications.

About the technology

Software for high-precision tasks like financial transactions, defense systems, and scientific research must be absolutely, provably correct. As a purely functional programming language, Haskell enforces a mathematically rigorous approach that can lead to concise, efficient, and bug-free code. To write such code you’ll need deep understanding. You can get it from this book!

About the book

Haskell in Depth unlocks a new level of skill with this challenging language. Going beyond the basics of syntax and structure, this book opens up critical topics like advanced types, concurrency, and data processing. You’ll discover key parts of the Haskell ecosystem and master core design patterns that will transform how you write software.

What's inside

    Building applications, web services, and networking apps
    Using sophisticated libraries like lens, singletons, and servant
    Organizing projects with Cabal and Stack
    Error-handling and testing
    Pure parallelism for multicore processors

About the reader

For developers familiar with Haskell basics.

About the author

Vitaly Bragilevsky has been teaching Haskell and functional programming since 2008. He is a member of the GHC Steering Committee.

Table of Contents

PART 1 CORE HASKELL
1 Functions and types
2 Type classes
3 Developing an application: Stock quotes
PART 2 INTRODUCTION TO APPLICATION DESIGN
4 Haskell development with modules, packages, and projects
5 Monads as practical functionality providers
6 Structuring programs with monad transformers
PART 3 QUALITY ASSURANCE
7 Error handling and logging
8 Writing tests
9 Haskell data and code at run time
10 Benchmarking and profiling
PART 4 ADVANCED HASKELL
11 Type system advances
12 Metaprogramming in Haskell
13 More about types
PART 5 HASKELL TOOLKIT
14 Data-processing pipelines
15 Working with relational databases
16 Concurrency
1135637248
Haskell in Depth
Haskell in Depth unlocks a new level of skill with this challenging language. Going beyond the basics of syntax and structure, this book opens up critical topics like advanced types, concurrency, and data processing.

Summary

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!

Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications.

About the technology

Software for high-precision tasks like financial transactions, defense systems, and scientific research must be absolutely, provably correct. As a purely functional programming language, Haskell enforces a mathematically rigorous approach that can lead to concise, efficient, and bug-free code. To write such code you’ll need deep understanding. You can get it from this book!

About the book

Haskell in Depth unlocks a new level of skill with this challenging language. Going beyond the basics of syntax and structure, this book opens up critical topics like advanced types, concurrency, and data processing. You’ll discover key parts of the Haskell ecosystem and master core design patterns that will transform how you write software.

What's inside

    Building applications, web services, and networking apps
    Using sophisticated libraries like lens, singletons, and servant
    Organizing projects with Cabal and Stack
    Error-handling and testing
    Pure parallelism for multicore processors

About the reader

For developers familiar with Haskell basics.

About the author

Vitaly Bragilevsky has been teaching Haskell and functional programming since 2008. He is a member of the GHC Steering Committee.

Table of Contents

PART 1 CORE HASKELL
1 Functions and types
2 Type classes
3 Developing an application: Stock quotes
PART 2 INTRODUCTION TO APPLICATION DESIGN
4 Haskell development with modules, packages, and projects
5 Monads as practical functionality providers
6 Structuring programs with monad transformers
PART 3 QUALITY ASSURANCE
7 Error handling and logging
8 Writing tests
9 Haskell data and code at run time
10 Benchmarking and profiling
PART 4 ADVANCED HASKELL
11 Type system advances
12 Metaprogramming in Haskell
13 More about types
PART 5 HASKELL TOOLKIT
14 Data-processing pipelines
15 Working with relational databases
16 Concurrency
43.99 In Stock
Haskell in Depth

Haskell in Depth

by Vitaly Bragilevsky
Haskell in Depth

Haskell in Depth

by Vitaly Bragilevsky

eBook

$43.99 

Available on Compatible NOOK devices, the free NOOK App and in My Digital Library.
WANT A NOOK?  Explore Now

Related collections and offers


Overview

Haskell in Depth unlocks a new level of skill with this challenging language. Going beyond the basics of syntax and structure, this book opens up critical topics like advanced types, concurrency, and data processing.

Summary

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!

Purchase of the print book includes a free eBook in PDF, Kindle, and ePub formats from Manning Publications.

About the technology

Software for high-precision tasks like financial transactions, defense systems, and scientific research must be absolutely, provably correct. As a purely functional programming language, Haskell enforces a mathematically rigorous approach that can lead to concise, efficient, and bug-free code. To write such code you’ll need deep understanding. You can get it from this book!

About the book

Haskell in Depth unlocks a new level of skill with this challenging language. Going beyond the basics of syntax and structure, this book opens up critical topics like advanced types, concurrency, and data processing. You’ll discover key parts of the Haskell ecosystem and master core design patterns that will transform how you write software.

What's inside

    Building applications, web services, and networking apps
    Using sophisticated libraries like lens, singletons, and servant
    Organizing projects with Cabal and Stack
    Error-handling and testing
    Pure parallelism for multicore processors

About the reader

For developers familiar with Haskell basics.

About the author

Vitaly Bragilevsky has been teaching Haskell and functional programming since 2008. He is a member of the GHC Steering Committee.

Table of Contents

PART 1 CORE HASKELL
1 Functions and types
2 Type classes
3 Developing an application: Stock quotes
PART 2 INTRODUCTION TO APPLICATION DESIGN
4 Haskell development with modules, packages, and projects
5 Monads as practical functionality providers
6 Structuring programs with monad transformers
PART 3 QUALITY ASSURANCE
7 Error handling and logging
8 Writing tests
9 Haskell data and code at run time
10 Benchmarking and profiling
PART 4 ADVANCED HASKELL
11 Type system advances
12 Metaprogramming in Haskell
13 More about types
PART 5 HASKELL TOOLKIT
14 Data-processing pipelines
15 Working with relational databases
16 Concurrency

Product Details

ISBN-13: 9781638356929
Publisher: Manning
Publication date: 07/13/2021
Sold by: SIMON & SCHUSTER
Format: eBook
Pages: 664
File size: 4 MB

About the Author

Vitaly Bragilevsky has been teaching Haskell and functional programming since 2008. He is a member of the GHC Steering Committee.

Table of Contents

Foreword xv

Preface xvii

Acknowledgments xxiv

About this book xxvi

About the author xxxii

About the cover illustration xxxiii

Part 1 Core Haskell 1

1 Functions and types 3

1.1 Solving problems in the GHCi REPL with functions 4

1.2 From GHCi and String to GHC and Text 6

1.3 Functional programs as sets of IO actions 7

1.4 Embracing pure functions 10

Separating I/O from pure functions 10

Computing the most frequent words by sorting them 13

Formatting reports 14

Rule them all with IO actions 17

2 Type classes 18

2.1 Manipulating a radar antenna with type classes 19

The problem at hand 19

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

Combining turns with Semigroup and Monoid 26

Printing and reading data with Show and Read 30

Testing Junctions with Ord and Random 33

2.2 Issues with numbers and text 38

Numeric types and type classes 38

Numeric conversions 40

Computing with fixed precision 41

More about Show and Read 43

Converting recursive types to strings 47

2.3 Abstracting computations with type classes 51

An idea of a computational context and a common behavior 51

Exploring different contexts in parallel 53

The do notation 54

Folding and traversing 56

3 Developing an application: Stock quotes 60

3.1 Setting the scene 61

Inputs 62

Outputs 62

Project structure 64

3.2 Exploring design space 68

Designing the user interface 69

Dealing with input data 70

Formatting reports 72

Plotting charts 73

Project dependencies overview 74

3.3 Implementation details 75

Describing data 76

Plotting charts 80

Preparing reports 85

Implementing the user interface 92

Connecting parts 94

Part 2 Introduction to Application Design 97

4 Haskell development with modules, packages, and projects 99

4.1 Organizing Haskell code with modules 100

Module structure, imports and exports, and module hierarchy 100

Custom Preludes 105

Example: containers-mini 107

4.2 Understanding Haskell packages 111

Packages at the GHC level 111

Cabal packages and Hackage 114

4.3 Tools for project development 121

Dependency management 122

Haskell projects as a collection of packages 127

Common project management activities and tools 129

5 Monads as practical functionality providers 132

5.1 Basic monads in use: Maybe, Reader, Writer 133

Maybe monad as a line saver 133

Carrying configuration all over the program with Reader 136

Writing logs via Writer 140

5.2 Maintaining state via the State monad 147

Basic examples with the State monad 148

Parsing arithmetic expressions with State 152

RWS monad to rule them all: The game of dice 160

5.3 Other approaches to mutability 162

Mutable references in the IO monad 162

Mutable references in the ST monad 166

6 Structuring programs with monad transformers 170

6.1 The problem of combining monads 171

Evaluating expressions in reverse Polish notation 171

Introducing monad transformers and monad stacks 174

6.2 IO-based monad transformer stacks 179

Describing a monad stack 182

Exploiting monad stack functionality 184

Running an application 188

Can we do it without RWSTf 189

6.3 What is a monad transformer? 190

Step 0 Defining a type for a transformer 191

Step 1 Turning a monad stack into a monad 191

Step 2 Implementing the full monad stack functionality 195

Step 3 Supplying additional functionality 197

Using a transformer 198

6.4 Monad transformers in the Haskell libraries 199

Identity is where it all starts 199

An overview of the most common monad transformers 200

Part 3 Quality Assurance 203

7 Error handling and logging 205

7.1 Overview of error-handling mechanisms in Haskell 206

The idea of exceptions 206

To use or not to use? 208

Programmable exceptions vs. GHC runtime exceptions 209

7.2 Programmable exceptions in monad stacks 210

The ExceptT monad transformer 211

Example: Evaluating RPN expressions 211

7.3 GHC runtime exceptions 216

An idea of extensible exceptions 216

Throwing exceptions 218

Catching exceptions 219

7.4 Example: Accessing web APIs and GHC exceptions 222

Application components 225

Exception-handling strategies 233

7.5 Logging 241

An overview of the monad-logger library 243

Introducing logging with monad-logger into the suntimes project 244

8 Writing tests 246

8.1 Setting a scene: IPv4 filtering application 247

Development process overview 247

Initial implementation 248

8.2 Testing the IPv4 filtering application 252

Overview of approaches to testing 253

Testing Cabal projects with tasty 253

Specifications writing and checking with Hspec 255

Property-based testing with Hedgehog 262

Golden tests with tasty-golden 272

8.3 Other approaches to testing 276

Testing functions à la the REPL with doctest 276

Lightweight verification with LiquidHaskell 278

Code quality with Mint 279

9 Haskell data and code at run time 281

9.1 A mental model for Haskell memory usage at run time 282

General memory structure and closures 282

Primitive unboxed data types 284

Representing data and code in memory with closures 285

A detour: Lifted types and the concept of strictness 290

9.2 Control over evaluation and memory usage 293

Controlling strictness and laziness 293

Defining data types with unboxed values 299

9.3 Exploring compiler optimizations by example 301

Optimizing code manually 302

Looking at GHC Core 308

10 Benchmarking and profiling 310

10.1 Benchmarking functions with criterion 311

Benchmarking implementations of a simple function 311

Benchmarking an IPv4 filtering application 316

10.2 Profiling execution time and memory usage 327

Simulating iplookup usage in the real world 328

Analyzing execution time and memory allocation 329

Analyzing memory usage 333

10.3 Tuning performance of the IPv4 filtering application 334

Choosing the right data structure 335

Squeezing parseIP performance 336

Part 4 Advanced Haskell 341

11 Type system advances 343

11.1 Haskell types 101 344

Terms, types, and kinds 344

Delivering information with types 348

Type operators 355

11.2 Data kinds and type-level literals 356

Promoting types to kinds and values to types 356

Type-level literals 358

11.3 Computations over types with type families 362

Open and closed type synonym families 362

Example: Avoid character escaping in GHCi 365

Data families 368

Associated families 370

11.4 Generalized algebraic data types 372

Example: Representing dynamically typed values with GADTs 373

Example: Representing arithmetic expressions with GADTs 376

11.5 Arbitrary-rank polymorphism 378

The meaning 378

Use cases 380

11.6 Advice on dealing with type errors 383

Be explicit about types 383

Ask the compiler 385

Saying more about errors 386

12 Metaprogramming in Haskell 387

12.1 Deriving instances 388

Basic deriving strategies 388

The problem of type safety and generalized newtype deriving 393

Deriving by an example with DerivingVia 400

12.2 Data-type-generic programming 401

Generic data-type representation 402

Example: Generating SQL queries 405

12.3 Template Haskell and quasiquotes 410

A tutorial on Template Haskell 411

Example: Generating remote function calls 421

13 More about types 435

13.1 Types for specifying a web API 436

Implementing a web API from scratch 436

Implementing a web service with servant 445

13.2 Toward dependent types with singletons 447

A Safety in Haskell programs 447

Example: Unsafe interface for elevators 448

Dependent types and substituting them with singletons 452

Example: Safe interface for elevators 458

Part 5 Haskell Toolkit 477

14 Data-processing pipelines 479

14.1 Streaming data 480

General components and naive implementation 481

The streaming package 493

14.2 Approaching an implementation of pipeline stages 502

Reading and writing data efficiently 502

Parsing data with parser combinators 504

Accessing data with lenses 509

14.3 Example: Processing COVLD-19 data 517

The task 517

Processing data 519

Organizing the pipeline 527

15 Working with relational databases 530

15.1 Setting up an example 531

Sample database 531

Sample queries 533

Data representation in Haskell 535

15.2 Haskell database connectivity 537

Connecting to a database 537

Relating Haskell data types to database types 538

Constructing and executing SELECT queries 539

Manipulating data in a database 541

Solving tasks by issuing many queries 542

15.3 The postgresql-simple library 544

Connecting to a database 544

Relating Haskell data types to database types 544

Executing queries 545

15.4 The hasql ecosystem 547

Structuring programs with hasql 547

Constructing type-safe SQL statements 548

Implementing database sessions 552

Running database sessions 553

The need for low-level operations and decoding data manually 554

15.5 Generating SQL with opaleye 556

Structuring programs with opaleye 556

Describing database tables and their fields 557

Writing queries 562

Running queries 564

16 Concurrency 567

16.1 Running computations concurrently 568

An implementation of concurrency in GHC 568

Low-level concurrency with threads 569

High-level concurrency with the async package 577

16.2 Synchronization and communication 584

Synchronized mutable variables and channels 585

Software transactional memory (STM) 592

Appendix Further reading 603

Index 605

From the B&N Reads Blog

Customer Reviews