Practical Haskell: A Real-World Guide to Functional Programming

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

Get a practical, hands-on introduction to the Haskell language, its libraries and environment, and to the functional programming paradigm that is fast growing in importance in the software industry. This updated edition includes more modern treatment of Haskell's web framework and APIs. This book contains excellent coverage of the Haskell ecosystem and supporting tools, including Cabal and Stack for managing projects, HUnit and QuickCheck for software testing, WAI and Elm to develop the back end and front end of web applications, Persistent and Esqueleto for database access, and parallel and distributed programming libraries. You’ll see how functional programming is gathering momentum, allowing you to express yourself in a more concise way, reducing boilerplate, and increasing the safety of your code. Haskell is an elegant and noise-free pure functional language with a long history, having a huge number of library contributors and an active community. This makes Haskell the best tool for both learning and applying functional programming, and Practical Haskell, Third Edition takes advantage of this to show off the language and what it can do. Free source code available on the Apress GitHub page for this book. What You Will Learn • Get started programming with Haskell • Examine the different parts of the language • Gain an overview of the most important libraries and tools in the Haskell ecosystem • Apply functional patterns in real-world scenarios • Understand monads and monad transformers • Proficiently use laziness and resource management Who This Book Is For Experienced programmers who may be new to the Haskell programming language. However, some prior exposure to Haskell is recommended.

Author(s): Alejandro Serrano Mena
Edition: 3
Publisher: Apress
Year: 2022

Language: English
Commentary: Vector PDF
Pages: 617
City: New York, NY
Tags: Databases; Data Mining; Web Applications; Concurrency; Functional Programming; Parallel Programming; SQL; Queries; Lambda Functions; Laziness; Documentation; Haskell; Monads; Error Handling; Software Architecture; Testing; Distributed Processing; Text Processing; Domain-Specific Languages; RESTful API; Code Reusability; Type-Driven Development

Table of Contents
About the Author
About the Technical Reviewer
Acknowledgments
Introduction
Part I: First Steps
Chapter 1: Going Functional
Why Haskell?
Why Pure Functional Programming?
Why Strong Static Typing?
The Haskell Ecosystem
The History of Haskell
Your Working Environment
First Steps with GHCi
The Time Machine Store
Summary
Chapter 2: Declaring the Data Model
Characters, Numbers, and Lists
Characters
Numbers
Strings
Lists
Creating a New Project
Creating a Project with Cabal
Creating a Project with Stack
Understanding Modules
Cabal and Stack
Defining Simple Functions
Creating a Simple Function
Specifying the Function’s Type
Developing a Robust Example
Returning More Than One Value
Working with Data Types
Pattern Matching
Simple Patterns
Lists and Tuples
Guards
View Patterns
Records
Creation and Use
The Default Values Idiom
Summary
Chapter 3: Increasing Code Reuse
Parametric Polymorphism
Functions As Parameters
Higher-Order Functions
Anonymous Functions
Partial Application of a Function
More on Modules
Module Imports
Smart Constructors and Views
Diving into Lists
Folds
Lists and Predicates
Lists Containing Tuples
List Comprehensions
Haskell Origami
Summary
Chapter 4: Using Containers and Type Classes
Using Packages
Managing Dependencies
Building Packages
Building Packages with Cabal
Building Packages with Stack
Obtaining Help
Containers: Maps, Sets, Trees, Graphs
Maps
Sets
Trees
Graphs
Ad Hoc Polymorphism: Type Classes
Declaring Classes and Instances
Built-In Type Classes
Binary Trees for the Minimum Price
Step 1: Simple Binary Trees
Step 2: Polymorphic Binary Trees
Step 3: Binary Trees with Monoidal Cache
Container-Related Type Classes
Functors
Foldables
Summary
Chapter 5: Laziness and Infinite Structures
An Infinite Number of Time Machines
Lazy Evaluation Model
Understanding Evaluation in Haskell
Problems with Laziness
Pattern Matching and Laziness
Profiling with GHC
Strictness Annotations
Summary
Part II: Data Mining
Chapter 6: Knowing Your Clients Using Monads
Data Mining
Implementing K-means
Lenses
Discovering Monads
Watching Out for Incomplete Data
Combinators for State
Dissecting the Combinators
do Notation
Monad Laws
Different Sorts of State
State and Lenses
Reader, Writer, and RWS
Mutable References with ST
Summary
Chapter 7: More Monads: Now for Recommendations
Returning More Than One Value
The List Monad
A New View over Monads
Failures and Alternatives
Association Rule Learning
Flattening Values into Transactions
The Apriori Algorithm
Search Problems
Paths in a Graph
The Logic Monad
Monads and Lists, Redux
Combining Values Under a Monad
Monad Comprehensions
Combining Monads
Monad Transformers
Monad Classes
Summary
Chapter 8: Working in Several Cores
Parallelism, Concurrency, and Distribution
The Par Monad
Futures
Dataflow Parallelism with IVars
Parallelizing the Apriori Algorithm
Software Transactional Memory
Concurrent Use of Resources
Atomic Transactions
Rolling Back Transactions
Producer-Consumer Queues
Single-Process Queues
Message Queues Using AMQP
AMQP in Haskell
Summary
Part III: Resource Handling
Chapter 9: Dealing with Files: IO and Conduit
Basic Input and Output
Randomness
Working with Files
Reading and Writing
Handling Files
Error Handling
Pure Errors
Catching Exceptions
Throwing Exceptions
Streaming Data with Conduit
Problems with Lazy Input/Output
Introducing Conduits
Accessing Files via Conduit
Looking Further Than Text Files
Basic Networking
Binary Serialization
Comma-Separated Values
Summary
Chapter 10: Building and Parsing Text
The Five Textual Data Types
Building As Fast As the Wind
Parsing with attoparsec
Introducing New Type Classes
Applicative
Functors, Applicatives, and Monads
Alternative
Traversable
Don’t Overengineer: Just Use JSON
Summary
Chapter 11: Safe Database Access
Database Access Landscape
Abstracting Over Several DBMSs
Introducing Persistent and Esqueleto
Connection
Schemas and Migrations
Describing the Entities
Creating the Database
Queries
Queries by Identifier or Uniqueness
Selecting Several Entities
SQL Queries with Esqueleto
Insertions, Updates, and Deletions
Summary
Chapter 12: Web Applications
Haskell Web Ecosystem
Web Applications
Compilation to JavaScript
RESTful Structure
Back End with WAI
Simple Skeleton
Showing Products from the Database
Inserting New Products Using Forms
Front End with Elm
Retrieving Products
Summary
Part IV: Domain-Specific Languages
Chapter 13: Strong Types for  Describing Offers
Domain-Specific Languages
Embedding Your Language in Haskell
The Offers Language
Adding Safety to the Expression Language
Type-Level Programming
Two Styles of Programming
Representing Natural Numbers
Functional Dependencies
Categories of Products with FDs
Vectors Using FDs
Enforcing the Presents Rule with FDs
Type Families
Vectors Using TFs
Enforcing the Presents Rule with TFs
Categories of Products with TFs
Data Type Promotion and Singletons
A Further Refinement to the Presents Rule
Cooking with Singletons
Enforcing the Duration Rule
Summary
Chapter 14: Interpreting Offers with Attributes
Interpretations and Attribute Grammars
A Simple Interpretation
Introducing Attribute Grammars
Your First Attribute Grammar
Synthesizing the Result
Integrating UUAGC in Your Package
Executing the Attribute Grammar
Expression Interpretation
Using an Attribute Grammar
Precomputing Some Values
A Different (Monadic) View
Offer Interpretations
Checking the Presents Rule
Showing an HTML Description
Programming with Data Types
Origami Programming over Any Data Type
Data Type–Generic Programming
Summary
Part V: Engineering the Store
Chapter 15: Documenting, Testing, and Verifying
Documenting Binary Trees with Haddock
Unit Testing with HUnit
Declaring Tests in Cabal
Writing Unit Tests
Randomized Testing with QuickCheck
Testing List Properties
Testing Binary Tree Properties
Formal Verification with LiquidHaskell
Describing Binary Search Trees
Summary
Chapter 16: Architecting Your Application
Tools
Project and Dependency Management
Code Style
Documentation
Test and Verification
Benchmarking
Profiling
Coverage
Remote Monitoring
Design Patterns and Functional Programming
Medium-Level Guidelines
Use Higher-Order Combinators
Refactor
Use Type Classes Wisely
Enforce Invariants via the Type System
Stay (As) Pure and Polymorphic (As Possible)
Patterns with Monads
Summary of Monads
Restrictive Monad Classes
Roll Your Own Monad
Summary
Chapter 17: Looking Further
Projects
Data Mining Library
Store Network Client
Administration Interface and Tetris
Additional Haskell Resources
Other Functional Languages
Appendix A: Time Travelling with Haskell
Index