Learning Haskell and FP

Jon Fairbairn jf15@hermes.cam.ac.uk
Wed, 17 Jan 2001 12:23:46 +0000 (GMT)

On Tue, 16 Jan 2001, Fritz Ruehr wrote:
> Erik Meijer said:
> > Not many other imperative languages have statements as first class citi=
> I don't have the details here (e.g., an Algol 68 report), but Michael Sco=
> reports in his "Programming Language Pragmatics" text (p. 279) that:
>     "Algol 68 [allows], in essence, indexing into an array of statements,
>     but the syntax is rather cumbersome."

Well, there are two ways it allows this.
1) The case statement is little more than array indexing
   case <int>
     in <stmt1>,
    out <other statement>

2) You can create an array of procedures returning void
results, for which if I remember correctly you have to write
VOID: <stmt>
to turn the <stmt> into a proc void.  You can certainly
index an array of these and the relevant proc will be called
as soon as the indexing happens (you don't need to write
() or anything).

So (VOID: print ("a"), VOID: print ("b"))[2] would print
"b". I can't remember if you need to specify the type of the
array, though.

The statements aren't first class, though, because their
scope is restricted by the scope of variables that they
reference. So

begin [10] proc void x; # declare an array of procs #
      begin int n :=3D 42;
            x[1] :=3D void: (print (n))

is invalid because at x[1] it would call the procedure,
which would refer to n, which is out of scope (and quite
possibly because of sundry syntax errors!). So Algol 68
isn't a counterexample to Erik's claim.

> This is in reference to historical variations on switch-like statements (=
> consistent with a running theme, typical in PL texts, about the extremes =
> orthogonality found in Algol 68).

Although if they'd really wanted to be extreme they could
have left out integer case clauses, because they are the
same as indexing a [] proc void!


J=F3n Fairbairn                                 Jon.Fairbairn@cl.cam.ac.uk
31  Chalmers Road                                        jf@cl.cam.ac.uk
Cambridge CB1 3SZ                      +44 1223 570179 (pm only, please)