Extending Functional Languages with High-Level Exception Handling

09/14/2017 ∙ by Keehang Kwon, et al. ∙ DONG-A UNIVERSITY ALLRIGHTS RESERVED 0

We extend functional languages with high-level exception handling. To be specific, we allow sequential-choice expressions of the form E_0 E_1 where E_0, E_1 are expressions. These expressions have the following intended semantics: sequentially choose the first successful E_i and evaluate E_i where i = 0 or 1. These expressions thus allow us to specify an expression E_0 with the failure-handling (exception handling) routine, i.e., expression E_1.



There are no comments yet.


page 1

page 2

This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

1 Introduction

The expressibility of functional programming has improved with higher-order programming, let-expression, etc. Nevertheless exception handling could not be dealt with concisely [1]. For this reason, only a few functional languages such as Standard ML support exception handling of the conventional - style.

In this paper, we discard the conventional approach and propose a new, high-level solution to this problem. A sequential-choice-disjunctive (SCD) expression, originally introduced in the seminal work of [2], is of the form where are expressions. Evaluating this goal with respect to a program – has the following intended semantics:

An illustration of this aspect is provided by the following definition of the function where is a list:

The body of the definition above contains a SC expression, denoted by . As a particular example, evaluating would result in selecting and executing the first expression . If the heapsort module is available in the program, then the given goal will succeed, producing solutions. If the execution fails, the machine tries the plan B, i.e., the quicksort module, and so on.

As seen from the example above, SCD expressions of the form can be used to specify an expression , together with the failure-handling routine . Of course, this expression can be generalized to .

This paper proposes Func, an extension of the core functional languages with SCD operators. The remainder of this paper is structured as follows. We describe Func in the next section. In Section 3, we present some examples of Func. Section 4 concludes the paper.

2 The Language

The language is a version of the core functional languages – also called primitive recursive functions – with SC expressions. It is described by - and -formulas given by the syntax rules below:

In the rules above, is a variable, and is a term which is either a variable or a constant. A -formula is called a program.

Following [4, 3], we will present an interpreter for this language as a set of rules. These rules are based on an eager evaluation. Note that execution alternates between two phases: the evaluation phase and the backchaining phase. In the evaluation phase (denoted by ), the machine tries to evaluate an expression from the program to get a value . The rule (6) – (8) are related to this phase. If is a function call , the machine first evaluates all of its arguments and then looks for a definition of in the program in the backchaining mode. This is encoded in the rule (5). In the backchaining mode (denoted by ), the machine tries to evaluate a function call by using the function definition in the program . The rules (1) – (4) describe these operations.

Definition 1.  Let be an expression and let be a program. Then the notion of evaluating to a value – is defined as follows:

  • if . % switch to evaluation mode.

  • if . % look for in

  • if . % look for in

  • if where . % argument passing to and .

  • if . % switch to backchaining. we make a copy of for a function call.

  • if and . % evaluate the arguments first.

  • % A success if is a constant.

  • if , provided that is the first successful expression. % exception handling.

In the above rules, only the rule (8) is a novel feature.

3 Examples

As an example, let us consider the well-known function. There are many different ways to define this function and below is another one.

In the above, let us consider evaluating . Using backchaining, it first tries 4/0. Since it leads to a failure, the system next tries a constant . This leads to a success and the system returns .

4 Conclusion

In this paper, we have considered an extension to functional languages with SCD expressions. This extension allows expressions of the form where are expressions. These expressions are particularly useful for specifying exception handling in a high level way.


  • [1] R.  Govindarajan, “Exception Handlers in Functional Programming ”, IEEE Transactions on Software Engieering, vol.19, No.8, pp.826–834, 1993.
  • [2] G. Japaridze, “Sequential operators in computability logic”, Information and Computation, vol.206, No.12, pp.1443-1475, 2008.
  • [3]

    E. Komendantskaya and V. Komendantsky, “On uniform proof-theoretical operational semantics for logic programming”, In J.-Y. Beziau and A.Costa-Leite, editors, Perspectives on Universal Logic, pages 379–394. Polimetrica Publisher, 2007.

  • [4] D. Miller, “A logical analysis of modules in logic programming”, Journal of Logic Programming, vol.6, pp.79–108, 1989.