From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id TAA27204; Fri, 9 Mar 2001 19:48:40 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id TAA26861 for caml-list@pauillac.inria.fr; Fri, 9 Mar 2001 19:48:39 +0100 (MET) Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id QAA30761 for ; Thu, 8 Mar 2001 16:31:58 +0100 (MET) Received: from localhost.localdomain (kenny84.zip.com.au [61.8.18.212]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f28FVtD20737 for ; Thu, 8 Mar 2001 16:31:56 +0100 (MET) Received: from ozemail.com.au (IDENT:root@localhost [127.0.0.1]) by localhost.localdomain (8.9.3/8.8.7) with ESMTP id CAA12690; Fri, 9 Mar 2001 02:26:25 +1100 Message-ID: <3AA7A4A1.66405033@ozemail.com.au> Date: Fri, 09 Mar 2001 02:26:25 +1100 From: John Max Skaller X-Mailer: Mozilla 4.7 [en] (X11; I; Linux 2.2.12-20 i686) X-Accept-Language: en MIME-Version: 1.0 To: Ravi Chamarty CC: caml-list@inria.fr Subject: Re: [Caml-list] Caml Wrappers References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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 abstraction 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 then 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 consider 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 types is a LOT of work. -- John (Max) Skaller, mailto:skaller@maxtal.com.au 10/1 Toxteth Rd Glebe NSW 2037 Australia voice: 61-2-9660-0850 checkout Vyper http://Vyper.sourceforge.net download Interscript http://Interscript.sourceforge.net ------------------- To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr