Functional Design and Architecture (E-Book + Code Samples)
Functional Design and Architecture
Building real programs in Haskell: application architectures, design patterns, best practices and approaches
About the Book
It is a fundamental book about Software Design in Haskell. The main idea of this book is to provide a comprehensive source of knowledge, a complete methodology of building real world applications in Haskell. Application architectures, best practices, design patterns and approaches, - all the information you need to achieve a simple, maintainable, testable code with low complexity and low risks. By reading this book, you’ll learn many useful techniques: from the requirement analysis to the implementation of particular subsystems such as SQL and NoSQL databases, multithreading, logging. You’ll learn about design principles, application layers, functional interfaces, Inversion of Control and Dependency Injection in Haskell.
The book has 9 chapters, 780K symbols, 120K words.
The book is very practical. It will be useful for software engineers who want to improve their software design skills with a strong relation to many advanced Haskell concepts.
The book requires a certain level of Haskell knowledge, up to intermediate.
The book covers a big gap in the Haskell ecosystem: the lack of resources about high-level application design. It’s also important that the ideas from the book were used in real production with great success. The book offers my own methodology - Functional Declarative Design, with Hierarchical Free Monads as a core technology. Using this methodology, I created several real-world frameworks, and they are driving a successful business in several companies.
There is a colored hardcover version of the book of the highest printing quality. This is how it looks like (video). Shipping is only across Russia. Contact me if you are interested. International shipping from Russia stopped working after January 2020 due to "new customs rules". You can find the detailed explanation here.
Book topics:
- requirements analysis and architecture modeling;
- application layering;
- design principles, SOLID;
- Haskell-specific design patterns;
- Inversion of Control and Dependency Injection;
- domain modeling, embedded and external DSLs;
- functional interfaces, subsystems and services;
- Free monads, ReaderT pattern, Service handle pattern;
- Final Tagless/mtl, GADTs
- multithreading and concurrency;
- state and stateful applications;
- design of business logic;
- interaction with impure subsystems;
- relational and key-value databases;
- error handling, exceptions, error domains;
- web servers, HTTP backends, CLI applications;
- property-based, functional and integration testing;
- black box and white box testing.
The book is project-based. There are two showcase projects for it:
- Hydra, a full-fledged framework for building web services, multithreaded and concurrent applications with SQL and KV DB support. Contains 3 engines: Final Tagless, Free Monad and Church Encoded Free Monad, as well as several demo applications to compare these 3 approaches.
- Andromeda, a SCADA software for spaceship control.
I designed the following real-world frameworks using the ideas from the book (with the help of other people of course):
- EulerHS - a Haskell framework for web backends and console apps. Has many subsystems out of the box: SQL DBs support (Postgres, MySQL, SQLite), KV DBs support (Reddis), logging, concurrent flows, exception handling, automatic whitebox testing, typed options and other stuff.
- PureScript Presto - a PureScript framework for building mobile apps using a handy eDSL.
- PureScript Presto.Backend - a PureScript framework for web backends. It has the same design as Presto but also is empowered by some additional features like logging, HTTP APIs integration, KV DB, SQL DB subsystems, state handling, automatic whitebox testing, and other useful stuff.
All of these frameworks drive the business of an Indian financial company Juspay. Its mobile apps and financial backends have hundreds of thousands lines of code, and these frameworks are really tested in production. This technology helped the company to grow up and enabled a wide adoption of PureScript and Haskell. Essentially, Juspay was the first company I used my ideas in. We found that Hierarchical Free Monads hide all the complexity of implementation details behind convenient interfaces so that the code is understandable by not only developers but by managers as well. This helped us to easily reason about the domain, the logic, the business goals and requirements. My approach also brought confidence that Haskell and PureScript are not only academic languages.
- Node - a full-fledged framework for building distributed, concurrent, multithreading apps, blockchains initially, but not only. I designed this framework for Enecuum and then we successfully created our own blockchain using it. What's important, we managed to achieve our goals less than in 4 months with a team of 4 haskellers. The framework allowed us to write fast, complicated blockchain logic easily, quickly, without bugs and with maximum confidence due to a great testability of the HFM approach. You can read more about the framework in this my article: Building network actors with Node Framework.
Table of Contents
- Part I Introduction to Functional Declarative Design
- 1 What is software design?
- 1.1 Software design
- 1.1.1 Requirements, goals, and simplicity
- 1.1.2 Defining software design
- 1.1.3 Low coupling, high cohesion
- 1.1.4 Interfaces, Inversion of Control and Modularity
- 1.2 Imperative design
- 1.3 Object-oriented design
- 1.3.1 Object-oriented design patterns
- 1.3.2 Object-oriented design principles
- 1.3.3 Shifting to functional programming
- 1.4 Functional declarative design
- 1.4.1 Immutability, purity and determinism in FDD
- 1.4.2 Strong static type systems in FDD
- 1.4.3 Functional patterns, idioms and thinking
- 1.5 Summary
- 1.1 Software design
- 2 Application architecture
- 2.1 Defining software architecture
- 2.1.1 Software architecture in FDD
- 2.1.2 Top-down development process
- 2.1.3 Collecting requirements
- 2.1.4 Requirements in mind maps
- 2.2 Architecture layering and modularization
- 2.2.1 Architecture layers
- 2.2.2 Modularization of applications
- 2.3 Modeling the architecture
- 2.3.1 Defining architecture components
- 2.3.2 Defining modules, subsystems and relations
- 2.3.3 Defining architecture
- 2.4 Summary
- 2.1 Defining software architecture
- 1 What is software design?
- Part II Domain Driven Design
- 3 Subsystems and services
- 3.1 Functional subsystems
- 3.1.1 Modules and libraries
- 3.1.2 Monads as subsystems
- 3.1.3 Layering subsystems with the monad stack
- 3.2 Designing the Hardware subsystem
- 3.2.1 Requirements
- 3.2.2 Algebraic data type interface to HDL
- 3.2.3 Functional interface to the Hardware subsystem
- 3.2.4 Free monad interface to HDL
- 3.2.5 Interpreter for monadic HDL
- 3.2.6 Advantages and disadvantages of a free language
- 3.3 Functional services
- 3.3.1 Pure service
- 3.3.2 Impure service
- 3.3.3 The MVar request-response pattern
- 3.3.4 Remote impure service
- 3.4 Summary
- 3.1 Functional subsystems
- 4 Domain model design
- 4.1 Defining the domain model and requirements
- 4.2 Simple embedded DSLs
- 4.2.1 Domain model eDSL using functions and primitive types
- 4.2.2 Domain model eDSL using ADT
- 4.3 Combinatorial eDSLs
- 4.3.1 Mnemonic domain analysis
- 4.3.2 Monadic Free eDSL
- 4.3.3 The abstract interpreter pattern
- 4.3.4 Free language of Free languages
- 4.3.5 Arrows for eDSLs
- 4.3.6 Arrowized eDSL over Free eDSLs
- 4.4 External DSL
- 4.4.1 External DSL structure
- 4.4.2 Parsing to the abstract syntax tree
- 4.4.3 The translation subsystem
- 4.5 Summary
- 5 Application state
- 5.1 Stateful application architecture
- 5.1.1 State in functional programming
- 5.1.2 Minimum viable product
- 5.1.3 Hardware network description language
- 5.1.4 Architecture of the simulator
- 5.2 Pure state
- 5.2.1 Argument-passing state
- 5.2.2 The State monad
- 5.3 Impure state
- 5.3.1 Impure state with IORef
- 5.3.2 Impure state with State and IO monads
- 5.4 Summary
- 5.1 Stateful application architecture
- 3 Subsystems and services
- Part III Designing real world software
- 6 Multithreading and Concurrency
- 6.1 Multithreaded applications
- 6.1.1 Why is multithreading hard?
- 6.1.2 Bare threads
- 6.1.3 Separating and abstracting the threads
- 6.1.4 Threads bookkeeping
- 6.2 Software Transactional Memory
- 6.2.1 Why STM is important
- 6.2.2 Reducing complexity with STM
- 6.2.3 Abstracting over STM
- 6.3 Useful patterns
- 6.3.1 Logging and STM
- 6.3.2 Reactive programming with processes
- 6.4 Summary
- 6.1 Multithreaded applications
- 7 Persistence
- 7.1 Database model design
- 7.1.1 Domain model and database model
- 7.1.2 Designing database model ADTs
- 7.1.3 Primary keys and the HKD pattern
- 7.1.4 Polymorphic ADTs with the HKD pattern
- 7.2 SQL and NoSQL database support
- 7.2.1 Designing untyped key-value database subsystem
- 7.2.2 Abstracted logic vs bare IO logic
- 7.2.3 Designing a SQL database model
- 7.2.4 Designing a SQL database subsystem
- 7.3 Advanced database design
- 7.3.1 Advanced SQL database subsystem
- 7.3.2 Typed key-value database model
- 7.3.3 Pools and transactions
- 7.4 Summary
- 7.1 Database model design
- 8 Business logic design
- 8.1 Business logic layering
- 8.1.1 Explicit and implicit business logic
- 8.2 Exceptions and error handling
- 8.2.1 Error domains
- 8.2.2 Native exceptions handling schemes
- 8.2.3 Free monad languages and exceptions
- 8.3 A CLI tool for reporting astronomical objects
- 8.3.1 API types and command-line interaction
- 8.3.2 HTTP and TCP client functionality
- 8.4 Functional interfaces and Dependency Injection
- 8.4.1 Service Handle Pattern
- 8.4.2 ReaderT Pattern
- 8.4.3 Additional Free monad language
- 8.4.4 GADT
- 8.4.5 Final Tagless/mtl
- 8.5 Designing web services
- 8.5.1 REST API and API types
- 8.5.2 Using the framework for business logic
- 8.5.3 Web server with Servant
- 8.5.4 Validation
- 8.5.6 Configuration management
- 8.6 Summary
- 8.1 Business logic layering
- 9 Testing
- 9.1 Testing in functional programming
- 9.1.1 Test-driven-development in functional programming
- 9.1.2 Testing basics
- 9.1.3 Property-based testing
- 9.1.4 Property-based testing of a Free monadic scenario
- 9.1.5 Integration testing
- 9.1.6 Acceptance testing
- 9.2 Advanced testing techniques
- 9.2.1 Testable architecture
- 9.2.2 Mocking with Free monads
- 9.2.3 White box unit testing
- 9.2.4 Testing framework
- 9.2.5 Automatic white box testing
- 9.3 Testability of different approaches
- 9.4 Summary
- 9.1 Testing in functional programming
- 6 Multithreading and Concurrency
- Appendix
- Appendix A Word statistics example with monad transformers
Authors have earned$10,261,184writing, 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.
500 QUIZ MMG COMMENTATI
ALS Medicina Generale500 Quiz degli ULTIMI Concorsi di Medicina Generale (2014/2016/2017/2018/2019)
Riassunti e suddivisi per area con Griglia risposte vuota e Griglia risposte esatte Ministeriale
Commentati con link alla fonte per approfondimento e ausilio allo studio
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.
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.
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!
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.
C++ Best Practices
Jason TurnerLevel up your C++, get the tools working for you, eliminate common problems, and move on to more exciting things!
Visualise, document and explore your software architecture
Simon BrownA short guide to visualising, documenting and exploring your software architecture.
Discrete Mathematics for Computer Science
Alexander Shen, Alexander S. Kulikov, Vladimir Podolskii, and Aleksandr GolovnevThis book supplements the DM for CS Specialization at Coursera and contains many interactive puzzles, autograded quizzes, and code snippets. They are intended to help you to discover important ideas in discrete mathematics on your own. By purchasing the book, you will get all updates of the book free of charge when they are released.
Functional Design and Architecture
Alexander GraninSoftware Design in Functional Programming, Design Patterns and Practices, Methodologies and Application Architectures. How to build real software in Haskell with less efforts and low risks. The first complete source of knowledge.
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
Software Architecture and Design Practice Reference
2 Books
Dive deeper in Software Architecture with the Design Practice Reference. Learn all about software architecture and design from the books in this bundle:Software Architecture covers topics from quality attributes to designing and modeling components, interfaces, connectors, and containers, all the way to services and microservices. The 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
The Python Craftsman
3 Books
The Python Craftsman series comprises The Python Apprentice, The Python Journeyman, and The Python Master. The first book is primarily suitable for for programmers with some experience of programming in another language. If you don't have any experience with programming this book may be a bit daunting. You'll be learning not just a programming... - #8
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... - #10
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!