Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Incremental, undoable parsing in OCaml as the general parser inversion
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-07-05 (13:23)
From: skaller <skaller@u...>
Subject: Re: [Caml-list] Incremental, undoable parsing in OCaml as the general parser inversion
On Thu, 2007-07-05 at 01:13 -0700, wrote:

> The beauty of delimited continuations is that we take any function
> that accepts some kind of `callback' and pass a specifically
> constructed callback (which is essentially shift f f). Thus we have
> accomplished inversion. The function in question can be a map-like
> traversal combinator (the callback is the function to map), a parser
> (the callback here is the stream, the function that provides data to
> the parser), a GUI system with its own event loop, etc.

Unfortunately what you need for a GUI is not control
inverting the callback -- programmers in industry do that
every day: it's an extremely common task.

Of course the way they do it is naive and laborious.

But it isn't the real problem.. it's the GUI event loop
that needs to be inverted.

Luckily that can be done for both X- and MS- Windows by
the simple expedient of not writing an event loop in the
first place!! In both systems, there is no event loop.
The API provides a function to read the message queue --
writing an event loop is the users job .. so inverting
it is easy .. just don't write it!

Unfortunately .. doing that throws away all the GUI toolkits
out there -- GTK is gone, for example. They were all written
the wrong way ..

Rewriting GTK in a monadic style is not going to be
so easy .. it's rather a lot of code and much of the
interface is *based* on the standard C model, where
continuations are passed by pushing the return address
implicitly onto the machine stack.

Luckily .. most of the work done in a GUI tool kit can be
done much better using Open GL anyhow .. and OpenGL is
algorithmic not event driven. In particular SDL is
also algorithmic, not even driven.

So .. if you really want to invert GTK .. you are left
with the system supported control inversion device,
which is more or less universal and works with some
C code at least .. Posix threads.

After all the *primary* job of an operating system
is precisely control inversion.

John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: