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

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.

There is a printed version of the book. This is how it looks like (video). You can either obtain a light package with the e-book only, or buy a full package offering an e-book copy, educational videos and a paper book. Send me your PurchaseID and shipping address by email, and I'll send you a copy for free.

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.

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):

  • PureScript Presto - a framework for building mobile apps using a handy eDSL.
  • PureScript Presto.Backend - a framework for web RESTful 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.

Both of these frameworks drive the business of an Indian financial company Juspay. Its mobile apps and financial backends are written on top of Presto and Presto.Backend. This technology helped the company to grow up and enabled a wide adoption of PureScript and Haskell in the future. 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.
  • Share this book

  • 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"

Packages

E-Book + Code Samples

+ E-Book + Code samples - No educational videos - No additional content - No paper book

Includes:

  • extras
    The Hydra project

    The second showcase project for the book. Hydra is a full-fledged framework for building web services, multithreaded and concurrent applications with SQL and KV DB support. The code is available here: https://github.com/graninas/Hydra

  • extras
    The Andromeda project

    The first showcase project for the book. A SCADA software for spaceship control. The code is available here: https://github.com/graninas/Andromeda

  • extras
    The book in a bigger font formatting, v.0.9.5.75

    This is a PDF with the book with the increased font. V.0.9.5.75. It is experimental, and the code is not properly formatted here. There will be a better formatted version by the end of September.

  • extras
    The book in the old formatting, v.1.0.1

    This is the previous version of the formatting (smaller text, 343 pages).

  • extras
    Functional Design and Architecture v.1.0.2f, e-pub2

    This is an export of e-pub v2 (Made as linux - chrome - docx - epub)

  • English

  • PDF

  • EPUB

$50.00
Minimum price
$60.00
Suggested price
E-Book + Paper book + 6 Educational Videos + Code Samples (plz, checkout book's description)

The bundle containing full set of materials for the book: * 6 private educational videos * 2 projects with code samples * Paper book (send me your PurchaseID & shipping address via email)

Includes:

  • extras
    The Hydra project

    The second showcase project for the book. Hydra is a full-fledged framework for building web services, multithreaded and concurrent applications with SQL and KV DB support. The code is available here: https://github.com/graninas/Hydra

  • extras
    The Andromeda project

    The first showcase project for the book. A SCADA software for spaceship control. The code is available here: https://github.com/graninas/Andromeda

  • extras
    The book in a bigger font formatting, v.0.9.5.75

    This is a PDF with the book with the increased font. V.0.9.5.75. It is experimental, and the code is not properly formatted here. There will be a better formatted version by the end of September.

  • extras
    Educational Video: FDaA screencasts (private links)

    This is the list of private videos accompanying the book.

  • extras
    The book in the old formatting, v.1.0.1

    This is the previous version of the formatting (smaller text, 343 pages).

  • extras
    Functional Design and Architecture v.1.0.2f, e-pub2

    This is an export of e-pub v2 (Made as linux - chrome - docx - epub)

  • English

  • PDF

  • EPUB

$80.00
Minimum price
$80.00
Suggested price

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

Authors have earned$9,708,273writing, 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

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. It really is that easy.

Learn more about writing on Leanpub