Hostname: page-component-76d6cb85b7-6jg5l Total loading time: 0 Render date: 2026-07-16T16:31:50.651Z Has data issue: false hasContentIssue false

A Monadic Implementation of Functional Logic Programs

Published online by Cambridge University Press:  25 June 2026

MICHAEL HANUS
Affiliation:
Department of Computer Science, Kiel University, Germany (e-mails: mh@informatik.uni-kiel.de, kpr@informatik.uni-kiel.de, fte@informatik.uni-kiel.de)
KAI-OLIVER PROTT
Affiliation:
Department of Computer Science, Kiel University, Germany (e-mails: mh@informatik.uni-kiel.de, kpr@informatik.uni-kiel.de, fte@informatik.uni-kiel.de)
FINN TEEGEN
Affiliation:
Department of Computer Science, Kiel University, Germany (e-mails: mh@informatik.uni-kiel.de, kpr@informatik.uni-kiel.de, fte@informatik.uni-kiel.de)
Rights & Permissions [Opens in a new window]

Abstract

Functional logic languages are a high-level approach to programming by combining the most important declarative features. They abstract from small-step operational details so that programmers can concentrate on the logical aspects of an application. This is supported by appropriate evaluation strategies. Demand-driven evaluation from functional programming is amalgamated with non-determinism from logic programming so that solutions or values are computed whenever they exist. This frees the programmer from considering the influence of an operational strategy on the success of a computation, but it is a challenge to the language implementer. A non-deterministic demand-driven strategy might duplicate unevaluated choices of an expression, which could duplicate the computational effort. In recent implementations, this problem has been tackled by adding a kind of memoization of non-deterministic choices to the expression under evaluation. Since this has been implemented in imperative target languages, it was unclear whether this could also be supported in a functional programming environment like Haskell. This paper presents a solution to this challenge by transforming functional logic programs into a monadic representation. Although this transformation is not new, we present an implementation of the monadic interface which supports memoization in non-deterministic branches. Additionally, we include more advanced features of functional logic languages, namely functional patterns and encapsulated search, in our approach. By optimizing our implementation for purely functional computations with both a static and dynamic approach, we are able to achieve a promising performance that outperforms current compilers for Curry.

Information

Type
Rapid Communication
Creative Commons
Creative Common License - CCCreative Common License - BY
This is an Open Access article, distributed under the terms of the Creative Commons Attribution licence (https://creativecommons.org/licenses/by/4.0/), which permits unrestricted re-use, distribution and reproduction, provided the original article is properly cited.
Copyright
© The Author(s), 2026. Published by Cambridge University Press
Figure 0

Fig. 1. Type transformation [[∘]]t$[\![ \circ ]\!]^t$.

Figure 1

Fig. 2. Data type transformation [[∘]]d$[\![ \circ ]\!]^d$.

Figure 2

Fig. 3. Expression transformation [[∘]]e$[\![ \circ ]\!]^e$ (where f$f$, y$y$, y1,…,yn$y_1,\ldots ,y_n$ are fresh variables).

Figure 3

Fig. 4. Improved alias$alias$ rule.

Figure 4

Fig. 5. Revised data type transformation [[∘]]d$[\![ \circ ]\!]^d$.

Figure 5

Fig. 6. Revised transformation rule for branches of case expressions [[∘]]b$[\![ \circ ]\!]^b$.

Figure 6

Fig. 7. Timings (in seconds) of various programs evaluated with different compilers, green marks best time.