Re: prelude extension proposal

From: Sergio Antoy <antoy_at_cs.pdx.edu>
Date: Tue, 18 Oct 2005 16:11:29 -0700

Dear Colleagues,

I'd like to thank all those who addressed my posting. Since I am
late, I'm sending a collective (as opposed to individual) reply.
>From the replies, at least how I understood them, I think that I
did not express myself clearly. I apologize and try one more
time. Sorry if this message is longer than I would like it to be.

Suppose that I am teaching a class about non-deterministic
computations and, by way of example, I code an operation named
"permute" that computes a permutation of its list argument. Since
the students are puzzled by an operation that when applied to an
argument can produce many values, I show how such an operation can
be profitably used.

I discuss how the well-know 8-queens puzzle uses permutations of
[1..8] to represent a placement of the queens on the board. Then,
I discuss how some operation, let's call it "safe", can tell if a
placement of queens on the board is a solution of the puzzle, and
finally I tell them that I can solve the puzzle with

    lect1> X=:=permute[1..8] & safe X

This done, I tell the students that there is another use of
non-deterministic operations, namely to get all the values of an
expression. For this I show:

    lect1> take 10 (findall ((permute [1..8]) =:=))

My experience proves that at this point I get a million questions
that are only marginally related to what I want to present. E.g.,
"what is permute [1..8]) equal to?", I have to talk about the
syntax of sections. "Yeah, but wath is the meaning of (-1)?", "Why
(- 1) is not a section?", "Why does findall take a function?",
"Why cannot it take a function of any type?", and finally "How is
findall defined?", I tell them it is magic.

Since magic is involved, why can't I make it a bit more magic and
much easier to follow? So I learned to place the following in
lect1.curry

    allValuesOf x = findall (x =:=)

This makes a simpler lecture because I get the above questions
by e-mail the next day after the students look at my code.

So, dear colleagues, my modest proposal was to place the above
definition in the prelude. The prelude is an anachronism. Recent
languages, and recent implementations of older languages, do
without it. Its purpose was simply to provide magic and/or
convenient functions at the programmer's fingertips. Would there
be a better place for allValuesOf?

Now, from various replies, I understand that there are concerns
for my modest proposal. I try to recall them below, perhaps a bit
crudely. One is that allValuesOf cannot be provided by MCC. This
is unfortunate. I think that a FL programming language could and
should have some mechanism such as allValuesOf, at least in some
restrictive cases, e.g., when the argument is a ground term, as in
my example. Perhaps future versions of Curry and/or MCC will
improve on this state of affairs. Another concern is that the
semantics of something like allValuesOf is difficult to capture
and its implementation should better be in the IO-monad. Ok, but
since I can simply put my allValuesOf in my program, what am I
saved from by not finding it in the prelude?

To conclude this thread, I retract my modest proposal, since it
appears to be quite controversial (and there are two easy
workarounds for my problem), and I thank you again for your
comments.

Cheers,
Sergio

_______________________________________________
curry mailing list
curry_at_lists.RWTH-Aachen.DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/curry
Received on Mi Okt 19 2005 - 08:00:17 CEST

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