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] Caml Wrappers
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2001-03-09 (18:48)
From: John Max Skaller <skaller@o...>
Subject: Re: [Caml-list] Caml Wrappers
Ravi Chamarty wrote:
> Hi ,
>  I am trying to write OCaml interfaces around a C library.  I tried
> looking at the Unix library and trying to understand it. However, I have
> much complex data types to deal with.I was wondering if anyone could help
> me out.
> Here is a signature of one of the C functions:
> an_flow_t *
> an_flow_create(void *mem, an_cred_t *cred, an_cpuspec_t *cspec,
>                 an_memspec_t *mspec, an_flowinit_func_t init,
>                 void *initarg, an_flowterm_func_t term)
> Each of these types are complex structures in C. How do I represent these
> in OCaml. Is it useful to use classes and methods? Or do I use abstract
> types to represent them ?

In the first instance, you should map these to tuples. Forget
at the Ocaml/C interface. Keep the mapping(s) as close to an isomorphism 
as possible.

If you then wish to provide Ocaml with a more abstract view, you can
provide an 'in Ocaml' abstraction layer, using modules or classes.

Take a careful look at which of your C structures requires modification
from the Ocaml side. This cannot be so easily done by a simple
pair of mappings. If you require extensive modification, you might
representing the C structure as a handle (abstract value), and using
functions to modify the underlying C structure directly.

For an extensive example of mappings, have a look at the mlgtk package.
Note that creating a binding to a C library with a large set of data
is a LOT of work.

John (Max) Skaller,
10/1 Toxteth Rd Glebe NSW 2037 Australia voice: 61-2-9660-0850
checkout Vyper
download Interscript
To unsubscribe, mail  Archives: