English version
Accueil     Ŕ propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis ŕ jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml ŕ l'adresse ocaml.org.

Browse thread
The Bridge Pattern in OCaml
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2008-03-29 (14:03)
From: Peng Zang <peng.zang@g...>
Subject: Re: [Caml-list] The Bridge Pattern in OCaml
Hash: SHA1

On Friday 28 March 2008 08:43:42 am Jim Farrand wrote:
> On 28/03/2008, Oliver Bandel <oliver@first.in-berlin.de> wrote:
> > Zitat von Michael Wohlwend <micha-1@fantasymail.de>:
> >
> >  Creating a datastrzucture, while creatzing the functionality.
> >  And later, when you want to serialize what you have build up,
> >  write that datastructure, you build by your own, to a file.
> >  and when rereading it, this means: re-create the functionality from the
> >  datastructure.
> >
> >  Isn't this, what is looked for, here?
> Yes, this definitely solves the problem and meets the requirements I
> specified.
> In Haskell, it would be very neat - define a Monad for composing the
> ASTs and then code just like you would any other Haskell program,
> you're just using a different Monad from normal.
> In O'Caml, a lot less neat because the user providing the behaviour
> suddenly isn't really coding the algorithm in O'Caml, but creating a
> data-structure that represents the computation.
> But still, it definitely gets the job done.

Forgive me if I'm missing something here, but couldn't you just use OCaml 

It appears to me that OCaml bytecode is perfect for your purposes.  It is, 
exactly, a serialized format for code.  So if your client wants to send you 
some arbitrary piece of code to run, tell them to compile it down to 
bytecode, send it over the wire, and then on your end, simply interpret the 
bytecode.  In fact you might be able to get away with just calling the 
current OCaml bytecode interpreter.

Or better yet, your client can just send you the plain ascii of the code and 
you can use the OCaml toplevel to interpret it.

(you may have to send the environment of the piece of code as well, but the 
environment is simply a big hashtable of (symbol, value) pairs.  Well, I 
say "value" but it may be a pointer to another piece of code or a pointer to 
a file with some raw data in it.)

If you are concerned with speed, you can do JIT compilation of 

Version: GnuPG v2.0.7 (GNU/Linux)