Effective Haskell
Solving Real-World Problems with Strongly Typed Functional Programming
by Rebecca Skinner
Put the power of Haskell to work in your programs, learning from an
engineer who uses Haskell daily to get practical work done efficiently.
Leverage powerful features like Monad Transformers and Type Families to
build useful applications. Realize the benefits of a pure functional
language, like protecting your code from side effects. Manage concurrent
processes fearlessly. Apply functional techniques to working with
databases and building RESTful services. Don’t get bogged down in
theory, but learn to employ advanced programming concepts to solve
real-world problems. Don’t just learn the syntax, but dive deeply into
Haskell as you build efficient, well-tested programs.
Haskell is a pure functional programming language with a rich ecosystem
of tools and libraries. Designed to push the boundaries of programming,
it offers unparalleled power for building reliable and maintainable
systems. But to unleash that power, you need a guide. Effective Haskell
is that guide. Written by an engineer who understands how to apply
Haskell to the real world and uses it daily to get practical work done,
it is your ticket to Haskell mastery.
Gain deep understanding of how Haskell deals with IO and the outside
world by writing a complete Haskell application that does several
different kinds of IO. Reinforce your learnings with practice exercises
in every chapter.
Write stable and performant code using Haskell’s type system, code that
is easier to grow and refactor. Leverage the power of pure functional
programming to improve collaboration, make concurrency safe and easy,
and make large code bases manageable.
Implement type-safe web services, write generative tests, design
strongly typed embedded domain-specific languages, and build
applications that exploit parallelism and concurrency without fear of
deadlocks and race conditions. Create and deploy cloud-native Haskell
applications. Master the performance characteristics of functional
applications to make them run faster and use less memory.
Write Haskell programs that solve real-world business problems.
What You Need
- Intel based Mac, M1 Macs, Linux PC, or Windows with WSL2
- ghcup (https://www. Haskell.org/ghcup/)
- An active internet connection will be required for some projects.
Resources
Releases:
- P1.0 2023/08/01
- B9.0 2023/03/14
- B8.0 2022/11/07
- B7.0 2022/09/19
- Introduction
- Why Choose Haskell?
- Why This Book
- How to Read This Book
- Getting Started with Haskell
- Exploring Haskell Interactively
- Writing Your First Haskell Program
- Formatting Haskell Code
- Creating New Variables
- Writing Functions
- Precedence, Operators, and Fixity
- Creating Local Variables Using Let Bindings
- Running Code Conditionally Using Branches
- Looping
- Summary
- Exercises
- Working With
Lists
- Writing Code Using Lists
- Destructuring Values with Pattern Matching
- Understanding How Programs Are Evaluated
- Hands-On with Infinite Fibonacci Numbers
- Summary
- Exercises
- Getting Started with Types
- Working with Basic Haskell Types
- Annotating Values with Type Information
- Looking Up Type Information
- Writing Type Annotations for Functions
- Reading Type Errors
- Working with Polymorphic Functions
- Exploring the Type Space of an Application with Undefined
- Getting Help from Type Holes
- Looking at the Type of main
- Summary
- Exercises
- Creating New Types
- Creating Data Types and Records
- Creating Sum Types
- Creating Inductively Defined Data Structures
- Building a Calculator
- Functions as Values
- Creating Type Aliases
- Summary
- Exercises
- Creating And Structuring Haskell Projects
- Creating Haskell Projects
- Using Code from Other Modules
- Creating Your Own Modules
- Choosing What to Export
- Documenting Modules
- Summary
- Exercises
- Type Classes
- Understanding IO
- Talking About IO
- Performing IO in a Pure, Lazy Language
- Ordering and Combining IO Actions
- Independently Sequencing IO Actions
- Mapping IO Values with fmap
- Running IO in Real Applications
- Summary
- Exercises
- Working with the Local System
- Building Applications with IO
- Procedural Shell, Functional Core
- Creating a Pager
- Viewing the Contents of an ASCII or UTF8 Encoded Text File
- Viewing Text One Page at a Time
- Adding a Status Line with Metadata
- Showing the Status Bar and Refactoring runHCat
- Summary
- Exercises
- Introducing Monads
- Mapping Functors
- Applying Applicatives
- Working with the Monad Type Class
- Understanding the Laws of the Land
- Using the Functor Laws
- Using the Monad Laws
- Using the Applicative Laws
- Summary
- Exercises
- Mutable Data in the Real World
excerpt
- Using Mutable References in a Pure Language
- Working with IORefs
- Building a Basic Metrics System with IORefs
- Dealing with Laziness and IO
- Summary
- Exercises
- Serializing Heterogenous Data
- Heterogenous Data in Haskell
- A First Pass at a File Archiver
- Serializing with Type Classes
- Building a List of FileData Values
- Summary
- Exercises
- Deserializing Heterogenous Data
- Extracting Heterogenous Values from the Archive
- Deserialization as Parsing
- Creating a Parsing Function
- Building a Monadic Parser
- Parsing a List of Values
- Adding a Monad Instance
- Adding a MonadFail Instance
- Summary
- Exercises
- Building Applications with Many Effects
- Revisiting the Parsing Problem
- Handling Errors in Other Computations
- State, Transformed
- Stacking Transformers Effectively
- Building a File Archiver
- Summary
- Exercises
- Building Efficient Programs
- Building a Naive Spellchecker
- Memoizing editDistance
- Internal Mutability with ST
- Optimizing Memory Layout with Vectors
- The Fastest Edit Distance
- Summary
- Exercises
- Programming with Types
- What Is Type Level Programming?
- Types and Kinds
- Functions from Types to Types
- GADTs: Functions from Terms to Types
- Type Classes: Functions from Types to Terms
- Summary
- Exercises
Author
Rebecca Skinner is a software engineer with over 10 years of
experience in Haskell and functional programming across industries
including security, cloud infrastructure, and data science. She
currently volunteers as a member of the Haskell.org committee.