From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.1 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id C5B27BBCA for ; Mon, 17 Mar 2008 20:07:13 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ao4FAG5e3kdDWxLC/2dsb2JhbACBWqZv X-IronPort-AV: E=Sophos;i="4.25,514,1199660400"; d="scan'208";a="8495111" Received: from ip67-91-18-194.z18-91-67.customer.algx.net (HELO server1.bertec.net) ([67.91.18.194]) by mail2-smtp-roc.national.inria.fr with ESMTP; 17 Mar 2008 20:07:13 +0100 Received: from kuba.bertec.net (kuba.bertec.net [192.168.2.16]) by server1.bertec.net (Postfix) with ESMTP id 3F47ECE06B for ; Mon, 17 Mar 2008 15:07:11 -0400 (EDT) From: Kuba Ober To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] A C to OCaml helper ? Date: Mon, 17 Mar 2008 14:07:09 -0500 User-Agent: KMail/1.9.6 (enterprise 0.20071204.744707) References: <20080312204217.3f5087e3@orange.fr> <20080312220938.236ba3d5@orange.fr> <47D8CCA1.9020502@starynkevitch.net> In-Reply-To: <47D8CCA1.9020502@starynkevitch.net> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200803171507.10069.ober.14@osu.edu> X-Spam: no; 0.00; ocaml:01 basile:01 basile:01 ocaml:01 translated:01 rewriting:01 pointer:01 callbacks:01 gtk:01 refactor:01 higher-level:01 ocaml's:01 cheers:01 utilize:98 utilize:98 On Thursday 13 March 2008, Basile STARYNKEVITCH wrote: > Fabrice Marchant wrote: > > On Wed, 12 Mar 2008 22:03:51 +0100 > > > > Basile STARYNKEVITCH 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). I disagree somewhat. A good starting point is to have mechanically-translated code that works, and then work on refactoring it to utilize what OCaml has to offer. In fact, C++ may provide much better translation results than C, since, if properly written, the C++ sources will utilize higher-level primitives that look better in OCaml. C is a really primitive language, by OCaml's standards ;) Cheers, Kuba