Version française
Home     About     Download     Resources     Contact us    
Browse thread
A C to OCaml helper ?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Basile STARYNKEVITCH <basile@s...>
Subject: Re: [Caml-list] A C to OCaml helper ?
Fabrice Marchant wrote:
> On Wed, 12 Mar 2008 22:03:51 +0100
> Basile STARYNKEVITCH <basile@starynkevitch.net> wrote:
> 
>> Fabrice Marchant wrote:
>>> Please does it exist some tool that could do at least the very mechanical first parts of the translation of a C source to OCaml ?
>> Why do you want to do that?
> 
> Why do I want a tool to do the _very mechanical parts_ of the job ?
>   A simple example :
> because I would be happy to get the comment brackets automatically translated ( and the C++ like C extension // too.)
>   There are several such very automatic things like if( ) -> if then.
> 
>> You could call most of your C routines from Ocaml.
>   Yes, but in the present case, I'm interesting in a full rewriting. This is precisely because I imagine to be able to rewrite the C ( game ) program a very different and terse way, that I undertake this task.
> 
>> And most importantly, the main interest of ocaml is the way of thinking 
>> it.
> Absolutely : that's the reason why I play to rewrite the C program an OCaml way.

Then you have to rewrite it manually, because you have to re design your 
program differently (in a functional way). In particular, functional 
values are very common in Ocaml, and do not exist as such in C (a C 
pointer function is *not* a closure, you have to bring it some data); 
and combining both is done manually: callbacks, signal & slots [like in 
QT or GTK], etc...

Also, in Ocaml you frequently have tiny functions : just look at how 
easily you can sort an array of records of person's first & last names 
in Ocaml (it really fits in one or two lines), and how it become harder 
in C.

 >  However, I remember you are the man who oriented me to OCaml and I'm 
 > very grateful of this, because OCaml programming is a real pleasure

So you learnt that Ocaml programming paradigms are different from those 
in C.

I'm really not convinced that any automatic tool could bring you 
something valuable. Because tools do not help to re design (not only 
refactor or translate) programs.

And my advice is even to avoid doing any immediate translation by hand. 
Do not look often at your C code, but redesign your game (and your 
former experience in C game coding would help you). Perhaps this could 
be done incrementally, by keeping some routines in C (and calling them 
from Ocaml).

-- 
Basile STARYNKEVITCH         http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mines, sont seulement les miennes} ***