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-28 (11:57)
From: Oliver Bandel <oliver@f...>
Subject: Re: [Caml-list] The Bridge Pattern in OCaml
Hey Jim,

Zitat von Jim Farrand <jim.farrand@gmail.com>:

> On 28/03/2008, Michael Wohlwend <micha-1@fantasymail.de> wrote:
> > I would make my own format with a version number.
> >  Maybe:
> >  a complicated binary format,
> >  a more text like format like json or yaml or xml *schockhorror*
> >  or use a small db for storing, like sqlite.
> But how would you encode an O'Caml function/closure as, say, XML?  As
> far as I know this isn't possible.
> My point is, I want to find some compromise between:
> - Representing behaviour as closures (very flexible, but not
> serializable), and
> - Representing behaviour without closures (serializable, but with
> huge
> loss of flexibility wrt. what the behaviour implementations can do -
> ie, the framework would have to predict in advance what kind of
> things
> the implementations might want to do in order to provide an encoding
> flexible enough).

If you create your closures not hard-coded,
but instead create them by program (from
a limited set of hardcoded closures), then you have
the way you created it at hand. Call it an "AST" if you want,
or give it a different name.

What I mean is: you can call a closure a closure, or you
can call it a partial applicated function. If you call it
a partial applicated function, IMHO it's easier to understand,
how to build up things from the bottom up to the top.

If you create your functions from bottom to top,
you also could create an AST (if you like this term) from it.
Or possibly you already have such a datastructure at hand...
...then you can build up the conglomerated functions from it.

The functionality that you have at hand then with your conglomerated
funcions, will have a corrosponding linearization when writing things to
the file ("will have", if you code it).

I have no completely elaborated explanation of it.
Possibly I should do this, when I have some time for it.
(If I would be a computer-scientist, I may already would have been
written a paper on it.)
But I have done such composition of functionality in one of my tools.
So I have some OCaml code.

Here is, how I did it:
I have an input language, use ocamllex and ocamlyacc to parse
it, and in the ocamlyacc actions I used that partial application
technique to build up functionality from bottom to top.

I don't know if this way is one that the OCaml-Gurus or the
Object.magicians would also recommend, ;-)  but for my purposes
it worked fine.

I did not needed to write corresponding linearized things to a file
(which seems to be your main problem here), so this was not
But IMHO this should be possible also in the same manner as one creates
the conglomerated functions. (Not prooved so far; it's an idea only.)

If you don't understand, what I'm talking about,
I could send you the link to the code.

If you understand, what I mean: does this make sense to you,
can you use that way for solving your problem?