Hostname: page-component-586b7cd67f-dsjbd Total loading time: 0 Render date: 2024-11-24T08:21:56.273Z Has data issue: false hasContentIssue false

Singular and plural functions for functional logic programming

Published online by Cambridge University Press:  17 May 2012

ADRIÁN RIESCO
Affiliation:
Dpto. Sistemas Informáticos y Computación, Facultad de Informática Universidad Complutense de Madrid, Ciudad Universitaria–28040 Madrid (e-mail: [email protected], [email protected])
JUAN RODRÍGUEZ-HORTALÁ
Affiliation:
Dpto. Sistemas Informáticos y Computación, Facultad de Informática Universidad Complutense de Madrid, Ciudad Universitaria–28040 Madrid (e-mail: [email protected], [email protected])

Abstract

Modern functional logic programming (FLP) languages use non-terminating and non-confluent constructor systems (CSs) as programs in order to define non-strict and non-deterministic functions. Two semantic alternatives have been usually considered for parameter passing with this kind of functions: call-time choice and run-time choice. While the former is the standard choice of modern FLP languages, the latter lacks some basic properties – mainly compositionality – that have prevented its use in practical FLP systems. Traditionally it has been considered that call-time choice induces a singular denotational semantics, while run-time choice induces a plural semantics. We have discovered that this latter identification is wrong when pattern matching is involved, and thus in this paper we propose two novel compositional plural semantics for CSs that are different from run-time choice.

We investigate the basic properties of our plural semantics – compositionality, polarity, and monotonicity for substitutions, and a restricted form of the bubbling property for CSs – and the relation between them and to previous proposals, concluding that these semantics form a hierarchy in the sense of set inclusion of the set of values computed by them. Besides, we have identified a class of programs characterized by a simple syntactic criterion for which the proposed plural semantics behave the same, and a program transformation that can be used to simulate one of the proposed plural semantics by term rewriting. At the practical level, we study how to use the new expressive capabilities of these semantics for improving the declarative flavor of programs. As call-time choice is the standard semantics for FLP, it still remains the best option for many common programming patterns. Therefore, we propose a language that combines call-time choice and our plural semantics, which we have implemented in the Maude system. The resulting interpreter is then employed to develop and test several significant examples showing the capabilities of the combined semantics.

Type
Regular Papers
Copyright
Copyright © Cambridge University Press 2012 

Access options

Get access to the full version of this content by using one of the access options below. (Log in options will check for institutional or personal access. Content may require purchase if you do not have access.)

References

Albert, E., Hanus, M., Huch, F., Oliver, J. and Vidal, G. 2005. Operational semantics for declarative multi-paradigm languages. Journal of Symbolic Computation 40, 1, 795829.Google Scholar
Antoy, S., Brown, D. and Chiang, S. 2007. Lazy context cloning for non-deterministic graph rewriting. Proceedings of the Termgraph'06. Electronic Notes in Theoretical Computer Science – ENTCS, 176, 1, 6170.Google Scholar
Antoy, S. and Hanus, M. 2002. Functional logic design patterns. In FLOPS, Hu, Z. and Rodríguez-Artalejo, M., Eds. Lecture Notes in Computer Science, vol. 2441. Springer, New York, USA, 6787.Google Scholar
Antoy, S. and Hanus, M. 2010. Functional logic programming. Communications of ACM 53, 4, 7485.Google Scholar
Antoy, S., Iranzo, P. J. and Massey, B. 2002. Improving the efficiency of non-deterministic computations. Electronic Notes in Theoretical Computer Science, 64 7394.CrossRefGoogle Scholar
Ariola, Z. M., Felleisen, M., Maraist, J., Odersky, M. and Wadler, P. 1995. The call-by-need lambda calculus. In Proceedings of 22nd Annual ACM SIGACT-SIGPLAN Symposium on Principles of Programming Languages, POPL 1995. ACM, 233246.Google Scholar
Baader, F. and Nipkow, T. 1998. Term Rewriting and All That. Cambridge University Press,Cambridge, UK.Google Scholar
Borovanský, P., Kirchner, C., Kirchner, H., Moreau, P.-E. and Ringeissen, C. 1998. An overview of ELAN. In Proceedings of the Second International Workshop on Rewriting Logic and Its Applications, WRLA'98, Pont-à-Mousson, France, September 1–4, Kirchner, C. and Kirchner, H., Eds. Electronic Notes in Theoretical Computer Science, vol. 15. Elsevier, 329344. http://www.elsevier.nl/locate/entcs/volume15.html.Google Scholar
Brassel, B. and Berghammer, R. 2009. Functional (logic) programs as equations over order-sorted algebras. Informal Proceedings of 19th International Symposium on Logic-Based Program Synthesis and Transformation, LOPSTR 2009.Google Scholar
Brassel, B., Fischer, S., Hanus, M. and Reck, F. 2010. Transforming functional logic programs into monadic functional programs. In WFLP, Mariño, J., Ed. Lecture Notes in Computer Science, vol. 6559. Springer, New York, USA, 3047.Google Scholar
Brassel, B., Hanus, M., Peemöller, B. and Reck, F. 2011. KiCS2: A new compiler from Curry to Haskell. In Proceedings of the 20th International Conference on Functional and Constraint Logic Programming, WFLP 2011, Kuchen, H., Ed. Lecture Notes in Computer Science, vol. 6816. Springer, New York, USA, 118.Google Scholar
Brassel, B. and Huch, F. 2007. On a tighter integration of functional and logic programming. In APLAS, Shao, Z., Ed. Lecture Notes in Computer Science, vol. 4807. Springer, New York, USA, 122138.Google Scholar
Caballero, R. and López-Fraguas, F. 2003. Improving deterministic computations in lazy functional logic languages. Journal of Functional and Logic Programming 2003, 1, 23.Google Scholar
Clavel, M., Durán, F., Eker, S., Lincoln, P., Martí-Oliet, N., Meseguer, J. and Talcott, C. 2007. All About Maude: A High-Performance Logical Framework. Lecture Notes in Computer Science, vol. 4350. Springer, New York, USA.Google Scholar
DeGroot, D. and Lindstrom, G. E. 1986. Logic Programming, Functions, Relations, and Equations. Prentice Hall, Upper Saddle River, NJ, USA.Google Scholar
Dijkstra, E. W. 1997. A Discipline of Programming. Prentice Hall, Upper Saddle River, NJ, USA.Google Scholar
Echahed, R. and Janodet, J.-C. 1998. Admissible graph rewriting and narrowing. In Proceedings of the 1998 Joint International Conference and Symposium on Logic Programming. MIT Press, Manchester, UK, 325340.Google Scholar
Escobar, S. 2004. Implementing natural rewriting and narrowing efficiently. In Proceedings of the 7th International Symposium on Functional and Logic Programming, FLOPS 2004, Kameyama, Y. and Stuckey, P., Eds. Lecture Notes in Computer Science, vol. 2998. Springer, New York, USA, 147162.Google Scholar
Fischer, S., Kiselyov, O. and Shan, C.-C. 2009. Purely functional lazy non-deterministic programming. In ICFP '09: Proceedings of the 14th ACM SIGPLAN International Conference on Functional Programming. ACM, New York, NY, USA, 1122.Google Scholar
Futatsugi, K. and Diaconescu, R. 1998. CafeOBJ Report. AMAST Series in Computing, vol. 6. World Scientific, Singapore.Google Scholar
González-Moreno, J. C., Hortalá-González, T., López-Fraguas, F. and Rodríguez-Artalejo, M. 1996. A rewriting logic for declarative programming. In Proceedings of the European Symposium on Programming, ESOP 1996. Lecture Notes in Computer Science, vol. 1058. Springer, New York, USA, 156172.Google Scholar
González-Moreno, J. C., Hortalá-González, T., López-Fraguas, F. and Rodríguez-Artalejo, M. 1999. An approach to declarative programming-based on a rewriting logic. Journal of Logic Programming 40, 1, 4787.Google Scholar
González-Moreno, J., Hortalá-González, M. and Rodríguez-Artalejo, M. 1997. A higher order rewriting logic for functional logic programming. In Proceedings of the International Conference on Logic Programming, ICLP 1997. MIT Press, Cambridge, MA, USA, 153167.Google Scholar
Hanus, M. 2005. Functional Logic Programming: From Theory to Curry. Tech. Rep. Christian-Albrechts-Universität, Kiel, Germany.Google Scholar
Hanus, M. (Ed.) 2006. Curry: An integrated functional logic language (version 0.8.2). Accessed 3 October 2010. URL: http://www.informatik.uni-kiel.de/~curry/report.html.Google Scholar
Hanus, M. 2007. Multi-paradigm declarative languages. In Proceedings of the International Conference on Logic Programming, ICLP 2007. LNCS, vol. 4670. Springer, New York, Usa, 4575.Google Scholar
Hermenegildo, M. V., Bueno, F., Carro, M., López-García, P., Mera, E., Morales, J. F. and Puebla, G. 2012. An overview of ciao and its design philosophy. Theory and Practice of Logic Programming 12, 1–2, 219252.Google Scholar
Hughes, J. and O'Donnell, J. 1990. Expressing and reasoning about non-deterministic functional programs. In Proceedings of the 1989 Glasgow Workshop on Functional Programming. Workshops in Computing, Springer, London, UK, 308328.Google Scholar
Hussmann, H. 1993. Non-Determinism in Algebraic Specifications and Algebraic Programs. Birkhäuser Verlag, Berlin, Germany.Google Scholar
Launchbury, J. 1993. A natural semantics for lazy evaluation. In Proceedings of the ACM Symposium on Principles of Programming Languages, POPL 1993. ACM Press, New York, USA, 144154.Google Scholar
López-Fraguas, F., Martin-Martin, E., Rodríguez-Hortalá, J. and Sánchez-Hernández, J. Available on request. Rewriting and narrowing for constructor systems with call-time choice semantics. Submitted to Theory and Practice of Logic Programming.Google Scholar
López-Fraguas, F., Rodríguez-Hortalá, J. and Sánchez-Hernández, J. 2007. A simple rewrite notion for call-time choice semantics. In Proceedings of the Principles and Practice of Declarative Programming. ACM Press, New York, USA, 197208.Google Scholar
López-Fraguas, F., Rodríguez-Hortalá, J. and Sánchez-Hernández, J. 2008. Rewriting and call-time choice: The HO case. In Proceedings of the 9th International Symposium on Functional and Logic Programming, FLOPS 2008. Lecture Notes in Computer Science, vol. 4989. Springer, New York, USA, 147162.Google Scholar
López-Fraguas, F., Rodríguez-Hortalá, J. and Sánchez-Hernández, J. 2009a. A fully abstract semantics for constructor systems. In Proceedings of the 20th International Conference on Rewriting Techniques and Applications, RTA 2009. Lecture Notes in Computer Science, vol. 5595. Springer, Berlin, Germany, 320334.Google Scholar
López-Fraguas, F., Rodríguez-Hortalá, J. and Sánchez-Hernández, J. 2009b. A lightweight combination of semantics for non-deterministic functions. CoRR abs/0903.2205.Google Scholar
López-Fraguas, F., Rodríguez-Hortalá, J. and Sánchez-Hernández, J. 2009c. A flexible framework for programming with non-deterministic functions. In Proceedings of the 2009 ACM SIGPLAN Workshop on Partial Evaluation and Program Manipulation, PEPM 2009. ACM, New York, USA, 91100.Google Scholar
López-Fraguas, F. and Sánchez-Hernández, J. 1999. $\mathcal{TOY}$ : A multiparadigm declarative system. In Proceedings of the Rewriting Techniques and Applications, RTA 1999. Lecture Notes in Computer Science, vol. 1631. Springer, New York, USA, 244247.Google Scholar
Lucas, S. 1997. Needed reductions with context-sensitive rewriting. In ALP/HOA, Hanus, M., Heering, J. and Meinke, K., Eds. Lecture Notes in Computer Science, vol. 1298. Springer, Berlin, Germany, 129143.Google Scholar
Lucas, S. 1998. Context-sensitive computations in functional and functional logic programs. Journal of Functional and Logic Programming 1998, 1, 161.Google Scholar
Lux, W. 2009. Curry mailing list: Type-classes and call-time choice vs. run-time choice. Accessed 3 October 2010. URL: http://www.informatik.uni-kiel.de/~curry/listarchive/0790.html.Google Scholar
McCarthy, J. 1963. A basis for a mathematical theory of computation. In Computer Programming and Formal Systems, Braffort, P. and Hirshberg, D., Eds. North-Holland, Amsterdam, Netherlands, 3370.Google Scholar
Plasmeijer, R. J. and van Eekelen, M. C. J. D. 1993. Functional Programming and Parallel Graph Rewriting. Addison-Wesley, Boston, MA, USA.Google Scholar
Plump, D. 1999. Term graph rewriting. In Handbook of Graph Grammars and Computing by Graph Transformation, vol. 2: Applications, Languages, and Tools. World Scientific, River Edge, NJ, USA, 361.Google Scholar
Riesco, A. and Rodríguez-Hortalá, J. 2010a. A natural implementation of plural semantics in Maude. In Proceedings of the 9th Workshop on Language Descriptions, Tools, and Applications, LDTA 2009, Ekman, T. and Vinju, J., Eds. Electronic Notes in Computer Science, vol. 253(7). Elsevier, Maryland Heights, MO, USA, 165175.Google Scholar
Riesco, A. and Rodríguez-Hortalá, J. 2010b. Programming with singular and plural non-deterministic functions. In Proceedings of the 2010 ACM SIGPLAN Workshop on Partial Evaluation and Program Manipulation, PEPM 2010. ACM, New York, USA, 8392.Google Scholar
Riesco, A. and Rodríguez-Hortalá, J. 2011. Singular and Plural Functions for Functional Logic Programming: Detailed Proofs. Tech. Rep. SIC-9/11, Dpto. Sistemas Informáticos y Computación, Universidad Complutense de Madrid. November. URL: http://gpd.sip.ucm.es/PluralSemantics.Google Scholar
Rodríguez-Hortalá, J. 2008. A hierarchy of semantics for non-deterministic term rewriting systems. In Proceedings Foundations of Software Technology and Theoretical Computer Science, FSTTCS 2008. Leibniz International Proceedings in Informatics. Schloss Dagstuhl–Leibniz-Zentrum fuer Informatik.Google Scholar
Rodríguez-Hortalá, J. 2009. Curry mailing list: Re: Type-classes and call-time choice vs. run-time choice. Accessed 3 October 2010. URL: http://www.informatik.uni-kiel.de/~curry/listarchive/0801.html.Google Scholar
Rodríguez-Hortalá, J. and Sánchez-Hernández, J. 2008. Functions and lazy evaluation in prolog. Electronic Notes in Theoretical Computer Science 206, 153174.Google Scholar
Roy, P. V. and Haridi, S. 2004. Concepts, Techniques, and Models of Computer Programming. MIT Press, Cambridge, MA, USA.Google Scholar
Søndergaard, H. and Sestoft, P. 1990. Referential transparency, definiteness and unfoldability. Acta Informatica 27, 6, 505517.Google Scholar
Søndergaard, H. and Sestoft, P. 1992. Non-determinism in functional languages. The Computer Journal 35, 5, 514523.Google Scholar
Sterling, L. and Shapiro, E. 1986. The Art of Prolog. MIT Press, MA, USA.Google Scholar
TeReSe. 2003. Term Rewriting Systems. Cambridge Tracts in Theoretical Computer Science, vol. 55. Cambridge University Press, Cambridge, UK.Google Scholar
The Mercury Team. 2012. The Mercury Language Reference Manual, Version 11.07.1. The Mercury Project, URL: http://www.mercury.csse.unimelb.edu.au/rss.xml.Google Scholar
Wadler, P. 1985. How to replace failure by a list of successes. In Proceedings of the Functional Programming and Computer Architecture. LNCS, vol. 201. Springer, Berlin, Germany, 113128.Google Scholar
Wadler, P. and Blott, S. 1989. How to make ad-hoc polymorphism less ad hoc. In Proceedings of the 16th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages. ACM, New York, NY, USA, 6076.Google Scholar
Warren, D. H. 1982. Higher-order extensions to Prolog: Are they needed? In Machine Intelligence 10, Hayes, J., Michie, D. and Pao, Y.-H., Eds. Ellis Horwood, Chichester, UK, 441454.Google Scholar