Browse thread
Wrapping OCaml function returning a variant
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2007-03-28 (11:52) |
From: | Serge Aleynikov <serge@h...> |
Subject: | Re: [Caml-list] Wrapping OCaml function returning a variant |
Joel Reymont wrote: > Is there an example of returning a variant from OCaml into C somewhere? > It's a regular variant, declared like this > > type morpher_output = > | Success of string > | Error of string * int * int * int You can read the section 18.3.4 of http://caml.inria.fr/pub/docs/manual-ocaml/manual032.html Then if still unclear, examine: http://oracaml.sourceforge.net/ or any other C-interface library available on Caml Hump: http://caml.inria.fr/cgi-bin/hump.en.cgi?sort=0&browse=65 > The other issue is that I don't know how to deal with strings allocated > in OCaml. Will they be collected automatically? If you are using caml_copy_string() or caml_alloc_string() they allocate strings on OCaml's heap, and will be automatically garbage collected. > The strings _must_ be allocated in OCaml but I can guarantee that they > will not be modified in the C code. Any suggestions on how to deal with > this? Unless I am not understanding your question, the above two functions are the way to allocate strings on OCaml's heap. Serge