A Declarative Debugger of Incorrect Answers for Constraint Functional-Logic Programs * System Demonstration Rafael Caballero Facultad de Inform´ atica. Univ. Complutense de Madrid rafa@sip.ucm.es Abstract Debugging is one of the essential parts of the software development cycle. However, the usual debugging techniques used in imperative languages such as the step by step execution often are not suitable for debugging declarative programming languages. We present here a graphical debugging environment for constraint lazy functional- logic programs based on declarative debugging. The debugger dis- plays the computation tree associated with a computation which has produced an incorrect answer, and navigates it with the assistance of the user until the error, an incorrect program rule, is found out. The debugger supports programs including equality and disequality constraints. Categories and Subject Descriptors D.3.2 [Programming lan- guages]: Language Classifications—Multiparadigm languages; H.5.2 [Information Interfaces and Presentation]: User Interfaces— Graphical user interfaces (GUI) General Terms Languages Keywords Functional-Logic Languages, Declarative Debugging 1. Declarative Debugging The lack of auxiliary tools such as debuggers has been pointed out in [11] as a possible impediment to the success of functional languages like Haskell [8]. The same arguments can be applied as well to the case of functional-logic languages [6]. However, imple- menting debuggers for these languages is not an easy task. The ap- proach followed traditionally in imperative programming, based on the step by step execution of the program, is not suitable in declar- ative languages, particularly in the case of the lazy functional and functional-logic languages, where features like the higher order, the polymorphism or the lazy evaluation makes the computation more difficult to observe. Declarative debugging was first proposed by E. Y. Shapiro [10] as an alternative in the field of logic programming, and has been ∗ Work partially supported by the Spanish CYCIT (project TIC2002-01167 ’MELODIAS’) 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. To copy otherwise, to republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. WCFLP’05 September 29, 2005, Tallinn, Estonia. Copyright c 2005 ACM 1-59593-069-8/05/0009. . . $5.00. later applied in functional and functional-logic programming as well. A declarative debugging session starts when the user observes an unexpected behavior of the program which is regarded as wrong, and can be divided in two phases: 1. The declarative debugger generates a suitable computation tree (CT in short) representing the behavior of the program during the computation. Each node of the tree represents the result of some subcomputation; the value at the root of the tree corre- sponds to the result of the overall computation, which is called the initial symptom, while the results at the children of each node N must correspond to the subcomputations necessary to obtain the result at N . Moreover, each node must have some associated fragment of code, which is responsible for the com- putation result stored at the node. 2. The debugger navigates tries to locate a node whose result is incorrect but with correct results at all its children nodes. Such a node is called a buggy node, and corresponds to a fragment of code which has produced an erroneous result from correct inputs, and is therefore incorrect. In order to check the correctness of the nodes, the debugger relies on an external oracle, usually the user. Here we present DDT , a graphical declarative debugger of incorrect answers for the constraint lazy functional-logic program- ming language T OY [1]. The prototype is based on a previous version described in [5], the main novelty of the new version being the possibility of debugging programs including equality and disequality constraints. The system can be downloaded from: http://toy.sourceforge.net. In the next section the programs considered in our setting are presented, together with a small example of incorrect program which will be used in the rest of the paper. The section 3 presents informally the computation trees handled by the debugger, while section 4 provide some details about the implementation of the program transformation employed by the tool. A short debugging session for our example program is shown in section 5, where some of the features of the graphical interface are introduced. The efficiency of the system is informally discussed in section 6. The paper ends in section 7 with some conclusions and some proposals of future work. 2. Toy programs A T OY program can include declarations of data, function types, type alias, infix operator declarations, and defining rules for func- tions symbols. Two important syntactic categories in this setting are expressions and patterns. The possible forms of an expression