Production Haskell
Production Haskell
Succeeding in Industry with Haskell
About the Book
So you've learned Haskell. You've taught your friends about monads, you've worked through some beginner textbooks, and maybe you've played around with some open source projects. Now that you've had a taste, you want more: you want to write an application in Haskell for fun! Maybe you want to use Haskell at work!
You sit down at your computer, and you're stuck.
How does anyone actually get anything done with this language?
This is a common thing to wonder.
Haskell has always enjoyed a wide variety of high quality learning material for advanced parts of the language, if you're not afraid of academic papers. The last five years have seen an upswelling of fantastic resources for learning the language as a beginner. However, the language does not have many resources for using it in production. It's difficult to navigate the ecosystems and identify quality resources that are in alignment with your goals and values.
This book aims to help with that situation. After reading this book, you should feel comfortable writing large software projects in Haskell, evaluating competing libraries and techniques, and productively reading material from a variety of Haskell users.
An Opinionated Tour Guide
Haskell is a hugely diverse landscape.
There are many regional groups: United Kingdom, Scandinavia, mainland Europe, Russia, the USA, Japan, China, and India all have thriving Haskell ecosystems that have interesting dialects and differences in custom and practice.
People come to Haskell with many backgrounds. Some people learned Haskell well into their careers, and had a long career writing Java, Scala, or C# beforehand. Some people came to Haskell from dynamically typed languages, like LISP or Ruby. Some people started learning Haskell very early on in their programming career, and use it as the basis of comparison. Some people primarily use Haskell in academic research, while others primarily use Haskell in industrial applications. Some people are hobbyists and just like to write Haskell for fun!
This book is intended for people that want to write Haskell in industry. The tradeoffs and constraints that industrial programmers face are different from academic or hobbyist programmers. This book will cover not only technical aspects of the Haskell language, but also social and engineering concerns that aren't "really" about Haskell.
Part of this book will be objective. I will teach you how to use some interesting techniques and ideas to make developing with Haskell more productive. We'll learn about Template Haskell, type-level programming, and other fun topics.
However, for the most part, this book is inherently subjective. Because Haskell serves so many ecosystems, it is imperative to discern what ecosystem a something is intended for. More than just giving out prescriptions - "This library is production ready! This is a toy!" - I hope to show my thought process and allow you to make your own judgment calls.
Ultimately, this is a book about the social reality of software engineering in niche languages.
About the Author
I'm Matt Parsons. I started learning programming in January 2014 with Java because I wanted to change careers. I learned JavaScript that summer with the excellent book [Eloquent JavaScript][eloquent-javascript]. It had a chapter on functional programming and object oriented programming. I found the chapter on functional programming more intuitive, so I made a mental note to learn the most functional language I could find. A few months later, I started learning Haskell.
My brain picked up Haskell extremely quickly. I had barely started learning imperative and object-oriented programming, so the difficult novelty of learning new jargon and concepts was expected. In August 2015, I started a Haskell internship, and I was able to use Haskell in my Artificial Intelligence coursework. In my last semester of college, I was able to use Haskell in my undergraduate thesis to study the connection between category theory, modal logic, and distributed systems.
I was extremely fortunate to have these opportunities, as they set me up for success to work with Haskell. My first job out of college was converting PHP applications to greenfield Haskell, and I've been working full-time with Haskell ever since. I've worked in a variety of contexts: a startup that wasn't 100% sold on Haskell, a larger company that was sold on Haskell but wrestling with social and technical difficulties of a huge code base and development team, and a startup that was sold on Haskell and working on growing. I also contribute to many open source projects, and I'm familiar with most of the ecosystems. All told, I have worked with nearly a million lines of Haskell code!
I've seen Haskell fail, and I've seen it succeed. I'd like to help you succeed with Haskell.
Table of Contents
-
-
CHANGELOG
- v6-2021-02-01
- v5-2021-01-01
- v4-2020-12-01
- v3-2020-11-01
- v2-2020-10-14
- v1-2020-10-07
-
Introduction
- An Opinionated Tour Guide
- About the Author
- Acknowledgements
-
Principles
- Complexity
- Novelty
- Cohesion
- Empathy
- References
-
CHANGELOG
-
I Building Haskell Teams
-
1. Selling Haskell
- 1.1 Assessing Receptiveness
- 1.2 Software Productivity
- 1.3 Statistics of Productivity
- 1.4 Know Your Competition
-
2. Learning and Teaching Haskell
- 2.1 The Philology of Haskell
- 2.2 Programming Isn’t Easy To Learn
- 2.3 Pick Learning Materials
- 2.4 Write Lots of Code
- 2.5 Don’t Fear the GHC
- 2.6 Start Simple
- 2.7 Solve Real Problems
- 2.8 Pair Programming
- 2.9 A Dialogue
- 2.10 References
-
3. Hiring Haskellers
- 3.1 The Double Edged Sword
- 3.2 Juniors and Seniors
- 3.3 Hiring Seniors
- 3.4 Hiring Juniors
-
4. Evaluating Consultancies
- 4.1 Identifying the Target
- 4.2 Well-Typed
- 4.3 FP Complete
-
1. Selling Haskell
-
II Application Structure
-
5. The Beginning
- 5.1 Abstraction for Mocking
- 5.2 Forward Compatibility
-
5.3
AppEnvironment
-
5.4 The
ReaderT
Pattern - 5.5 Embed, don’t Stack
-
6. Three Layer Haskell Cake
- 6.1 Layer 1: Imperative Programming
- 6.2 Layer 2: Object Oriented Programming
- 6.3 Layer 3: Functional Programming
- 6.4 Examples
-
7. Invert Your Mocks!
- 7.1 Decomposing Effects
- 7.2 Streaming Decomposition
- 7.3 Plain ol’ abstraction
- 7.4 Decompose!!!
- 7.5 What if I need to?
-
8. Project Preludes
- 8.1 Prelude Problems
- 8.2 Custom Benefits
- 8.3 Off-The-Shelf Preludes
- 8.4 Nesting Preludes
- 8.5 Downsides
- 8.6 Using a Custom Prelude
-
9. Optimizing GHC Compile Times
-
9.1 The
Project.Types
Megamodule - 9.2 Package Splitting
- 9.3 Big Ol Instances Module
- 9.4 Some random parting thoughts
- 9.5 Results
-
9.1 The
-
5. The Beginning
-
III Domain Modeling
-
10. Type Safety Back and Forth
- 10.1 The Ripple Effect
- 10.2 Ask Only What You Need
-
11. Keep Your Types Small…
- 11.1 Expansion and Restriction
- 11.2 Constraints Liberate
- 11.3 Restrict the Range
- 11.4 A perfect fit
-
12. The Trouble with Typed Errors
- 12.1 Monolithic error types are bad
- 12.2 Boilerplate be gone!
- 12.3 Type Classes To The Rescue!
-
13. Exceptions
- 13.1 Exceptions In Five Minutes
- 13.2 Best Practices
- 13.3 Hierarchies
- 13.4 Reinventing
- 13.5 Asynchronous Exceptions
- 13.6 The Theory
- 13.7 HasCallStack
-
14. EDSL Design
-
14.1 Tricks with
do
- 14.2 Overloaded Literals
- 14.3 Type Inference Trick
- 14.4 Fluent Interfaces
- 14.5 Case Study: Weightlifting Logging
-
14.6 Case Study:
rowdy
-
14.7 Case Study:
hspec
-
14.1 Tricks with
-
15. Growing Pains
- 15.1 A Taxonomy of Breaking Changes
- 15.2 Avoiding Breaking Changes
- 15.3 Communicating To Users
-
10. Type Safety Back and Forth
-
IV Interfacing the Real
-
16. Testing
- 16.1 Libraries and Tools
- 16.2 Designing Code for Testing
-
17. Mocking
-
17.1 Case Study:
MonadLock
-
17.1 Case Study:
-
18. Logging
- 18.1 Logging Contexts
- 18.2 Library Comparison
-
19. Databases
- 19.1 Separate Database Types
- 19.2 Schema Migrations
- 19.3 Data Migrations
- 19.4 Access Patterns
- 19.5 Conclusion
- 20. Database Library Comparisons
- 21. Profiling
-
16. Testing
-
V Advanced Haskell
-
22. Template Haskell Is Not Scary
- 22.1 A Beginner Tutorial
- 22.2 wait this isn’t haskell what am i doing here
- 22.3 Constructing an AST
- 22.4 Boilerplate Be Gone!
-
23. Basic Type Level Programming
- 23.1 The Basic Types
- 23.2 The Higher Kinds
- 23.3 Dynamically Kinded Programming
- 23.4 Data Kinds
- 23.5 GADTs
- 23.6 Vectors
- 23.7 Type Families
- 23.8 This Sucks
- 23.9 Heterogeneous Lists
- 23.10 Inductive Type Class Instances
- 23.11 Extensible Records
- 23.12 Like what you read?
-
24. Trade-offs in Type Programming
- 24.1 MPTCs
- 24.2 MPTCs + Fundeps
- 24.3 Associated Types
- 24.4 Comparisons
-
25. Case Study: Prairie
- 25.1 Problem Statement:
- 25.2 Prior Art
- 25.3 The GADT Approach
- 25.4 Improvements?
- 25.5 Symbols
- 25.6 Compare and Constrast
- 25.7 Identify the Issue
- 25.8 Generalize a GADT
- 25.9 Fundeps
- 25.10 More Class Please
- 25.11 Refining the Class
- 25.12 Template Haskell
- 25.13 Conclusion
-
22. Template Haskell Is Not Scary
- Notes
Authors have earned$10,095,386writing, publishing and selling on Leanpub, earning 80% royalties while saving up to 25 million pounds of CO2 and up to 46,000 trees.
Learn more about writing on Leanpub
The Leanpub 45-day 100% Happiness Guarantee
Within 45 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers), EPUB (for phones and tablets) and MOBI (for Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Learn more about Leanpub's ebook formats and where to read them
Top Books
C++20
Rainer GrimmC++20 is the next big C++ standard after C++11. As C++11 did it, C++20 changes the way we program modern C++. This change is, in particular, due to the big four of C++20: ranges, coroutines, concepts, and modules.
The book is almost daily updated. These incremental updates ease my interaction with the proofreaders.
A Guide to Artificial Intelligence in Healthcare
Dr. Bertalan MeskoCan we stay human in the age of A.I.? To go even further, can we grow in humanity, can we shape a more humane, more equitable and sustainable healthcare? This e-book aims to prepare healthcare and medical professionals for the era of human-machine collaboration. Read our guide to understanding, anticipating and controlling artificial intelligence.
Atomic Kotlin
Bruce Eckel and Svetlana IsakovaFor both beginning and experienced programmers! From the author of the multi-award-winning Thinking in C++ and Thinking in Java together with a member of the Kotlin language team comes a book that breaks the concepts into small, easy-to-digest "atoms," along with exercises supported by hints and solutions directly inside IntelliJ IDEA!
C++ Best Practices
Jason TurnerLevel up your C++, get the tools working for you, eliminate common problems, and move on to more exciting things!
Introducing EventStorming
Alberto BrandoliniThe deepest tutorial and explanation about EventStorming, straight from the inventor.
Ansible for DevOps
Jeff GeerlingAnsible is a simple, but powerful, server and configuration management tool. Learn to use Ansible effectively, whether you manage one server—or thousands.
Everyday Rails - RSpecによるRailsテスト入門
Junichi Ito (伊藤淳一), AKIMOTO Toshiharu, 魚振江, and Aaron SumnerRSpecを使ってRailsアプリケーションに信頼性の高いテストを書く実践的なアドバイスを提供します。詳細で丁寧な説明は本書のオリジナルコンテンツです。また、説明には実際に動かせるサンプルアプリケーションも使用します。本書は2017年版にアップデートされ、RSpec 3.6やRails 5.1といった新しい環境に対応しています!さあ、自信をもってテストできるようになりましょう!
R Programming for Data Science
Roger D. PengThis book brings the fundamentals of R programming to you, using the same material developed as part of the industry-leading Johns Hopkins Data Science Specialization. The skills taught in this book will lay the foundation for you to begin your journey learning data science. Printed copies of this book are available through Lulu.
The Hundred-Page Machine Learning Book
Andriy BurkovEverything you really need to know in Machine Learning in a hundred pages.
Continuous Delivery Pipelines
Dave FarleyThis practical handbook provides a step-by-step guide for you to get the best continuous delivery pipeline for your software.
Top Bundles
- #1
Software Architecture for Developers: Volumes 1 & 2 - Technical leadership and communication
2 Books
"Software Architecture for Developers" is a practical and pragmatic guide to modern, lightweight software architecture, specifically aimed at developers. You'll learn:The essence of software architecture.Why the software architecture role should include coding, coaching and collaboration.The things that you really need to think about before... - #2
All the Books of The Medical Futurist
6 Books
We put together the most popular books from The Medical Futurist to provide a clear picture about the major trends shaping the future of medicine and healthcare. Digital health technologies, artificial intelligence, the future of 20 medical specialties, big pharma, data privacy, digital health investments and how technology giants such as Amazon... - #3
PowerShell
3 Books
Buy every PowerShell book from Adam Bertram at a 20% discount! - #4
Cisco CCNA 200-301 Complet
4 Books
Ce lot comprend les quatre volumes du guide préparation à l'examen de certification Cisco CCNA 200-301. - #5
Software Architecture and Beautiful APIs
2 Books
There is no better way to learn how to design good APIs than to look at many existing examples, complementing the Software Architecture theory on API design. - #6
Linux Administration Complet
4 Books
Ce lot comprend les quatre volumes du Guide Linux Administration :Linux Administration, Volume 1, Administration fondamentale : Guide pratique de préparation aux examens de certification LPIC 1, Linux Essentials, RHCSA et LFCS. Administration fondamentale. Introduction à Linux. Le Shell. Traitement du texte. Arborescence de fichiers. Sécurité... - #7
Learn Git, Bash, and Terraform the Hard Way
3 Books
Learn Git, Bash and Terraform using the Hard Way method.These technologies are essential tools in the DevOps armoury. These books walk you through their features and subtleties in a simple, gradual way that reinforces learning rather than baffling you with theory. - #8
9 Books-Bundle: Shut Up and Code!
9 Books
"Shut up and code." Laughter in the audience. The hacker had just plugged in his notebook and started sharing his screen to present his super-smart Python script. "Shut up and code" The letters written in a white literal coding font on black background was the hackers' home screen background mantra. At the time, I was a first-year computer... - #9
Mastering Containers
2 Books
Docker and Kubernetes are taking the world by storm! These books will get you up-to-speed fast! Docker Deep Dive is over 400 pages long, and covers all objectives on the Docker Certified Associate exam.The Kubernetes Book includes everything you need to get up and running with Kubernetes! - #10
CCDE Practical Studies (All labs)
3 Books
CCDE lab