On 06/13/2012 09:36 AM, Yi Dai wrote:
> Applying 2 to 3 seems so weird and it is even so when such an
> over-application is used, for example,
>
>> max 1 2 3 + 4
> 2 3 + 4
>
> Even in a dynamically-typed setting, one would expect a dynamic error.
That doesn't happen in Pure because of the term rewriting semantics. You
won't usually get an exception in Pure because that interferes with
symbolic evaluation of expressions. E.g., the following computation is
perfectly legal in Pure, with f, g, x, y, z and t being free (undefined)
symbols:
> (f x . g y) z t;
f x (g y z) t
If you're too lazy to invent variable names, you might as well write:
> (1 2 . 3 4) 5 6;
1 2 (3 4 5) 6
That kind of stuff would be precluded in a language which forbids
anything but a closure in the head position of a function application.
Actually that's the case in virtually every other FPL (except maybe
computer algebra systems), but I think of this as a very important
feature of Pure.
Also note that in Pure "constructor terms" are just applications of a
free symbol to some arguments, such as [1] === 1:[] === (:) 1 []. So
there's no distinction between "normal" function applications and
constructor terms like in Haskell et al. I consider this design
minimalistic and elegant.
> According to your answer, it seems this strange behavior is a
> consequence of Pure's TRS base. But is it a feature or misfeature. If
> it is the former, any scenario for its use?
As pointed out above, Pure allows any free symbol in the head position
of a function application, so it would be a rather arbitrary restriction
to forbid a number (or anything else which is not a symbol or an
application) there.
It's true that from the practical POV a normal form like 2 3 isn't
usually of much use since, as John pointed out, you can't have a rule
that defines a "headless" application of the form x::int y::int right
now. But you might still use them as constructor terms, so you could
define something like:
> foo (x@_ y) = x*y;
> foo (2 3);
6
Whether that's actually useful in some cases is left to your
imagination. But at least it's possible. Pure is much more permissive
than languages with the H/M safety net, so it doesn't put many
restrictions on the forms of terms.
In this context I just can't help taking the opportunity to link to this
again:
http://www.lisperati.com/landoflisp/panel01.html. Enjoy. :)
Albert
--
Dr. Albert Gr"af
Dept. of Music-Informatics, University of Mainz, Germany
Email:
Dr.G...@t-online.de,
a...@muwiinfa.geschichte.uni-mainz.de
WWW:
http://www.musikinformatik.uni-mainz.de/ag