Representation of monadic effects in the non-monadic form

R.S. Shevchenko

Abstract


Modern programming relies heavily on effects systems. In the context of the development of programming languages, two approaches to understanding effects are distinguished: the first recognizes an effect as a characteristic of a program that affects the execution environment, separating it from a simple calculation (that is, effects are not taken into account in the system of language types, which is typical for imperative programming languages); the second considers an effect as an aspect of program interpretation that affects the process of its interpretation (such effects are considered in the type system as higher-order types, and this approach is characteristic of functional programming). In industrial programming, the first approach is preferred because of its efficiency in rapid development and less complex concepts. However, this leads to the loss of the possibility of automatic analysis of effects using type systems and increases the difficulty of finding errors. Monads are a convenient tool for describing effects because they have a built-in computation composition operation and can sink values into the monadic environment. A direct contextual representation of effects can be useful for application developers because it reduces cognitive load from syntactic noise while preserving information about effects in data types. This representation also allows for cross-platform applications that can use both monadic and non-monadic effect systems. The paper describes the ergonomic programming language interface for working with monadic effects, which encapsulates the logic of computation and associated non-computational operations in the effect system monad, and describes the direct context encoding technique. The translation of the direct context encoding into the monadic form is implemented in the form of a Scala compiler plugin, which is available as an open source. The use of conditional effects compilation to organize cross-platform interfaces that combine different methods of implementing effects on different platforms is also discussed.

Prombles in programming 2024; 2-3: 116-123

 


Keywords


effects; monads; Scala; programing language; program transformation

References


E. Moggi, Notions of computation and monads, in: Information and Computation, 93 1 (1991) 55–92. doi:10.1016/0890-5401(91)90052-4.

P. Wadler, Monads for Functional Programming, in: Advanced Functional Programming, First International Spring School on Advanced Functional Programming Techniques-Tutorial, Berlin, Heidelberg, Springer-Verlag, 1995, pp. 24–52.

P. Wadler, The essence of functional programming, in: Proceedings of the 19th ACM SIGPLAN-SIGACT symposium on Principles of programming languages (POPL’92), 1992, New York, ACM, pp. 1–14. https://doi.org/10.1145/143165.143169

S. Liang, P. Hudak, M. Jones, Monad transformers and modular interpreters, in: Proceedings of the 22nd ACM SIGPLAN-SIGACT symposium on Principles of programming languages (POPL’95), 1995, New York, ACM, pp. 333–343. https://doi.org/10.1145/199448.199528

T. Schrijvers, M. Piróg, N. Wu, M. Jaskelioff, Monad transformers and modular algebraic effects: what binds them together, in: Proceedings of the 12th ACM SIGPLAN International Symposium on Haskell (Haskell 2019),2019, New York, ACM, pp. 98–113. https://doi.org/10.1145/3331545.334259

O. Kiselyov, H. Ishii, Freer monads, more extensible effects. SIGPLAN Not. 50, 12 (2015) 94–105. https://doi.org/10.1145/2887747.2804319

eff: https://github.com/atnos-org/eff

kyo: https://github.com/getkyo/kyo

turbolift https://marcinzh.github.io/turbolift/

Carette, J., Kiselyov, O., Shan, C.-C., Finally tagless, partially evaluated: Tagless staged interpreters for simpler typed languages, in: Journal of Functional Programming, 19 5 (2009) 509–543. doi:10.1017/S0956796809007205.

P. Hudak, J. Hughes, S. P. Jones, P. Wadler, A history of Haskell: being lazy with class, in: Proceedings of the third ACM SIGPLAN conference on History of programming languages (HOPL III), New York, ACM, 2007, pp. 12–1 – 12–55. https://doi.org/10.1145/1238844.1238856

T. Petricek, D. Syme, The F# Computation Expression Zoo, in: Flatt, M., Guo, HF. (eds) Practical Aspects of Declarative Languages. PADL 2014. Lecture Notes in Computer Science, vol. 8324. Cham, Springer, 2014, https://doi.org/10.1007/978-3-319-04132-2_3

Scala 3 Language Reference. cited 08.04.2024 https://docs.scalalang.org/scala3/reference/

Idris Language Reference. https://docs.idrislang.org/en/latest/reference/index.html

C# Asyncronious Programming Scenarious. https://learn.microsoft.com/enus/dotnet/csharp/asynchronousprogramming/async-scenarios

R. Shevchenko, Project Paper: Embedding Generic Monadic Transformer into Scala, in: Lecture Notes in Computer Science, 3401 (2022). https://doi.org/10.1007/978-3-031-21314-4_1

dotty-cps-async. https://github.com/rssh/dotty-cps-async

R.S. Shevchenko, А.Yu. Doroshenko, O.A. Yatsenko. Embedding a family of logic languages with custom monadic unification in Scala, in: Problems in programming 1 (2024) 3–11.

A. Boruch-Gruszecki, M. Odersky, E. Lee, O. Lhoták, J. rachthäuser, Capturing Types, in: ACM Trans. Program. Lang. Syst. 45, 4, Article 21 (2023) pp. 1-52. https://doi.org/10.1145/3618003

Koltin coroutines guide. https://kotlinlang.org/docs/coroutinesguide.html

Gears. An Async library for Scala. https://github.com/lampepfl/gear


Refbacks

  • There are currently no refbacks.