Free variables in Curry

From: Michael Hanus <hanus_at_informatik.rwth-aachen.de>
Date: Thu, 7 Jan 1999 12:36:06 +0100

Dear Colleagues,

after some discussion with Sergio on the syntax of Curry,
we'd like to propose a further simplification of the syntax of
Curry which is related to implicitly declared free variables.

In order to support a convenient logic programming-oriented
style, the current language definition (Section 2.4) allows
implicitly declared free variables which must start with an underscore
and whose scope is the entire rule. For instance, the definition

   last l | append _xs [_x] =:= l = _x

is an abbreviation for the following rule with explicit declarations:

   last l | append xs [x] =:= l = x where x,xs free

This works fine as long as there is only one scope in the rule,
but it may cause some confusion in the presence of different scopes.
I cite from an email by Sergio:

Sergio Antoy wrote:
> 3. Undeclared free (existential, extra) variables are implicitly
> scoped in the declaration (equation) in which they occur. What
> does it mean? The draft presents the definition
>
> f x | c \z->g x _y = 0
>
> This could be understood as
>
> aux x z = g x _y
> f x | c aux x = 0
>
> or
> aux x y z = g x y
> f x | c aux x _y = 0
>
> The first interpretation seems more reasonable, since there is no
> indication that the scope of _y goes beyond the definition of an
> anonymous function (in other words, _y plays no role in the
> definition of f). The second interpretation is harder to compile.
> It requires one extra pass on the source to find undeclared free
> variables before inner scopes are created; in this example the
> scope of z in which _y is then found.
>
> However this simpler interpretation raises the issue of whether in
> the following definition the two occurrences of identifier _y
> refer to the same variable. According to the first
> interpretation, the answer should be "no."
>
> f x | c \z->g x _y = _y
>
> My conclusion is that the use of undeclared free variables should
> be banned from the language. These would be the only elements of
> the language making an exception to the rule that identifiers must
> be declared. Although undeclaring free variables eases
> understanding in simple situations where understanding is already
> easy, this practice makes understanding more difficult in other
> situations where understanding is difficult. Hence it is not a
> beneficial feature.

I agree on this. Looking at my Curry programs, free variables
only occur at some few places in the program text (due to the use
of functions; in logic programming free variables are extensively
used to pass results from one predicate to another which is
not necessary in Curry) and for most of these occurrences it
is already clearer to define them explicitly. Furthermore,
the explicit definition of existential variables is also
required in other programming languages with different scopes.

Thus, the proposal is to omit the possibility to use undeclared
free variables. This makes the language simpler but requires
more writing in some situations.

Any objections?

Best regards,

Michael
Received on Do Jan 07 1999 - 12:40:00 CET

This archive was generated by hypermail 2.3.0 : Do Feb 01 2024 - 07:15:05 CET