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
[Caml-list] [ANN] The Missing Library
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-04-29 (03:01)
From: skaller <skaller@u...>
Subject: Re: [Caml-list] [ANN] The Missing Library
On Thu, 2004-04-29 at 11:56, Jon Harrop wrote:

> Can you give me a simple example where you are forced to use mutable state?

Implement List.rev by defining "revit" below:

List.iter revit lst

Note: you have also implemented something more.
You have also implemented: Array.to_rev_list

Array.iter revit arr

Your revit function is polyadic with respect
to the input data structure, the XXXX.iter
function is used to factor that out.

This property is also shared by the
'read/pull/control inverted/thread-like/
continuation passing' solution.

In fact, the two solutions are dual.
They do the same job.

For "full inversion" you need to also
invert the HOF. For example here is
the traditional master List.iter:

let iter f = function 
| h::t -> f h; iter f t 
| [] ->()

This is the desirable form. This is an algorithm
that writes its output: it is the caller.

The inverse is a supplier of list elements:

let make_supplier lst =
  let lst = ref lst in
  let get () = function
  | h :: t -> lst :=t; h
  | [] -> raise Not_found
in get

This is hard to write but allows the client
routine to get() elements.

Traditionally, algorithms had to be factored
so one of the cooperating pair of routines
had to be unnatural: one had to be master,
and the other slave.

This sux. You want BOTH to be masters.
You can clearly do that with two threads and
a monitor object (more precisely, coroutines).

Felix control inverts arbitrary procedural code
mechanically: that is, you write code that reads
data and it is translated into a callback.

Wouldn't you rather program an *active* agent
for your complex GUI widgets that a passive callback
driven one?

John Skaller,
voice: 061-2-9660-0850, 
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: