From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id IAA18696 for caml-red; Mon, 28 Aug 2000 08:57:46 +0200 (MET DST) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id AAA11410 for ; Mon, 28 Aug 2000 00:22:59 +0200 (MET DST) Received: from localhost.localdomain (brian-boitano151.zip.com.au [210.23.147.151]) by nez-perce.inria.fr (8.10.0/8.10.0) with ESMTP id e7RMMqr14614; Mon, 28 Aug 2000 00:22:54 +0200 (MET DST) Received: from maxtal.com.au (IDENT:root@localhost [127.0.0.1]) by localhost.localdomain (8.9.3/8.8.7) with ESMTP id JAA11203; Mon, 28 Aug 2000 09:21:55 +1100 Message-ID: <39A99483.A1EDD4BC@maxtal.com.au> Date: Mon, 28 Aug 2000 09:21:55 +1100 From: John Max Skaller X-Mailer: Mozilla 4.7 [en] (X11; I; Linux 2.2.12-20 i686) X-Accept-Language: en MIME-Version: 1.0 To: Jerome Vouillon CC: Francois.Pottier@inria.fr, caml-list@inria.fr Subject: Re: Language Design References: <000d01c00bb8$fb3e3560$210148bf@dylan> <39A36758.E474CC1E@maxtal.com.au> <20000824111226.28393@pauillac.inria.fr> <39A58286.81AEAF47@maxtal.com.au> <20000825174159.39156@pauillac.inria.fr> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: weis@pauillac.inria.fr Jerome Vouillon wrote: > I think you should really consider using monads. Here is an example. I will have to study this example in more detail: thank you very much for spending the time writing it. My translator generates C++, but it looks as if the generated code follows the pattern below. > We define a value of type void to be either a continuation expecting a > string or a final function that do not expect anything. > > type void = Cont of (string -> void) > | Term of (unit -> unit) > > This is a procedure that does nothing. My equivalent: a pointer to a C++ object of class 'continuation_t' is returned when reading is desired, the dispatcher comes back later with the message and stores it in the continuation object. If there is no work to do, the routine returns a null pointer. In fact, each procedure call returns control, and a flag tells whether a read is desired, or whether to call the returned continuation immediately. > We can try this procedure. First we define an evaluator. It takes the > input stream and a procedure call as inputs. > > let rec eval l p = > match l, p with > _, Term t -> t () > | s :: r, Cont c -> eval r (c s) > | _ -> ((* Stuck evaluation *)) > > Then we evaluate read2 when two strings "a" and "b" are given as > input: > > let x = ref "" in eval ["a"; "b"] (read2 x); !x This is very nice. It's much less code than my C++ version :-) -- John (Max) Skaller, mailto:skaller@maxtal.com.au 10/1 Toxteth Rd Glebe NSW 2037 Australia voice: 61-2-9660-0850 checkout Vyper http://Vyper.sourceforge.net download Interscript http://Interscript.sourceforge.net