Functional Design and Architecture (First Edition) (E-Book (First Edition) + Code Samples)
$50.00
Minimum price
$60.00
Suggested price

Functional Design and Architecture (First Edition)

Building real programs in static functional languages: application architectures, design patterns, best practices and approaches

About the Book

Important: this is the First Edition of the book.

* Consider buying Functional Design and Architecture (Second Edition) by Manning instead.

* See also my new book Pragmatic Type-Level Design.

FDaA is a fundamental book about Software Design in Haskell and other functional languages. The main idea of this book is to provide a comprehensive source of knowledge, and a complete methodology for building real-world applications. 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, and logging. You’ll learn about design principles, application layers, functional interfaces, Inversion of Control, and Dependency Injection.

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 for 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 limited colored hardcover version of the book of the highest printing quality. This is what it looks like (video). Shipping is not possible at the moment.

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 of lines of code, and these frameworks are really tested in production. This technology helped the company to grow and enabled wide adoption of PureScript and Haskell. Essentially, Juspay was the first company I used my ideas. 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 the 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, and 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 the great testability of the HFM approach. You can read more about the framework in this my article: Building network actors with Node Framework.
  • Share this book

  • Categories

    • Haskell
    • Software Architecture
    • Software Engineering
    • Functional Programming
  • Feedback

    You must own a copy of this Book to access the forums.

    Email the Author(s)

About the Author

Alexander Granin
Alexander Granin

International speaker, researcher, author

Expert Haskell and C++ developer

Software architect, team lead

Haskell consultant

Author of the book "Functional Design and Architecture"

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
    • 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
  • 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
    • 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
  • 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
    • 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
    • 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
    • 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
  • Appendix
    • Appendix A Word statistics example with monad transformers

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.

You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!

So, there's no reason not to click the Add to Cart button, is there?

See full terms...

80% Royalties. Earn $16 on a $20 book.

We pay 80% royalties. That's not a typo: you earn $16 on a $20 sale. If we sell 5000 non-refunded copies of your book or course for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earnedover $13 millionwriting, publishing and selling on Leanpub.

Learn more about writing on Leanpub

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) and EPUB (for phones, tablets and 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

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub