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:
- B9.0 2023/03/14
- B8.0 2022/11/07
- B7.0 2022/09/19
- B6.0 2022/08/15
Note: Contents and extracts of beta books will change as the book is developed.
- 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
- Creating Local Variables Using Let Bindings
- Running Code Conditionally Using Branches
- Writing Recursive Functions
- Summarizing
- Exercises
- Working With
Lists
- Writing Code Using Lists
- Destructuring Values With Pattern Matching
- Understanding How Programs Are Evaluated
- Summarizing
- 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
- Looking at the Type of main
- Summarizing
- Exercises
- Creating New Types
- Creating Data Types and Records
- Creating Sum Types
- Creating Inductively Defined Data Structures
- Building A Calculator
- Functions as Data Types
- Creating Types Aliases
- Summary
- Exercises
- Creating And Structuring Haskell Projects
- Creating Haskell Projects
- Depending On Other Files
- Creating Your Own Modules
- Writing Documentation and Packaging
- 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
- Summarizing
- 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
- Summarizing
- Exercises
- Introducing Monads
- Mapping Functors
- Applying Applicatives
- Working With The Monad Typeclass
- Understanding The Laws of The Land
- Using The Functor Laws
- Using The Monads Laws
- Using The Applicative Laws
- 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 Lazy IO
- Summarizing
- Exercises
- Serializing Heterogenous Data
- Heterogenous Data in Haskell
- A First Pass At A File Archiver
- Serializing With TypeClasses
- Building A List Of FilesDatas
- 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
- Summarizing
- Exercises
- Monad Transformers
- Composing Monads
- Carrying Around an Environment With The Reader Monad
- Generating Exceptions and Handling Failure
- Transforming With IO Actions
- Dealing With Mutable State
- Handling Data Efficiently
- Using Mutable Values in Pure Functions with ST
- Working With Mutable Arrays
- Fast Mutable Vectors
- Concurrency and Mutability with STM
- Summarizing
- Exercises
- Type Families
- Creating Typeclasses With More Than One Parameter
- Using Functional Dependencies
- Creating Constraints On TypeClass Parameters
- Adding Associated Type Families To Typeclasses
- Writing Type-Level Functions with Closed Type Families
- Extending Type-Level Programs with Open Type Families
- Programming With Types
- Programming with Types
- Building A Combinator With GADTs
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.