caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Kuba Ober <ober.14@osu.edu>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] A C to OCaml helper ?
Date: Mon, 17 Mar 2008 14:07:09 -0500	[thread overview]
Message-ID: <200803171507.10069.ober.14@osu.edu> (raw)
In-Reply-To: <47D8CCA1.9020502@starynkevitch.net>

On Thursday 13 March 2008, Basile STARYNKEVITCH wrote:
> 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).

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


  reply	other threads:[~2008-03-17 19:07 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-12 19:42 Fabrice Marchant
2008-03-12 20:51 ` [Caml-list] " Richard Jones
2008-03-12 21:03 ` Basile STARYNKEVITCH
2008-03-12 21:09   ` Fabrice Marchant
2008-03-13  6:41     ` Basile STARYNKEVITCH
2008-03-17 19:07       ` Kuba Ober [this message]
2008-03-17 20:33         ` Sylvain Le Gall
2008-03-13  1:56 ` [Caml-list] " Christopher L Conway
2008-03-13  3:14 ` Jon Harrop

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200803171507.10069.ober.14@osu.edu \
    --to=ober.14@osu.edu \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).