📝 Original Info
- Title: A Lightweight Combination of Semantics for Non-deterministic Functions
- ArXiv ID: 0903.2205
- Date: 2009-03-13
- Authors: Researchers from original ArXiv paper
📝 Abstract
The use of non-deterministic functions is a distinctive feature of modern functional logic languages. The semantics commonly adopted is call-time choice, a notion that at the operational level is related to the sharing mechanism of lazy evaluation in functional languages. However, there are situations where run-time choice, closer to ordinary rewriting, is more appropriate. In this paper we propose an extension of existing call-time choice based languages, to provide support for run-time choice in localized parts of a program. The extension is remarkably simple at three relevant levels: syntax, formal operational calculi and implementation, which is based on the system Toy.
💡 Deep Analysis
Deep Dive into A Lightweight Combination of Semantics for Non-deterministic Functions.
The use of non-deterministic functions is a distinctive feature of modern functional logic languages. The semantics commonly adopted is call-time choice, a notion that at the operational level is related to the sharing mechanism of lazy evaluation in functional languages. However, there are situations where run-time choice, closer to ordinary rewriting, is more appropriate. In this paper we propose an extension of existing call-time choice based languages, to provide support for run-time choice in localized parts of a program. The extension is remarkably simple at three relevant levels: syntax, formal operational calculi and implementation, which is based on the system Toy.
📄 Full Content
arXiv:0903.2205v1 [cs.PL] 12 Mar 2009
A Lightweight Combination of Semantics for
Non-deterministic Functions ⋆
Francisco Javier L´opez-Fraguas, Juan Rodr´ıguez-Hortal´a, and
Jaime S´anchez-Hern´andez
Departamento de Sistemas Inform´aticos y Computaci´on
Universidad Complutense de Madrid, Spain
fraguas@sip.ucm.es, jrodrigu@fdi.ucm.es, jaime@sip.ucm.es
Abstract. The use of non-deterministic functions is a distinctive feature
of modern functional logic languages. The semantics commonly adopted
is call-time choice, a notion that at the operational level is related to the
sharing mechanism of lazy evaluation in functional languages. However,
there are situations where run-time choice, closer to ordinary rewriting, is
more appropriate. In this paper we propose an extension of existing call-
time choice based languages, to provide support for run-time choice in
localized parts of a program. The extension is remarkably simple at three
relevant levels: syntax, formal operational calculi and implementation,
which is based on the system Toy.
1
Introduction
Non-strict non-deterministic functions are a distinctive feature of modern func-
tional logic languages (see [5] for a recent survey). It is known that the introduc-
tion of non-determinism in a functional setting gives rise to a variety of semantic
decisions (see e.g. [12]). For term-rewriting based specifications, Hussmann [7]
established a major distinction between call-time choice and run-time choice.
Call-time choice is closely related to call-by-value and, in the case of strict se-
mantics, it is easily implemented by innermost rewriting. In the case of non-strict
semantics, things are more complicated, since the call-by-value view of call-time
choice must include partial values. Operationally, this
needs something simi-
lar to the sharing mechanism followed, for efficiency reasons, in (deterministic)
functional languages under lazy evaluation. In contrast, run-time choice does not
share, corresponds rather to call-by-name, and is realized by ordinary rewriting.
For deterministic programs, run-time and call-time are able to produce the same
set of values, but in general the set of values reachable by run-time choice is larger
than that of call-time choice.
Non-deterministic functions with non-strict and call-time choice semantics
were introduced in the functional logic setting with the CRWL framework [4],
⋆This work has been partially supported by the Spanish projects MERIT-FORMS-
UCM (TIN2005-09207-C03-03), FAST-STAMP (TIN2008-06622-C03-01/TIN) and
Promesas-CAM (S-0505/TIC/0407) .
A Lightweight Combination of Semantics for Non-deterministic Functions
53
in which programs are possibly non-confluent and non-terminating constructor-
based term rewriting systems (CTRS). Since then, they are common part of
daily programming in systems like Curry [6] or Toy [11]. Run-time choice has
been rarely [1] considered as a valuable global alternative to call-time choice.
However, there might be parts in a program or individual functions for which
run-time choice could be a better option, and therefore it would be convenient
to have both possibilities (run-time/call-time) at programmer’s disposal. The
following example illustrates the interest of combining both semantics.
Example 1.
Modeling grammar rules for string generation can be directly done
by CTRS like the following (non-confluent and non-terminating) one, in which
we assume that texts (terminals) are represented as strings (lists of characters),
that can be concatenated with ++ (defined in a standard way):
letter →”a” .... letter →”z”
word →” ”
word →letter++word
Disregarding syntax, this CTRS is a valid program in functional logic systems
like Curry or Toy. The program acts as a non-deterministic generator of the
texts in the language defined by the grammar. Each individual reduction leads
to a string in the language.
The generation of palindromes (of even length, for simplicity) could be done
by the rewrite rules:
palindrome →palAux(word)
palAux(X) →X ++ reverse(X)
where reverse is defined in any standard way. It is important to remark that the
definition of palindrome/palAux works fine only if call-time choice is adopted for
non-determinism, meaning operationally that in the (partial) reduction
palindrome →palAux(word) →word ++ reverse(word)
the two occurrences of word created by the rule of palAux must be shared. If
run-time choice (i.e., ordinary rewriting) were used, the two occurrences of word
could follow independent ways, and therefore palindrome could be reduced, for
instance, to ”oops”, which is not a palindrome. Two useful operators to structure
grammar specifications are the alternative ‘|’ and Kleene’s ‘∗’ for repetitions:
X | Y →X
X | Y →Y
star X →” ”
star X →X++star(X)
With them letter and word could be redefined as follows:
letter →”a” | ”b” | ... | ”z”
word →star(letter)
The annoying fact is that this does not work! At least not under call-time
choice, which implies that this is an uncorrect definition of sta
…(Full text truncated)…
📸 Image Gallery
Reference
This content is AI-processed based on ArXiv data.