caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>
To: skaller@ozemail.com.au
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Possible use for camlp4
Date: Thu, 30 May 2002 11:42:06 +0900	[thread overview]
Message-ID: <20020530114206Z.garrigue@kurims.kyoto-u.ac.jp> (raw)
In-Reply-To: <3CF52B1F.2050004@ozemail.com.au>

From: John Max Skaller <skaller@ozemail.com.au>

> The idea is a file of hand written bindings which generate the C code
> necessary to wrap a C library. There are two outputs: the C glue code
> and the ocaml binding definitions.
> 
> The point is to use camlp4 to make it easier to write the C glue code,
> by inventing some language syntax which knows about the garbage
> collector, heap format, the macros needed to do all that, etc.
> 
> That is, the glue code isn't generated *automatically* from a C interface,
> like with SWIG. Instead, you have to write the glue code by hand,
> as you do now. The difference is that you write it in  a slightly
> higher level language than the ugly and error prone C/Ocaml macros
> system. In addition, the 'simplified' way of using those macros is sometimes
> very inefficient. [eg, making parameters and local variables gc roots
> when there is no need]

Why not.

> If there is one thing that Ocaml is perceived as needing more
> than anything else for industrial use, it's bindings to more C libraries.
> At present, writing them is very very expensive, and maintaining
> them is an even worse problem if the target C library is evolving
> eg GTK. So .. why not use ocamlp4 to help reduce the problem?

This can help, but a frequent misconception is that gluing is the main
problem with external libraries.
It is for beginners, but for experimented programmers, with a good set
of C macros and sane habits, that's the easy part.  Even cooperating
with the GC is not that hard (as long as you don't try to optimize too
much).

What is really difficult is fancy callback systems, and abstracting
the invariants from the C API (including allocation problems).
Both are hard problems, with very little automated support.
In both cases you must understand how the library works from informal
explanations (or quite often reading the source code) before starting
to code. If the library is very regular, or uses a specific language
like Tcl/Tk, you may end up with some way to speed-up the process, but
in general you need to go into details, and there are exceptions.

So, yes for making things easier, like ocamlidl does already for
instance, but there are no miracles: as long as the external world is
not strongly typed in a language we can understand, the process is
going to be painful.

      Jacques Garrigue
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  reply	other threads:[~2002-05-30  2:43 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-05-25  3:45 [Caml-list] What about polymorphic methods? Alessandro Baretta
2002-05-25  3:55 ` Jacques Garrigue
2002-05-25  5:42   ` John Prevost
2002-05-27 19:10   ` Alessandro Baretta
2002-05-27 18:22     ` John Max Skaller
2002-05-30  0:02       ` Alessandro Baretta
2002-05-27 18:27     ` [Caml-list] Possible use for camlp4 John Max Skaller
2002-05-27 18:35       ` Alexander V. Voinov
2002-05-27 19:33       ` Daniel de Rauglaudre
2002-05-29 19:25         ` John Max Skaller
2002-05-30  2:42           ` Jacques Garrigue [this message]
2002-05-30  8:15           ` Daniel de Rauglaudre
2002-05-27 19:37       ` Daniel de Rauglaudre
2002-06-02  8:34   ` [Caml-list] What about polymorphic methods? Lauri Alanko
2002-06-03 23:57     ` Jacques Garrigue
2002-06-08  9:52   ` [Caml-list] What about polymorphic methods Alessandro Baretta
2002-06-10 10:13     ` Jacques Garrigue

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=20020530114206Z.garrigue@kurims.kyoto-u.ac.jp \
    --to=garrigue@kurims.kyoto-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=skaller@ozemail.com.au \
    /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).