Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] create a closure in external C function?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2001-03-07 (00:22)
From: qrczak@k...
Subject: Re: [Caml-list] create a closure in external C function?
Tue, 06 Mar 2001 14:56:51 -0800, Chris Hecker <> pisze:

> On the C side, we'll use the ffcall trampoline/vacall interface
> to pass qsort the pointer to a function that calls back the caml
> function with the right parms.

I've just seen ffcall. callback is approximately what I wanted.

trampoline+vacall is evil. It uses a global variable; this is not
thread safe.

callback seems to be better, but still more kludgy than I expected.
I'm not sure if it's the right choice for OCaml; it should not be
*that* ugly. Especially if you statically know types of arguments,
which is the case I am talking about. Unfortunately it's very

I would like to have this functionality in OCaml's foreign function
interface, without forcing to rely on an inconvenient third-party

I'm not sure how it should look like, because OCaml has a different
approach to FFI than Haskell: the OCaml<->C glue is in C, where for
Haskell<->C the glue is in Haskell. So Haskell defines a mapping
from Haskell function types involving primitive types to C types,
and a special kind of declaration which defines converters from
Haskell functions to C function pointers of particular types. The
OCaml's approach would need to call the conversion from the C level,
in which case the compiler has no chance of generating stubs tailored
for a particular type but must offer a generic C interface with its
own way to describe C types.

 __("<  Marcin Kowalczyk *
  ^^                      SYGNATURA ZASTĘPCZA

To unsubscribe, mail  Archives: