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 to 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 efforts. 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. We demonstrate that our approach yields a promising performance that outperforms current compilers for Curry.
- Andreas Abel, Marcin Benke, Ana Bove, John Hughes, and Ulf Norell. 2005. Verifying Haskell Programs Using Constructive Type Theory. In Proceedings of the 2005 ACM SIGPLAN Workshop on Haskell. ACM Press, New York, NY, USA, 62–73. https://doi.org/10.1145/1088348.1088355Google ScholarDigital Library
- E. Albert, M. Hanus, F. Huch, J. Oliver, and G. Vidal. 2005. Operational Semantics for Declarative Multi-Paradigm Languages. Journal of Symbolic Computation 40, 1 (2005), 795–829. https://doi.org/10.1016/j.jsc.2004.01.001Google ScholarDigital Library
- A. Alqaddoumi, S. Antoy, S. Fischer, and F. Reck. 2010. The Pull-Tab Transformation. In Proc. of the Third International Workshop on Graph Computation Models. Published Online, Enschede, The Netherlands, 127–132. Available at http://gcm2010.imag.fr/pages/gcm2010-preproceedings.pdf.Google Scholar
- S. Antoy. 1997. Optimal Non-Deterministic Functional Logic Computations. In Proc. International Conference on Algebraic and Logic Programming (ALP’97). Springer LNCS 1298, Berlin, Heidelberg, 16–30. https://doi.org/10.1007/BFb0027000Google ScholarCross Ref
- S. Antoy. 2001. Constructor-based Conditional Narrowing. In Proc. of the 3rd International ACM SIGPLAN Conference on Principles and Practice of Declarative Programming (PPDP 2001). ACM Press, New York, NY, USA, 199–206.Google ScholarDigital Library
- S. Antoy. 2011. On the Correctness of Pull-Tabbing. Theory and Practice of Logic Programming 11, 4-5 (2011), 713–730. https://doi.org/10.1017/S1471068411000263Google ScholarCross Ref
- S. Antoy, R. Echahed, and M. Hanus. 2000. A Needed Narrowing Strategy. J. ACM 47, 4 (2000), 776–822. https://doi.org/10.1145/347476.347484Google ScholarDigital Library
- S. Antoy and M. Hanus. 2000. Compiling Multi-Paradigm Declarative Programs into Prolog. In Proc. International Workshop on Frontiers of Combining Systems (FroCoS’2000). Springer LNCS 1794, Berlin, Heidelberg, 171–185. https://doi.org/10.1007/10720084_12Google Scholar
- S. Antoy and M. Hanus. 2005. Declarative Programming with Function Patterns. In Proceedings of the International Symposium on Logic-based Program Synthesis and Transformation (LOPSTR’05). Springer LNCS 3901, Berlin, Heidelberg, 6–22. https://doi.org/10.1007/11680093_2Google ScholarDigital Library
- S. Antoy and M. Hanus. 2006. Overlapping Rules and Logic Variables in Functional Logic Programs. In Proceedings of the 22nd International Conference on Logic Programming (ICLP 2006). Springer LNCS 4079, Berlin, Heidelberg, 87–101. https://doi.org/10.1007/11799573_9Google ScholarDigital Library
- S. Antoy and M. Hanus. 2009. Set Functions for Functional Logic Programming. In Proceedings of the 11th ACM SIGPLAN International Conference on Principles and Practice of Declarative Programming (PPDP’09). ACM Press, New York, NY, USA, 73–82. https://doi.org/10.1145/1599410.1599420Google ScholarDigital Library
- S. Antoy and M. Hanus. 2010. Functional Logic Programming. Commun. ACM 53, 4 (2010), 74–85. https://doi.org/10.1145/1721654.1721675Google ScholarDigital Library
- S. Antoy, M. Hanus, A. Jost, and S. Libby. 2020. ICurry. In Declarative Programming and Knowledge Management - Conference on Declarative Programming (DECLARE 2019). Springer LNCS 12057, Berlin, Heidelberg, 286–307. https://doi.org/10.1007/978-3-030-46714-2_18Google ScholarDigital Library
- S. Antoy and A. Jost. 2016. A New Functional-Logic Compiler for Curry: Sprite. In Proceedings of the 26th International Symposium on Logic-Based Program Synthesis and Transformation (LOPSTR 2016). Springer LNCS 10184, Berlin, Heidelberg, 97–113. https://doi.org/10.1007/978-3-319-63139-4_6Google Scholar
- F. Baader and T. Nipkow. 1998. Term Rewriting and All That. Cambridge University Press, Cambridge, UK. https://doi.org/10.1017/CBO9781139172752Google Scholar
- J. Böhm, M. Hanus, and F. Teegen. 2021. From Non-determinism to Goroutines: A Fair Implementation of Curry in Go. In Proc. of the 23rd International Symposium on Principles and Practice of Declarative Programming (PPDP 2021). ACM Press, New York, NY, USA, 16:1–16:15. https://doi.org/10.1145/3479394.3479411Google ScholarDigital Library
- B. Braßel, M. Hanus, B. Peemöller, and F. Reck. 2011. KiCS2: A New Compiler from Curry to Haskell. In Proc. of the 20th International Workshop on Functional and (Constraint) Logic Programming (WFLP 2011). Springer LNCS 6816, Berlin, Heidelberg, 1–18. https://doi.org/10.1007/978-3-642-22531-4_1Google ScholarCross Ref
- B. Braßel and F. Huch. 2007. On a Tighter Integration of Functional and Logic Programming. In Proc. APLAS 2007. Springer LNCS 4807, Berlin, Heidelberg, 122–138. https://doi.org/10.1007/978-3-540-76637-7_9Google ScholarDigital Library
- J. Christiansen, M. Hanus, F. Reck, and D. Seidel. 2013. A Semantics for Weakly Encapsulated Search in Functional Logic Programs. In Proc. of the 15th International Symposium on Principle and Practice of Declarative Programming (PPDP’13). ACM Press, New York, NY, USA, 49–60. https://doi.org/10.1145/2505879.2505896Google ScholarDigital Library
- S. Fischer, O. Kiselyov, and C. Shan. 2011. Purely functional lazy nondeterministic programming. Journal of Functional programming 21, 4&5 (2011), 413–465. https://doi.org/10.1017/S0956796811000189Google ScholarDigital Library
- J.C. González-Moreno, M.T. Hortalá-González, F.J. López-Fraguas, and M. Rodríguez-Artalejo. 1999. An approach to declarative programming based on a rewriting logic. Journal of Logic Programming 40 (1999), 47–87. https://doi.org/10.1016/s0743-1066(98)10029-8Google ScholarCross Ref
- M. Hanus. 2012. Improving Lazy Non-Deterministic Computations by Demand Analysis. In Technical Communications of the 28th International Conference on Logic Programming, Vol. 17. Leibniz International Proceedings in Informatics (LIPIcs), Dagstuhl, Germany, 130–143. https://doi.org/10.4230/LIPIcs.ICLP.2012.130Google Scholar
- M. Hanus. 2013. Functional Logic Programming: From Theory to Curry. In Programming Logics - Essays in Memory of Harald Ganzinger. Springer LNCS 7797, Berlin, Heidelberg, 123–168. https://doi.org/10.1007/978-3-642-37651-1_6Google Scholar
- M. Hanus, S. Antoy, B. Braßel, M. Engelke, K. Höppner, J. Koj, P. Niederau, R. Sadre, F. Steiner, and F. Teegen. 2021. PAKCS: The Portland Aachen Kiel Curry System. Available at http://www.informatik.uni-kiel.de/~pakcs/.Google Scholar
- M. Hanus, B. Peemöller, and F. Reck. 2012. Search Strategies for Functional Logic Programming. In Proc. of the 5th Working Conference on Programming Languages (ATPS’12). Springer LNI 199, Bonn, 61–74. https://doi.org/20.500.12116/18376Google Scholar
- M. Hanus and F. Teegen. 2021. Memoized Pull-Tabbing for Functional Logic Programming. In Proc. of the 28th International Workshop on Functional and (Constraint) Logic Programming (WFLP 2020). Springer LNCS 12560, Berlin, Heidelberg, 57–73. https://doi.org/10.1007/978-3-030-75333-7_4Google Scholar
- M. Hanus (ed.). 2016. Curry: An Integrated Functional Logic Language (Vers. 0.9.0). Available at http://www.curry-lang.org.Google Scholar
- G. Huet and J.-J. Lévy. 1991. Computations in Orthogonal Rewriting Systems. In Computational Logic: Essays in Honor of Alan Robinson, J.-L. Lassez and G. Plotkin (Eds.). MIT Press, Cambridge, Massachusetts, 395–443.Google Scholar
- H. Hussmann. 1992. Nondeterministic Algebraic Specifications and Nonconfluent Term Rewriting. Journal of Logic Programming 12 (1992), 237–255. https://doi.org/10.1016/0743-1066(92)90026-YGoogle ScholarDigital Library
- T. Johnsson. 1985. Lambda Lifting: Transforming Programs to Recursive Functions. In Functional Programming Languages and Computer Architecture. Springer LNCS 201, Berlin, Heidelberg, 190–203. https://doi.org/10.1007/3-540-15975-4_37Google Scholar
- Georgios Karachalias, Filip Koprivec, Matija Pretnar, and Tom Schrijvers. 2021. Efficient Compilation of Algebraic Effect Handlers. Proc. ACM Program. Lang. 5, OOPSLA (Oct. 2021), 28 pages. https://doi.org/10.1145/3485479Google ScholarDigital Library
- J.W. Lloyd. 1987. Foundations of Logic Programming. Springer, second, extended edition, Berlin, Heidelberg. https://doi.org/10.1007/978-3-642-96826-6Google Scholar
- F. López-Fraguas and J. Sánchez-Hernández. 1999. TOY: A Multiparadigm Declarative System. In Proc. of RTA’99. Springer LNCS 1631, Berlin, Heidelberg, 244–247. https://doi.org/10.1007/3-540-48685-2_19Google Scholar
- Nigel Perry. 2005. The Implementation of Practical Functional Programming Languages. Ph.D. Dissertation. University of London.Google Scholar
- Tomas Petricek. 2012. Evaluation Strategies for Monadic Computations. Electronic Proceedings in Theoretical Computer Science 76 (2012), 68–89. https://doi.org/10.4204/EPTCS.76.7Google ScholarCross Ref
- S. Peyton Jones (Ed.). 2003. Haskell 98 Language and Libraries—The Revised Report. Cambridge University Press, Cambridge, UK.Google Scholar
- Simon Peyton Jones, Mark Shields, John Launchbury, and Andrew Tolmach. 1998. Bridging the Gulf: A Common Intermediate Language for ML and Haskell. In Proceedings of the 25th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages(POPL ’98). Association for Computing Machinery, New York, NY, USA, 49–61. https://doi.org/10.1145/268946.268951Google ScholarDigital Library
- U.S. Reddy. 1985. Narrowing as the Operational Semantics of Functional Languages. In Proc. IEEE International Symposium on Logic Programming. IEEE Computer Society, Boston, 138–151.Google Scholar
- J.A. Robinson. 1965. A Machine-Oriented Logic Based on the Resolution Principle. J. ACM 12, 1 (1965), 23–41. https://doi.org/10.1145/321250.321253Google ScholarDigital Library
- J.R. Slagle. 1974. Automated Theorem-Proving for Theories with Simplifiers, Commutativity, and Associativity. J. ACM 21, 4 (1974), 622–642. https://doi.org/10.1145/321850.321859Google ScholarDigital Library
- Finn Teegen, Kai-Oliver Prott, and Niels Bunkenburg. 2021. Haskell− 1: Automatic Function Inversion in Haskell. In Proceedings of the 14th ACM SIGPLAN International Symposium on Haskell(Haskell 2021). Association for Computing Machinery, New York, NY, USA, 41–55. https://doi.org/10.1145/3471874.3472982Google ScholarDigital Library
- P. Wadler. 1985. How to Replace Failure by a List of Successes: A method for exception handling, backtracking, and pattern matching in lazy functional languages. In Conference on Functional Programming and Computer Architecture (FPCA’85). Springer LNCS 201, Berlin, Heidelberg, 113–128. https://doi.org/10.1007/3-540-15975-4_33Google ScholarCross Ref
- P. Wadler. 1990. Comprehending Monads. In Proc. 1990 ACM Conference on LISP and Functional Programming. ACM, New York, NY, USA, 61–78. https://doi.org/10.1145/91556.91592Google ScholarDigital Library
- P. Wadler. 1997. How to Declare an Imperative. Comput. Surveys 29, 3 (1997), 240–263. https://doi.org/10.1145/262009.262011Google ScholarDigital Library
Index Terms
- A Monadic Implementation of Functional Logic Programs
Recommendations
Uniform proofs and disjunctive logic programming
LICS '95: Proceedings of the 10th Annual IEEE Symposium on Logic in Computer ScienceOne formulation of the concept of logic programming is the notion of an abstract logic programming language. Central to its definition is a uniform proof, which enforces the requirements of inference direction, including goal-directedness, and the ...
Correctness and Completeness of Logic Programs
We discuss proving correctness and completeness of definite clause logic programs. We propose a method for proving completeness, while for proving correctness we employ a method that should be well known but is often neglected. Also, we show how to ...
A semantics for weakly encapsulated search in functional logic programs
PPDP '13: Proceedings of the 15th Symposium on Principles and Practice of Declarative ProgrammingEncapsulated search is a key feature of (functional) logic languages. It allows the programmer to access and process different results of a non-deterministic computation within a program. Unfortunately, due to advanced operational features (lazy ...
Comments