An Automatic Composition Algorithm for Functional Logic Programs
Functional logic languages with a complete operational semantics are based on narrowing, which combines the instantiation of variables with the reduction of expressions. In this paper, we investigate the relationship between partial evaluation and more general transformations based on folding/unfolding. First, we show that the transformations obtained by partial evaluators can be also achieved by folding/unfolding using a particular kind of eurekas which can be mechanically attained. Then, we propose an algorithm (based on folding/unfolding) which starts with the automatic eureka generation and is able to perform program composition, i. e. it is able to produce a single function definition for some nested functions of the original program. This avoids the construction of intermediate data structures that are produced by the inner function and consumed as inputs by the outer function. As opposed to both partial evaluation and (general) fold/unfold transformations, strong correctness of the transformed programs holds w. r. t. goals which contain calls to the old function symbols—i. e. from the original program—as well as to the new ones—i. e. introduced during the transformation.
Unable to display preview. Download preview PDF.
- 1.E. Albert, M. Alpuente, M. Falaschi, P. Julián, and G. Vidal. Improving Control in Functional Logic Program Specialization. In G. Levi, editor, Proc. of Static Analysis Symposium, SAS’98, pages 262–277. Springer LNCS 1503, 1998. 292Google Scholar
- 2.M. Alpuente, M. Falaschi, G. Moreno, and G. Vidal. A Transformation System for Lazy Functional Logic Programs. In A. Middeldorp and T. Sato, editors, Proc. of the 4th Fuji International Symposyum on Functional and Logic Programming, FLOPS’99, Tsukuba (Japan), pages 147–162. Springer LNCS 1722, 1999. 290, 293, 296Google Scholar
- 4.M. Alpuente, M. Hanus, S. Lucas, and G. Vidal. Specialization of Inductively Sequential Functional Logic Programs. In P. Lee, editor, Proc. of 1999 International Conference on Functional Programming, ICFP’99, Paris (France). ACM, New York, 1999. 291, 292Google Scholar
- 5.S. Antoy, R. Echahed, and M. Hanus. A Needed Narrowing Strategy. In Proc. 21st ACM Symp. on Principles of Programming Languages, Portland, pages 268–279, New York, 1994. ACM Press. 289Google Scholar
- 7.W. Chin. Towards an Automated Tupling Strategy. In Proc. of Partial Evaluation and Semantics-Based Program Manipulation, 1993, pages 119–132. ACM, New York, 1993. 296Google Scholar
- 8.C. Consel and O. Danvy. Tutorial notes on Partial Evaluation. In Proc. of 20th Annual ACM Symp. on Principles of Programming Languages, pages 493–501. ACM, New York, 1993. 290Google Scholar
- 9.J. Darlington. Program transformation. In J. Darlington, P. Henderson, and D. A. Turner, editors, Functional Programming and its Applications, pages 193–215. Cambridge UniversityPress, 1982. 294Google Scholar
- 10.N. Dershowitz and J.-P. Jouannaud. Rewrite Systems. In J. van Leeuwen, editor, Handbook of Theoretical Computer Science, volume B: Formal Models and Semantics, pages 243–320. Elsevier, Amsterdam, 1990. 291Google Scholar
- 11.J. Gallagher. Tutorial on Specialisation of Logic Programs. In Proc. of Partial Evaluation and Semantics-Based Program Manipulation, Copenhagen, Denmark, June 1993, pages 88–98. ACM, New York, 1993. 290Google Scholar
- 15.A. Pettorossi and M. Proietti. A Comparative Revisitation of Some Program Transformation Techniques. In O. Danvy, R. Glück, and P. Thiemann, editors, Partial Evaluation, Int’l Seminar, Dagstuhl Castle, Germany, pages 355–385. Springer LNCS 1110, 1996. 290, 295Google Scholar
- 16.W. L. Scherlis. Program Improvement byI nternal Specialization. In Proc. of 8th Annual ACM Symp. on Principles of Programming Languages, pages 41–49. ACM Press, New York, 1981. 294Google Scholar
- 17.H. Tamaki and T. Sato. Unfold/Fold Transformations of Logic Programs. In S. Tärnlund, editor, Proc. of Second Int’l Conf. on Logic Programming, Uppsala, Sweden, pages 127–139, 1984. 290, 295Google Scholar