In article ... pop@dcs.glasgow.ac.uk (Robin Popplestone) writes:
My idea
of stack-grammars seems the only one presented in this group (to my
knowledge) that has a chance of preserving a useful body of open-stack usage
with the possiblity of a feasible implementation.
I have been tinkering, on and off, with a way of desribing the types of
Pop functiosn which includes the open stack. I suspect that it's isomorphic
to Robin's ideas, but I derived it by trying to extend the ML notion
of type-checking with the open stack. There are links with abstract
interpretation too (hardly surprising; that, in a sense, is what type-
checking *is*).
Consider our friend applist. This gets a type like this:
applist:
Args,, List(T), (Args, T) -> (U, Args)
-> Args, U*
Here Args, T, and U are stack type variables. The type says that
applist takes:
* some pile of things on the stack, typed by Args;
* a list of elements of type T
* a function which takes an Args-shaped pile and a T, and
delivers a U and another Args-shaped pile
Suppose inc(x) returns x+1; it has type ``Num -> Num''. Then the simple
application ``applist([1,2,3], inc)'' fits the type specification:
* Args is the empty stack-sequence
* T is Num
* U is also Num
and the result of the application has type Num*, ie, a pile of Num's
on the stack. Well, that was easy, but even ML can do this: a more
interesting expression is ``applist(0, [1,2,3], nonop +)''. ``+''
is, of course, ``(Num, Num) -> Num''. Again, the application fits:
* Args is just Num
* T is Num
* U is *nothing*, ie, the empty stack sequence
and the result is a single Num, just as we'd hope.
Now, I've played fast-and-loose with some issues (such as, what is Num?
is there a difference twix a single-type and a stack-type? What about
overloading?), and I've not got around to doing proper inference rules,
but I think this can be pushed into the right direction.
Oh yes, the list notation is Pepper. Whoops.
--
Regards, | ``"I can't suit myself," said Weinbaum, a little petulantly.
Kers. | "I work for the Government".'' - Blish, "The Quincunx of Time".
|