Developing suitable formal semantics can be of great help in the understanding, design and implementation of a programming language, and act as a guide for software development tools like analyzers or partial evaluators. In this sense, full abstraction is a highly desirable property, indicating a perfect correspondence between the semantics and the observable behavior of program pieces. In this work we address the question of full abstraction for the family of modern functional logic languages, in which functions can be higher order and non-deterministic, and where the semantics adopted for non-determinism is \emph{call-time choice}. We show that, with respect to natural notions of \emph{observation}, any semantics based on \emph{extensional} functions is necessarily unsound; in contrast, we show that the higher order version of \emph{CRWL}, a well-known existing semantic framework for functional logic programming, based on an \emph{intensional} view of functions, turns out to be fully abstract and compositional.
Developing suitable formal semantics can be of great help in the understanding, design and implementation of a programming language, and acts as a guide for software development tools like analyzers or partial evaluators. In this sense, full abstraction is a highly desirable property, indicating a perfect correspondence between the semantics and the behavior of program pieces, according to a given criterion of observation.
The notion of full abstraction was introduced by Plotkin [19] in connection to PCF, a simple model of functional programming based on λ-calculus. He realized that the standard Scott semantics, in which expressions of functional types have classical mathematical functions as meanings, lacks full abstraction with respect to observing the value obtained in the evaluation of an expression. The reason lays in the impossibility of defining the function por (parallel or ) in PCF. Using this fact one can build two higher order (HO) expressions e 1 , e 2 denoting two different mathematical functions ϕ 1 , ϕ 2 , both expecting boolean functions as arguments, such that ϕ 1 , ϕ 2 only differ when applied to por as argument. Therefore e 1 , e 2 have different Scott semantics but this difference cannot be observed. It is usually said that the semantics is too concrete. Notice, however, that Scott semantics for PCF is sound, that is, if two expressions have the same semantics, they cannot be observably distinguished. Unsoundness of a semantics can be considered a flaw, much more severe that being too concrete, which is more a weakness than a flaw.
Full abstraction for PCF was achieved in different technical ways (see e.g. [3]). But for our purposes it is more interesting to recall that the Scott semantics becomes fully abstract if PCF is enriched with the ‘missing’ por function (see e.g. [18]). The mainstream of functional logic programming (FLP, see [10]) is based rather in the theory of term rewriting systems than in λ-calculus; a consequence is that parallel or can be defined straightforwardly by an overlapping (almost orthogonal) rewriting system. So one could think of assigning to FLP languages a denotational semantics in the FP style. For instance, for a definition like f x = 0, one could assign to f the meaning λx.0. The next step of our discussion is taking into account that modern FLP languages like Curry [12] or Toy [16] also permit non-confluent and non-terminating programs that define non-deterministic nonstrict functions. This suggests that the standard semantics should be modified in the sense that the meaning of a function would be some kind of set-valued function.
The starting motivation of this paper is that this roadmap cannot be followed anymore when non-determinism is combined with HO, at least when considering call-time choice [13,9], which is the notion of non-determinism adopted in, e.g., Curry or Toy. The following example taken from [15] shows it: Example 1. The following program computes with natural numbers represented by the constructors 0 and s, and where + is defined as usual. The syntax uses HO curried notation.
Here f and f ′ are non-deterministic functions that are (by definition of f ′ ) extensionally equivalent. In a set-valued variant of Scott semantics, their common denotation would be the function λX.{0, s 0}, or something essentially equivalent. But this leads to unsoundness of the semantics. To see why, consider the expressions (fdouble f 0) and (fdouble f ’ 0). In Curry or Toy, the possible values for (fdouble f 0) are 0, s (s 0), while (fdouble f ’ 0) can be in addition reduced to s 0. The operational reason to this situation is that fdouble f 0 is rewritten first to fadd f f 0 and then to f 0 + f 0 ; now, call-time choice enforces that evaluation of the two created copies of f (which is an evaluable expression) must be shared.
In the case of f ’ 0 + f ’ 0, since f ′ is a normal form, the two occurrences of f ’ 0 evolve independently. We see then that f and f ′ can be put in a context able to distinguish them, implying that any semantics assigning f and f ′ the same denotation is necessarily unsound, and therefore not fully abstract.
The combination HO + Non-determinism + call-time choice was addressed in HOCRWL [7,8], an extension to HO of CRWL [9], a semantic FO framework specifically devised for FLP with call-time choice semantics for non-determinism. HOCRWL adopts an intensional view of functions, where different descriptionsin the form of HO-patterns-of the same extensional function are distinguished as different data. The intensional point of view of HOCRWL was an a priori design decision, motivated by the desire of achieving enough power for HO programming while avoiding the complexity of higher-order unification of λ-terms modulo βη, followed in other approaches [17,11]. The issues of soundness or full abstraction were not the (explicit nor implicit) concerns of [7,8]; whether HOCRWL actually fulfils those properties or not is exactly the question
This content is AI-processed based on open access ArXiv data.