Embedding a family of logic languages with custom monadic unification in Scala

R.S. Shevchenko, А.Yu. Doroshenko, O.A. Yatsenko


The paper proposes a framework for embedding logic programming and constraint programming methods in Scala by building a logical object-oriented language around the unification of typed logic based on monads. Two types of API are considered — high-level for language embeddings and low-level for organization of the bidirectional flow of data during the execution of logic programs. Differences in the capabilities of logical mechanisms can be expressed as subclasses of the class of unification monad types. This design makes it possible to share the implementation of custom unification between different frameworks and to use other languages’ embeddings in Scala from the declarative side. The monadic API provides the application developer with a simple and intuitive tool to implement custom logic within the unification. Our frameworks provide a clear representation of logical deduction: Scala code is only used for ad hoc unification. But the overall goal execution is an external interpretation that can implement different strategies. This design provides modularity and good integration with the rest of the ecosystem.

Prombles in programming 2024; 1: 3-11


declarative programming; embedding; logical programming; monad; object-oriented language; term; unification; Scala


The Flix Programming Language [Online]. Available from: https://flix.dev

Magnus, M., Starup, J.L. & Lhoták, O. (2022) Flix: a meta programming language for Datalog. Datalog. 4th International Workshop on the Resurgence of Datalog in Academia and Industry (Datalog 2.0 2022). p. 202-206. [Online]. Available from: https://ceur-ws.org/Vol-3203/short8.pdf

Logtalk [Online]. Available from: https://logtalk.org

Doroshenko, A. & Shevchenko, R. (2006) A rewriting framework for rule-based programming dynamic applications. Fundamenta Informaticae. 72 (1-3). p. 95-108.

Mamedov, T.A., Doroshenko, А.Yu. & Shevchenko, R.S. (2020) Static analysis of .NET programs using rewriting rules. Problems in programming. (2–3). p. 157-163. (in Ukrainian)

Ciatto, G., Calegari, R. & Omicini, A. (2021) 2P-Kt: a logic-based ecosystem for symbolic AI. SoftwareX. 16, 100817. p. 1-7. [Online]. Available from: https://doi.org/10.1016/ j.softx.2021.100817

Sahebolamri, A. et al. (2023) Bring your own data structures to Datalog. Proceedings of the ACM on Programming Languages. 7 (OOPSLA2), Article 264. p. 1198-1223. [Online]. Available from: https://doi.org/10.1145/3622840

Sterling, L. & Shapiro, E. (1994) The art of Prolog advanced programming techniques. 2nd ed. Cambridge, MA, USA: MIT Press.

Pfenning, F. & Elliott, C. (1988) Higher-order abstract syntax. ACM SIGPLAN 1988 conference on Programming language design and implementation (PLDI’88). ACM SIGPLAN Notices. 23 (7). p. 199-208. [Online]. Available from: https://doi.org/ 10.1145/960116.54010

Shevchenko, R. (2022) Project paper: Embedding generic monadic transformer into Scala. In Swierstra, W., Wu, N. (eds.) Trends in Functional Programming. TFP 2022. Lecture Notes in Computer Science. 13401. p. 1-17. Cham: Springer. [Online]. Available from: https://doi.org/10.1007/978-3-031-21314-4_1

LogKit [Online]. Available from: https://github.com/logkit/logkit

Kiselyov, O. at el. (2005) Backtracking, interleaving, and terminating monad transformers (functional pearl). 10th ACM SIGPLAN international conference on Functional programming (ICFP’05). New York: ACM. p. 192-203. [Online]. Available from: https://doi.org/10.1145/1086365. 1086390

Körner, P. et al. (2022) Fifty years of Prolog and beyond. Theory and Practice of Logic Programming. 22 (6). p. 776-858. [Online]. Available from: https://doi.org/10.48550/ arXiv.2201.10816

Amin, N., Byrd, W.E. & Rompf, T. (2019) Lightweight functional logic meta-programming. In Lin, A. (eds.) Programming Languages and Systems. APLAS 2019. Lecture Notes in Computer Science. 11893. Cham: Springer. [Online]. Available from: https://doi.org/10.1007/978-3-030-34175-6_12

Baumgartner, P. (2021) The Fusemate logic programming system. 28th International Conference on Automated Deduction (Automated Deduction – CADE 28). Berlin: Springer. p. 589-601. [Online]. Available from: https://doi.org/10.1007/978-3-030-79876-5_34


  • There are currently no refbacks.