caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: micha-1@fantasymail.de
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] question about how to bind c++ classes to ocaml
Date: Mon, 14 Aug 2006 17:45:01 +0900 (JST)	[thread overview]
Message-ID: <20060814.174501.82090269.garrigue@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <20060814071715.183780@gmx.net>

From: "Michael Wohlwend" <micha-1@fantasymail.de>

> > Calls from ocaml to C are very cheap. If your access function doesn't
> > do any allocation (i.e. never calls the GC), you can even make it
> > faster by marking it as "noalloc". Beware many functions do
> > allocate, including copy_double or copy_string.
> 
> thanks for pointing this out. The "noalloc"-thing isn't really
> described in the docu? :-)

I suppose this is because it is a bit tricky. You have to look at all
the dependencies to be sure that the function will never trigger the
GC, and you might easily get it wrong.

> Another question which came up was: you can only declare normal
> functions (not methods) as "external", so you have to write a c
> function for every c++ member function. Do you rebuild the
> inheritance hierachy somehow through the type system (maybe with
> those mysterious phantom types?) or just put an ocaml class system
> on top of it? 

My approach in lablgtk was to first use phantom types, ie use
parameters in abstract types to simulate subtyping. Then there is a
second layer using ocaml objects, but I'm not sure you need it in
general. It isonly needed because GTK+ has so many classes that it is
difficult to track which function comes from which class.

In Labltk for instance, there are only phantom types, and without
subtyping (it uses a coercion function "coe" instead). This works well
if you have a hierarchy with few layers (only two in labltk)

Cheers,

Jacques Garrigue


      reply	other threads:[~2006-08-14  8:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-13 20:47 micha
2006-08-14  0:20 ` [Caml-list] " Jacques Garrigue
2006-08-14  7:04   ` Jonathan Roewen
2006-08-14  7:17   ` Michael Wohlwend
2006-08-14  8:45     ` Jacques Garrigue [this message]

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=20060814.174501.82090269.garrigue@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@yquem.inria.fr \
    --cc=micha-1@fantasymail.de \
    /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).