Automatic assembling of effect monad
Ivan Kyrylov, Ruslan ShevchenkoIntroduction
The monadic effect system is an approach to build programs inside some monadic structure, consisting of individual effects. Instead of creating different effects in different monads, monadic effect systems provide a way to create different effects inside one structured monad. Effects can be stacked with each other. The execution of the composite effect is performed using effect handlers.
The use of effect systems can sometimes be a complicated and unnecessary approach, because for many cases exist more simple ways of code organization, which does not affect the complexity of the code. Historically, effect systems were developed as alternatives to chains of monad transformers which become less manageable when the number of different monads increases and you need to somehow aggregate it all..
The initial goal of this project was initially to write a macro on top of dotty-cps-async, which allows developers to use effect system monads within direct style.. In the end, we came to a different view of this problem, namely, we created a uniform interface for different effect systems for client programs written in final tagless style. This allowed us to have the same interface for effect systems and still write in In direct style using dotty-cps-async. This simplifies the readability of the code and allows you not to go into the details of how certain effect systems work.
Work results
At this point, It is possible to write programs using effects in a direct style. Also, we can abstract out from the technical details of each effect system and use EffectSystem typeclass. Here is an example of a program, use generic effect notation.

This program can be interpreted by different effect systems.

Completed Goals
Understood How Macros Work in Scala 3: Gained a deep understanding of macro functionalities, limitations, and applications in Scala 3.
Practiced Writing Various Macros: Enhanced skills through practical exercises in writing macros for different tasks.
Analyzed Different Effect Systems: Studied various effect systems, understanding their common features and how they differ from each other.
Reviewed and Practiced Direct Style Coding and Effect Handling: Evaluated straightforward coding styles and their effect management, improving understanding and practice in this area.
Implemented CpsMonad for Various Effect Systems: Implemented CpsMonad for different effect systems to ensure broad usability.
Conducted Extensive Testing on Various Cases and Effects: Tested the implementation across different scenarios to ensure robustness and correct functionality.
Wrote Comprehensive Tests to Cover Basic and Advanced Usage: Ensured high standards of code reliability and correctness by covering various usage scenarios through testing.
Leftovers
Expand and Enhance Documentation: The documentation should contain technical details, usage examples, and guidelines for both the authors of effect systems who plan to integrate their effect systems into dotty-cps-async and those who will use these effect systems. For those who will use them, there should also be information on how to describe the code using the concept of final tagless coding, since the uniform interface for effect systems is based on it.
Write Technical Reports for Educational Purposes: Apart from the regular documentation, preparing detailed technical reports that can be used for educational purposes would be beneficial. These reports should delve into the theoretical aspects, practical implementations, and lessons learned throughout the development process.
Future Direction
It is planned to generalize the effect of the system and with the help of erased types add more effect systems to make these abstractions zero-cost, which will allow using dotty-cps-async without loss in performance.
Implementation of standard CpsMonadConversions for using monads from Scala core within the dotty-cps-async reify method. Add for such types as Option, List, Either, Try, etc. This will reduce the potential amount of boilerplate code.
Contributes
static-injection – implementation of two types of injections: plain and async, using macros with the corresponding tests.
cps-async-effects – implementation of examples of the same program was done to show that we use different kinds of effects when writing programs, examples were implemented both without using effects and with the use of effect systems to demonstrate the simplification of stack effects. We also implemented a core for integrating effect systems into dotty-cps-async: interfaces, abstractions, and described concepts. Integration with such effect systems as Eff and Turbolift was implemented and tested: a CpsMonad implementation and a framework for the most common effects in effect systems.