skip to main content
10.1145/3551357.3551370acmotherconferencesArticle/Chapter ViewAbstractPublication PagesppdpConference Proceedingsconference-collections
research-article

A Monadic Implementation of Functional Logic Programs

Published:20 September 2022Publication History

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.

References

  1. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  2. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  3. 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 ScholarGoogle Scholar
  4. 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 ScholarGoogle ScholarCross RefCross Ref
  5. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  6. 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 ScholarGoogle ScholarCross RefCross Ref
  7. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  8. 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 ScholarGoogle Scholar
  9. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  10. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  11. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  12. S. Antoy and M. Hanus. 2010. Functional Logic Programming. Commun. ACM 53, 4 (2010), 74–85. https://doi.org/10.1145/1721654.1721675Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  14. 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 ScholarGoogle Scholar
  15. F. Baader and T. Nipkow. 1998. Term Rewriting and All That. Cambridge University Press, Cambridge, UK. https://doi.org/10.1017/CBO9781139172752Google ScholarGoogle Scholar
  16. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  17. 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 ScholarGoogle ScholarCross RefCross Ref
  18. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  19. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  20. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  21. 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 ScholarGoogle ScholarCross RefCross Ref
  22. 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 ScholarGoogle Scholar
  23. 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 ScholarGoogle Scholar
  24. 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 ScholarGoogle Scholar
  25. 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 ScholarGoogle Scholar
  26. 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 ScholarGoogle Scholar
  27. M. Hanus (ed.). 2016. Curry: An Integrated Functional Logic Language (Vers. 0.9.0). Available at http://www.curry-lang.org.Google ScholarGoogle Scholar
  28. 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 ScholarGoogle Scholar
  29. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  30. 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 ScholarGoogle Scholar
  31. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  32. J.W. Lloyd. 1987. Foundations of Logic Programming. Springer, second, extended edition, Berlin, Heidelberg. https://doi.org/10.1007/978-3-642-96826-6Google ScholarGoogle Scholar
  33. 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 ScholarGoogle Scholar
  34. Nigel Perry. 2005. The Implementation of Practical Functional Programming Languages. Ph.D. Dissertation. University of London.Google ScholarGoogle Scholar
  35. 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 ScholarGoogle ScholarCross RefCross Ref
  36. S. Peyton Jones (Ed.). 2003. Haskell 98 Language and Libraries—The Revised Report. Cambridge University Press, Cambridge, UK.Google ScholarGoogle Scholar
  37. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  38. 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 ScholarGoogle Scholar
  39. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  40. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  41. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  42. 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 ScholarGoogle ScholarCross RefCross Ref
  43. 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 ScholarGoogle ScholarDigital LibraryDigital Library
  44. P. Wadler. 1997. How to Declare an Imperative. Comput. Surveys 29, 3 (1997), 240–263. https://doi.org/10.1145/262009.262011Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. A Monadic Implementation of Functional Logic Programs

          Recommendations

          Comments

          Login options

          Check if you have access through your login credentials or your institution to get full access on this article.

          Sign in
          • Published in

            cover image ACM Other conferences
            PPDP '22: Proceedings of the 24th International Symposium on Principles and Practice of Declarative Programming
            September 2022
            187 pages
            ISBN:9781450397032
            DOI:10.1145/3551357

            Copyright © 2022 ACM

            Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

            Publisher

            Association for Computing Machinery

            New York, NY, United States

            Publication History

            • Published: 20 September 2022

            Permissions

            Request permissions about this article.

            Request Permissions

            Check for updates

            Qualifiers

            • research-article
            • Research
            • Refereed limited

            Acceptance Rates

            Overall Acceptance Rate230of486submissions,47%

          PDF Format

          View or Download as a PDF file.

          PDF

          eReader

          View online with eReader.

          eReader

          HTML Format

          View this article in HTML Format .

          View HTML Format