, 29 tweets, 11 min read Read on Twitter
I’m pretty sure there is a big demand for materials about high level architecture and design of big applications in pure FP (Scala, Haskell). This is what I'm actually doing for a long time.

Let me describe the materials I have to the present moment (ongoing thread).

1/
1) Functional Design and Architecture book

In this book, I develop a complete set of tools and approaches for building complex applications in a pure functional language (Haskell).

I’m working on the book currently. 5 chapters are available already:
graninas.com/functional-des…

2/
It tells how to make a finely structured, layered applications composed of subsystems and services, with database support, multithreading, safe concurrency. The code should satisfy requirements: testability, maintainability, simplicity, should be easy to understand.

3/
I show the approaches how to divide an application into layers: business logic, persistence, state, services, runtime. It's all about building eDSLs, and Free monads play the main role in separation of interfaces and implementation.

4/
The book describes several useful design patterns and principles as well: Inversion of Control, SOLID, low coupling, functional interfaces etc. - all this is aimed to achieve the main goal: low accidental complexity of the big codebase and good separation of concerns.

5/
The book is project-based. Initially it was a SCADA application named “Andromeda”, later I decided to write another app “Hydra”. Both are on my GitHub:

github.com/graninas/Andro…
github.com/graninas/Hydra

There are also samples from chapters here:
github.com/graninas/Funct…

6/
Please consider to support the book! I’ll be very thankful for any your help!

Patreon program:
patreon.com/functional_des…

Paypal donations:
paypal.me/graninas

Comments, retweets and advertising will work too!

7/
2) Node Framework

github.com/graninas/Node

This is a comprehensive framework in Haskell to build complex, distributed, multithreaded apps. It has a lot of features out of the box: logging, KV DB, config management, safe concurrent state, networking (TCP/UDP) and more.

8/
Initially, it was designed to create blockchain nodes at Enecuum, but it’s not limited by this domain. For example, you can easily create a TCP/UDP/JSON-RPC server and client apps on it. The framework provides several eDSLs having a good design so the code will be simple.

9/
In fact, the framework is completely based on the ideas I’m describing in my book. It has a Free monad languages layer which abstracts all the underlying implementation and its complexity.

10/
The application built with the framework will look like a set of monadic scripts representing a business logic. The design of the languages eliminates many problems related to hardness of multithreaded and concurrent programming. Concurrent state is STM-based.

11/
Framework has configs management. It’s possible to create several apps having a shared codebase but with different configs. Running a particular app will be like passing the corresponding config to the executable.

12/
Framework allows to work with state. Every app can have own STM-based state. Or it can be a KV database. Also, logging is fully supported and can be configured with configs.

Another nice feature is CLI. The app can interact with console if you need.

13/
The framework also provides testing facilities. You can use it to do integration and functional testing of your application, including its multithreaded behavior.

The framework also contains sample nodes having a non-trivial logic.
github.com/graninas/Node/…

14/
The framework has other interesting features. It also demonstrates how to build complex apps in Haskell.

You’ll find more info about the framework in this tutorial:

“Building network actors with Node Framework”
gist.github.com/graninas/9beb8…

15/
3) Custom STM on Free Monads

In 2018, I created my own monadic STM in Haskell and C++ exclusively for the C++ Russia 2018 conference. It was a very difficult challenge: concurrency, FP in C++, lack of monads... I felt I could use Free Monads to achieve my goals.

16/
So I succeeded and now we have two libraries demonstrating several interesting ideas of design using Free Monads.

C++ library cpp_stm_free: github.com/graninas/cpp_s…
Haskell library stm_free: github.com/graninas/stm-f…

17/
In fact, C++ library has two engines based on Free Monad and Church Encoded Free Monad. The second is way faster but the implementation code is also much more difficult. Still, the usage is simple and very similar to Haskell native STM.

18/
I wrote several articles about the work.

Article (Rus, Haskell version): “STM на Free-монадах”:
habr.com/ru/post/350628/

Tutorial (Eng, C++ version): “STM in C++: Pure Functional Approach”:
gist.github.com/graninas/c7e0a…

19/
I gave two talks on it.

Talk (Rus, C++ Russia 2018): “Функциональный подход к STM”


Slides (Eng):
slideshare.net/alexandrgranin…

Talk (Rus, LambdaNsk): “ФП в С++ и конкурентные вычисления”


Slides (Eng):
slideshare.net/alexandrgranin…

20/
There is a separate project with the “Dining Philosophers” problem solved with my cpp_stm_free library:
github.com/graninas/cpp_p…

The same task is solved on Haskell version:
github.com/graninas/stm-f…

21/
In my long time researching of FP in C++ I created other materials, talks, articles. I’ll tell you about the results in this thread.

I composed a list of resources about FP in C++:
github.com/graninas/cpp_f…

It’s not a secret that C++ is moving to the brave FP world nowadays.

22/
4) hinteractive - an interaction fiction game like Zork.

I wanted to research how Free Monads can help with eDSL creation. What syntax and semantics it’s possible to express? Also I wanted to do something entertaining. And I created this project.

github.com/graninas/hinte…

23/
I needed a convenient mechanism for game locations. For this purpose I created “transition-graph”. With it, you describe nodes and transitions between them. Different transitions are supported: by event, by condition, unconditionally etc.

github.com/graninas/trans…

24/
The graph is parametrized by an external language providing transition events. The graph tracks all the transitions made, and it’s possible to return back.

Initially the graph was invented for mobile UI transitions with the “Back” button for a private project I worked on.

25/
The most interesting part in “hinteractive” was designing game mechanics. It’s not complete for now and there are unclear parts but I wanted to make the code (locations, objects, interactions) look good and near to its semantics.

26/
It’s Free Monad based. You can learn how to introspect values and do a “dynamic pattern-match” with it (select a transition depending on the game situation). You can even compose transitions on the fly. The code is also feel like reactive programming.

27/
I’ve recorded two screencasts (Rus) in which I’m working on the code and explaining different things.

1:
2:

This project is open for contributions. There are tasks for beginners and advanced haskellers, so welcome!

28/
I also gave a talk about "hinteractive" for @fprog_spb.

Talk (Rus): “eDSL for transition graph using Free monads and existential types”:


Slides (Eng):
slideshare.net/alexandrgranin…

This was entertaining and enlightening indeed.

29/
Missing some Tweet in this thread?
You can try to force a refresh.

Like this thread? Get email updates or save it to PDF!

Subscribe to Alexander Granin
Profile picture

Get real-time email alerts when new unrolls are available from this author!

This content may be removed anytime!

Twitter may remove this content at anytime, convert it as a PDF, save and print for later use!

Try unrolling a thread yourself!

how to unroll video

1) Follow Thread Reader App on Twitter so you can easily mention us!

2) Go to a Twitter thread (series of Tweets by the same owner) and mention us with a keyword "unroll" @threadreaderapp unroll

You can practice here first or read more on our help page!

Follow Us on Twitter!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just three indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3.00/month or $30.00/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!