A Complete Guide to Functional Programming from First Principles to Production Mastery
Introduction: The Haskell Mindset
- What You Will Learn
- Prerequisites and How to Use This Book
- A Note About GHC Versions
- The Journey Ahead
Chapter 1: Why Haskell: A Different Way to Think About Code
- The Problem with Imperative Code
- What Makes Haskell Different
- A Taste of Haskell: Your First Program
- Who Uses Haskell in Production
- How to Read This Book
Chapter 2: Getting Started: Installation and Your First Programs
- Installing GHC and the Haskell Toolchain
- Your First Program: Hello World and Beyond
- The GHCi Interactive REPL
- Understanding the Compilation Process
- Cabal vs Stack: Package Managers Compared
- Your First Project Structure
- Building a Calculator: Pure Functions in Practice
- Exploring GHCi with Your Project
Chapter 3: Expressions, Types and Functions: The Building Blocks
- Everything Is an Expression
- Basic Types: Numbers, Booleans, Characters, Strings
- Defining and Calling Functions
- Type Declarations and Type Inference
- Guards and Conditional Logic
- Where and Let Bindings
- Practical Examples: Putting It All Together
Chapter 4: Lists, Pattern Matching and Recursion
- Lists: The Workhorse Data Structure
- Pattern Matching: Deconstructing Data Elegantly
- Recursion: Thinking Without Loops
- List Comprehensions
- Common List Functions: Map, Filter, Fold
- Writing Your First Recursive Algorithms
- Implementing Standard List Functions
Chapter 5: Algebraic Data Types: Modeling the World
- Product Types: Records and Structured Data
- Sum Types: Choice and Variants
- Type Synonyms and Newtypes
- Deriving Standard Classes
- Modeling a Domain: A Complete Example
- Extensible Effects with GADTs (Preview)
- Working with Trees: A Complete Example
- Custom Error Types with Smart Constructors
- Smart Constructors for Validation
Chapter 6: Higher-Order Functions and Function Composition
- Functions as First-Class Values
- Currying and Partial Application
- Function Composition: Building from Small Pieces
- Common Higher-Order Patterns
- Section Notation and Operator Sections
- The Lambda Calculus Connection
- Advanced Composition Patterns
Chapter 7: Type Classes: Ad Hoc Polymorphism Done Right
- What Are Type Classes?
- The Standard Hierarchy: Eq, Ord, Show, Read
- Numeric Type Classes: Num, Integral, Fractional
- Defining Your Own Type Classes
- Type Class Design Patterns
- Designing Your Own Type Classes
Chapter 8: Functors, Applicatives and Monads: The Big Three
- Functors: Mapping Over Contexts
- Applicatives: Combining Contextual Values
- Monads: Sequencing Computations
- The Maybe Monad: Handling Absence
- The List Monad: Non-Deterministic Computation
- The IO Monad: Bridging Pure and Impure Worlds
- Practical Monad Examples
Chapter 9: Advanced Type System Features
- Higher-Kinded Types
- Existential Types
- Type Families
- DataKinds and Singleton Types
- Liquid Haskell: Refinement Types
- The Expressiveness of the Haskell Type System
- Practical Advanced Types
Chapter 10: Lazy Evaluation and Performance Semantics
- How Laziness Works: Thunks and Demand
- Benefits of Lazy Evaluation
- The Space Leak Problem
- Strictness Annotations: Bang Patterns and STRICT
- Profiling and Benchmarking Haskell Programs
- Writing Performant Code: Best Practices
- Diagnosing and Fixing Space Leaks
Chapter 11: Error Handling: Beyond Exceptions
- Maybe and Either: Pure Error Handling
- The ExceptT Transformer
- Assertions and Debugging
- Exceptions in Haskell: When and Why
- The Validation Pattern: Accumulating Errors
- Custom Error Types for Your Domain
- Practical Error Handling Patterns
Chapter 12: Concurrency and Parallelism
- Threads and the MVar Primitive
- Software Transactional Memory (STM)
- The STM Pattern: Composable Transactions
- Parallelism with Strategies
- Concurrent Data Structures
- Real-World Concurrent Applications
- Advanced Concurrency Patterns
Chapter 13: Testing, Quality and Refactoring
- The Haskell Testing Ecosystem
- Unit Testing with HUnit
- Property-Based Testing with QuickCheck
- Combining Test Frameworks with Tasty
- Mocking and Integration Testing
- Refactoring Haskell Code
- Comprehensive Testing Examples
Chapter 14: The Haskell Ecosystem: Tools, Libraries and Packages
- Build Tools: Cabal, Stack and GHCup
- Linting and Formatting: HLint, Fourmolu, Stylish-Haskell
- Documentation: Haddock and Hoogle
- Package Management and Publishing to Hackage
- Essential Libraries: Text, Aeson, Lens, Conduit
- Web Frameworks: Servant, Yesod, Snap
- Setting Up a Professional Haskell Project
- Building a Blog API with Servant
Chapter 15: Design Patterns in Haskell
- The Parser Combinator Pattern
- The Church Encoding Pattern
- Free Monads: Interpretable Programs
- The Lens Pattern: Accessing Nested Data
- The Arrow Pattern: Dataflow Programming
- Functional Design Patterns vs Object-Oriented Patterns
- Advanced Design Pattern Examples
Chapter 16: Building Real Projects: From Concept to Production
- Project 1: A Command-Line Task Manager
- Project 2: A REST API with Servant
- Project 3: A Concurrent Web Crawler
- Deployment and CI/CD for Haskell
- Performance Tuning a Production Application
- Production Deployment Patterns
