[Date Prev] [Date Next] [Thread Prev] [Thread Next] Date Index Thread Index Search archive:
Date:Mon Nov 7 17:23:11 1997 
Subject:A new language 
From:Robin Popplestone 
Volume-ID:971107.03 

I've been doing some work towards creating a new computer language, which
will be functional but in some crucial ways more like POP than it is like
Scheme, Haskell or SML. Possible names for the language include:

    POP2000

    Lean

    al-Khwarizmi

Status
------
I had a pilot implementation working, though it's currently apart on the
kitchen floor while I'm putting in some basic type stuff.

Features
--------

The Language is quite close to POP and Scheme, but with a syntax that is
more Haskell/SML like, and with a little HOLery/LCFery in the existence of
a Theorem datatype. It is intended to support a principled approach to some
basic Computer Science.

(1) Anything of interest is a first-class object (something Rod
Burstall and I tried to incorporate in POP-2). So, there will be NO
ML-style structures, functors, Java-style classes etc., but first-class
equivalents.

(2) No Hindley-Milner typing. I've tried SML on my Honors class (US Honors
are to be distinguished from UK Honours). It disnae work for them, since
they don't have the intellectual sophistication to debug at the -type-
level of abstraction rather than the base-level they get in Scheme. Ditto
yours truly...

However, I am including a type-advisor which will identify obvious
impossibilities [e.g. (x=y)+27, or hd(a+b) ], and with luck, will be
integrable with the fanciest feature, the Theorem data-type.

The underlying concept of type is derived from the key-cells of POP. A
primitive type is a set of objects which share a common key-cell.
Non-primitive types share a finite set of key-cells. The exceptions are

    (a) there is a Top type, which is characterised by -all- the key-cells
    which the computation has produced (or might produce?)

    (b) the Procedure type is subdivided on the basis of
    argument-type -> value-type.


(3) The Scheme notion of variadic functions is a theoretical abomination,
however handy for hackers. It is OUT. The trad. POP notion is actually
closer to the lambda-calc., but is too sloppy. So, the Language is pukka
Lambda Calculus, partially applying as reqd. Thus  (+) x  means "add x".
(parentheses around an operator have the force of nonop in POP-11).
Likewise

    hd x y z

has an interpretation in which x is a list of binary functions. So

    hd [(+),(-),(*)] 4 5

evaluates to 9.

Indeed it's close to the POP

    z y x.hd

but is perhaps more clearly written

    (hd x) y z

In fact, down in the engine-room, hd x y z can be exactly equivalent to

    z y x.hd

since an optimised version of code generated by The Language is the same as
that generated by POP, but with the order of all arguments reversed. [We
should have done this in 1968 to make partial application come out in
accord with lambda-calculus conventions]. Optimisation will depend on
type-checking.

(4) The Language has a convention for defining CLASSES. A class is simply
a function from names to values. The dot notation is used by analogy with
SML, Java etc and in disctinction to POP-2/POP-11 to denote the
application of a function to a symbol.

    Class.symbol

means

    Class 'symbol'

Every class must map the following names '?', 'any', 'hash'.

    Class.?   x    Is x a member of Class?
    Class.any s    Maps from a "seed" quantity to a pseudo-random member
                   of the class and a new seed. ****
    Class.hash c   If c is a member of Class, this is an integer.


[**** This is the current convention. I'm thinking of passing the class
Random in as an extra argument, to allow fine-tuning of "random"-object
generation. Producing a new seed allows these generators to be cascaded.
The 'hash' component allows one to implement

    (C1->C2).any

that is, a "random" function that maps members of class C1 to C2.
]

Here is a fragment of a definition of the List class from the primitive
Pair and Null classes.

Definition List =
    \ C sym.
        let rec is_list = \x. x=[] or
                            (Pair.? x and C.? (front x) and
                            is_list (back x))

         .... other local  definitions

        in
            case sym of
                '?'     => is_list
            |   'any'   => any_list
            |   hd      => front
            ....
            |   base    => C        ;;; eg. LI.base [1,2,3] = Integer
                                    ;;; if LI = List Integer
            end case
        end let
End;

Thus, in essence, the Class concept provides the kind of capability of ML
structures, but more, because classes are first-class objects.

(5) Following Milner, the Theorem data-type contains entities that are
guaranteed to be "true" 'cos all constructors for the Theorem type are
proof-methods. However, The Language is not at all foundational in this.
There is a pre-populated set of axioms which, in effect, specify a
correct implemention of the langauge.

Thus, for example, the following should be a consequence of the axioms and
the definition of List:

    |-   All C x.  (List C).? x  ==> (x=[] or  C.? (List.hd x))

that is, for any class C, the head of a non-empty list of C's is a C.
The Theorem-constructors are similar to those of HOL, whose antecedents go
back to Church.

(6) However, while theorem-proving provides the most rigorous notion of
verification of a program, a concept of -stochastic verification- is also
supported, via the "any" component of classes. This should be easier to
use.

The Language supports an idea something like an algebra or theory. For
example, we might have:

Definition Set =
 \ C Ax.
     let (\/)   = C.(\/),
         (/\)   = C.(/\),
         mem    = C.mem,
         C_base = C.base  ;;; i.e. C is a set with members from C_base
     in
         Ax.and
            [
             "(Ax.S1 (All (x:C_base) (s1:C) (s2:C).
                    (mem x s1 and mem x s2)
                                    <=> mem x (s1/\s2)))",
              .... other axioms of set theory...
            ]
    end let
End;

Now, here C is a class which is alleged to be an implementation of the
concept of set, while Ax is a -verification method-. Ax can be a stochastic
verification method, in which case it uses the ".any" feature to think of
"random" members of C and C_base, or it can be proof-based. In this case,
because the name of the axiom is passed in [for example Ax.S1], the user
can specify how each set-axiom is to be proved from existing theorems about
The Language. That is Ax.S1 is an invocation of proof-procedures
hand-crafted for S1. That way we get around the difficulties of automatic
theorem proving.

Thus to verify stochastically that, say, a class-creator TreeSet, appears
to create sets that satisfy the Set axioms, one could call:

    Set (TreeSet Integer) (Random.verify);

expecting an error report if any violations are discovered. Likewise

    Set (TreeSet Integer) prove_treeset

will evaluate to true precisely if the function  prove_treeset is able to
create theorems whose unconditional conclusion is identical to that
specified in the axioms. It should be noted that double-quotation in The
Language means a -quoted closure-, that is the meanings of the non-local
variables are determined by scope rules. Since it is likely that the class

    TreeSet Integer

will be pre-populated with relevant theorems, the "prove_treeset" function
should be easy enough to write, at the expense of course of the difficulty
of writing the TreeSet class.

[Thought - could lazy evaluation help with this concept???]
[Snag - while we are sketching out how to endow any fully-instantiated
class with theorems, and thereby make it easy to show that such a class
obeys certain laws, we seem to be requiring instantiation - for example
we can show that

    TreeSet Integer

is an implementation of sets, but maybe have trouble with

    TreeSet C

for any class C.
============================================================================

I've put some of my thoughts on the web.

http://www.cs.umass.edu

Go to the Education Laboratory (under the heading Academic)

Go to course cs287

Most of this page is devoted to the course of lectures on Programming
Language Paradigms for which we use Scheme. [The material is being
transcribed from VED files, so I've only got lectures 1-18 onWeb].

However, down at the bottom you'll find two files relating to proposals
for  the new language. I'll endeavour to translate the Scheme  lectures
as the opportunity arises.

Robin.