English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    
Browse thread
Language Design
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: John Max Skaller <skaller@m...>
Subject: Re: Language Design
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