De nitional Programming in GCLA Techniques, oloft/Papers/lic.pdfDe nitional Programming in GCLA Techniques, Functions, and Predicates Olof Torgersson 1 Introduction When a new programming

  • View
    213

  • Download
    1

Embed Size (px)

Text of De nitional Programming in GCLA Techniques, oloft/Papers/lic.pdfDe nitional Programming in GCLA...

  • Definitional Programming in GCLA

    Techniques, Functions, and Predicates

    Olof Torgersson

    Department of Computing Science1996

  • Definitional Programming in GCLA

    Techniques, Functions, and Predicates

    Olof Torgersson

  • A Dissertation for the Licentiate Degree in Computing Science

    at the University of Goteborg

    Department of Computing Science

    S-412 96 Goteborg

    ISBN 91-7197-242-0

    CTH, Goteborg, 1996

  • Abstract

    When a new programming language or programming paradigm is devised, it is

    essential to investigate its possibilities and give guide-lines for how it can best

    be used. In this thesis we describe some of the possibilities of the declarative

    programming paradigm definitional programming. We discuss both general pro-

    gramming methodology and delve further into the subject of combining functional

    and logic programming within the definitional framework. Furthermore, we in-

    vestigate the relationship between functional and definitional programming by

    translating functional programs to the definitional programming language GCLA.

    The thesis consists of three separate parts. In the first we discuss general

    programming methodology in GCLA. A program in GCLA consists of two parts,

    the definition and the rule definition, where the definition is used to give the

    declarative content of an application and the rule definition is used to give a

    procedural interpretation of the definition. We present and discuss three different

    ways to write the rule definition to a given definition. The first is a stepwise

    refinement strategy, similar to the usual way to give control information in Prolog

    where cuts are added in a rather ad-hoc fashion. The second is to split the set

    of conditions in the definition in a number of different classes and to give control

    information for each class. The third alternative is a local approach where we

    give a procedural interpretation to each atom in the definition.

    The second part of the thesis concerns the integration of functional and logic

    programming. We show how GCLA can be used to amalgamate first order func-

    tional and logic programming. A number of different rule definitions developed

    for this purpose are presented as well as a rule generator for functional logic pro-

    grams. The rule generator creates rule definitions according to the third method

    described in the first part of the thesis. We also compare our approach with other

    existing and proposed integrations of functional logic programming. Even though

    all examples are given in GCLA the described ideas could just as well serve as a

    basis for a specialized functional logic programming language based on the theory

    of partial inductive definitions.

    In the third part we report on an experiment where we translated a subset of

    the lazy functional language LML to GCLA. This work has a close connection to

    different attempts to integrate functions and lazy evaluation into logic program-

    ming. The basic idea in the translation is that we use ordinary techniques from

    compilers for lazy functional languages to transform the functional program into

    a set of supercombinators. These supercombinators can then easily be mapped

    into GCLA definitions.

  • Acknowledgements

    I would like to thank Lars Hallnas for encouragement and support, Goran Falk-

    man for reading my papers very carefully, Nader Nazari for being so very stub-

    born, Johan Jeuring and Jan Smith for reading and commenting on earlier ver-

    sions of this thesis, and finally my family for being there.

  • This thesis consists of the following papers:

    G. Falkman and O. Torgersson. Programming Methodologies in GCLA. InR. Dyckhoff, editor, Extensions of logic programming, ELP93, number 798in Lecture Notes in Artificial Intelligence, pages 120151. Springer-Verlag,1994.

    Olof Torgersson. Functional Logic Programming in GCLA. Different partsof this paper are published as:

    O. Torgersson. Functional logic programming in GCLA. In U. Eng-berg, K. Larsen, and P. Mosses, editors, Proceedings of the 6th NordicWorkshop on Programming Theory. Aarhus, 1994.

    O. Torgersson. A definitional approach to functional logic program-ming. In Extensions of Logic Programming, ELP96, Lecture Notes inArtificial Intelligence. Springer-Verlag, 1996.

    Olof Torgersson. Translating Functional Programs to GCLA.

  • Definitional Programming in GCLA

    Techniques, Functions, and Predicates

    Olof Torgersson

    1 Introduction

    When a new programming language or programming paradigm is devised, it isessential to investigate its possibilities and give guide-lines for how it can bestbe used. In this thesis we describe some of the possibilities of the declarativeprogramming paradigm definitional programming. We will discuss both generalprogramming methodology and delve further into the subject of combining func-tional and logic programming within the definitional framework. Furthermore, weinvestigate the relationship between functional and definitional programming bytranslating functional programs to the definitional programming language GCLA1.

    Declarative programming is divided into two major areas, functional and logicprogramming. Although the theoretical bases for these are quite different the re-sulting programming languages share one common goalthe programmer shouldnot need to be concerned with control. Instead the programmer should only needto state the declarative content of an application. It is then up to the compilerto decide how this declarative description of a problem should be evaluated. Thisgoal of achieving declarative programming in a strong sense [22] is most pro-nounced in modern functional languages like Haskell [17] where the programmerrarely is aware of control. Due to the more complex evaluation principles of logicprogramming languages, they so far typically provide declarative programming ina weaker sense where the programmer still need to provide some control informa-tion to get an efficient program. However, the aim at declarative programming inthe strong sense reflects an extensional view of programs; focus is on the functionsor predicates defined not on their definitions.

    Definitional programming takes a quite different approach in that it studiesthe definitions that constitute programs. Programs are regarded as partial in-ductive definitions [13] and focus is on the definitions themselves as the primaryobjectsa focus that reflects an intensional view of programs. In this more low-level approach there is no obvious fixed uniform computational or proceduralmeaning of all definitions. Instead, different kinds of definitions require differentkinds of evaluation, for instance the definition of a predicate is not used in the

    1To be pronounced Gisela.

    1

  • Definitional Programming in GCLA: Techniques, Functions, and Predicates

    same way as the definition of a function. To describe the intended computationalcontent or procedural information we use another definition, the rule definition,with a fixed interpretation. Thus, control becomes an integrated part of the pro-gram with the same status and with a declarative reading just like the definitionof the problem to be solved.

    What we get is a model where programs consists of two separate but connectedpartsboth understood by the same basic theorywhere one part is used toexpress the declarative content of a problem, and the other to analyze and expressits computational content to form an executable program. This model in turngives rise to questions like What are the typical properties of definitions of typea that makes them executable using rule definitions of type b? or How can weclassify algorithms with respect to their computational content as expressed inthe rule definition? Some research in this direction is discussed in [9, 10] wherealgorithms are analyzed by a program separation scheme using a certain notionof form and content.

    From a programming methodology point of view, a GCLA programmer mustbe much more concerned with control than a functional or logic programmer. Theconcern for control reflects a philosophical or ideological difference between defi-nitional programming as realized in GCLA and functional and logic programminglanguages. In a conventional functional or logic programming language, wherethe control component of programs is fixed or rather limited, the declarative de-scription of a problem that constitutes a program must be adjusted to conform tothe computational model. In GCLA on the other hand, control is an integrateddeclarative part of the program, and the power of the control part of the languagegives a very large amount of freedom in the declarative part, making it easy toexpress different kinds of ideas [3, 11]. The other side of the coin is of coursethat when writing programs with simple controllike functional programstheGCLA programmer has to supply the control information that in a functionallanguage is embedded in the computational model. However, in such relativelysimple cases the necessary control part, as we will show, can usually be suppliedby some library definition or be more or less automatically generated.

    2 Definitional Programming and GCLA

    A program in GCLA consists of two partial inductive definitions which we refer toas the definition or the object-level definition and the rule definition respectively.We will sometimes refer to the definition as D and to the rule definition as R.Since both D and R are understood as definitions we talk about programmingwith definitions, or definitional programming.

    Definitional programming as it is reali