<div dir="ltr">Jeremy,<div><br></div><div>Your interface is kind of cool! There's something kind of fun about your futures. However, I do think it adds complexity that perhaps is not needed.</div><div><br></div><div>I actually like the approach you suggested (earlier on this thread) of using an abstract type and hand-creating accessors to the needed fields. I like this approach because it does not add new ideas to the client's head. Specifically, it would reuse the notion of an abstract type (which they already are familiar with). Then the user needs to 1) ferry the size of the type into Ocaml (my example does not currently do this, but this is straightforward) and 2) generate the accessor functions (<a href="https://github.com/trevorsummerssmith/ocaml-libuv/blob/test-lifecycle/lib_gen/libuv_accessor_gen.ml">accessor generation</a>, <a href="https://github.com/trevorsummerssmith/ocaml-libuv/blob/test-lifecycle/lib_gen/libuv_bindings.ml#L267">ml accessors</a>). The code I wrote is a straightforward proof of concept that repeats a lot of information. </div><div><br></div><div>However, *hand wave*, I think cstubs could be extended in a relatively straightforward manor to generate this staged information, without introducing new paradigms into the cstubs interface.</div><div><br></div><div>Thoughts? Thanks.</div><div><br></div><div>Trevor</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Nov 3, 2014 at 10:45 AM, Jeremy Yallop <span dir="ltr"><<a href="mailto:yallop@gmail.com" target="_blank">yallop@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 30 October 2014 12:34, Trevor Smith <<a href="mailto:trevorsummerssmith@gmail.com">trevorsummerssmith@gmail.com</a>> wrote:<br>
> Thanks for this work! I just got a chance this morning to take a look. This<br>
> work should save me a ton of time.<br>
><br>
> I'm having problems referencing a cstub'd struct within another cstub'd<br>
> struct. Looking at the types it doesn't seem that this would work - the<br>
> cstubs typ is different than the Ctypes.typ. I reproduced a tiny example in<br>
> the cstubs test files (diff below).<br>
<br>
</span>Right: this is a difficulty with the current approach. You can work<br>
round it, of course, by generating each struct via a separate functor,<br>
but that's terribly clunky, especially where there are self references<br>
involved.<br>
<br>
We really need to embrace the fact that the stub generation approach<br>
involves staging, and make that explicit in the interface somehow.<br>
David Sheets and I have considered adding an 'applicative' for staging<br>
in the past, but I've been reluctant because it makes the interface<br>
more complicated.<br>
<br>
An interface with staging might work as follows: values, and<br>
specifically values that represent types, are classified as either<br>
'present' or 'future' according to whether we know about them now or<br>
whether we have to generate some code to learn about them. For<br>
example, 'int' is present, since we know its size etc. now, but<br>
'struct uv_loop_s' is future: we have to generate some C code to<br>
determine its properties. Present values can be used to build either<br>
present or future values, but future values can only be used to build<br>
future values: we don't get access to the future in advance.<br>
<br>
The interface looks like this:<br>
<br>
<a href="https://github.com/yallop/ocaml-ctypes/blob/staged-struct-stubs/src/cstubs/cstubs_structs.mli" target="_blank">https://github.com/yallop/ocaml-ctypes/blob/staged-struct-stubs/src/cstubs/cstubs_structs.mli</a><br>
<br>
There are a couple of extra functions !^ and <*> for lifting present<br>
values into the future and for future application, and the structure,<br>
union, etc. functions now create future typ values rather than values<br>
of an abstract type. In practice it looks much the same as before,<br>
except for a little extra syntactic noise when you use a present value<br>
in a future definition -- for example, when you build a future struct<br>
definition with an int field:<br>
<br>
<a href="https://github.com/yallop/ocaml-ctypes/blob/staged-struct-stubs/src/cstubs/cstubs_structs.mli#L16-L17" target="_blank">https://github.com/yallop/ocaml-ctypes/blob/staged-struct-stubs/src/cstubs/cstubs_structs.mli#L16-L17</a><br>
<br>
Is this approach intelligible? Overly complex? Thoughts welcome.<br>
</blockquote></div><br></div>