[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH v2-resend 08/30] libxl: ocaml: support for KeyedUnion in the bindings generator.



On Tue, 2013-08-27 at 16:09 +0100, Ian Jackson wrote:
> Rob Hoes writes ("[Xen-devel] [PATCH v2-resend 08/30] libxl: ocaml: support 
> for KeyedUnion in the bindings generator."):
> > A KeyedUnion consists of two fields in the containing struct. First an
> > enum field ("e") used as a descriminator and second a union ("u")
> > containing potentially anonymous structs associated with each enum
> > value.
> ...
> > foo = Enumeration("foo", [
> >     (0, "BAR"),
> >     (1, "BAZ"),
> > ])
> > s = Struct("s", [
> >     ("u", KeyedUnion(none, foo, "blargle", [
> >         ("bar", Struct(...xxx...)),
> >         ("baz", Struct(...yyy...)),
> 
> I think you have some confusion betwwen bar,baz and foo,bar ?  At
> least, I hope so, as otherwise I haven't understood at all.

I don't think so, foo is an enumeration with possible values of "bar"
and "baz".

The keyed union has a discriminator (called blargle in this example)
which is of type "enum foo". There is then an anonymous union with two
members, "bar" and "baz" corresponding to the possible values of
blargle.

> 
> > and map this to ocaml
> > 
> > type foo = BAR | BAZ;
> > module S = struct
> >     type blargle_bar = ...xxx...;
> >     type blargle_baz = ...yyy...;
> >     type blargle__union = Bar of blargle_bar | Baz of blargle_baz;
> >     type t =
> >     {
> >         blargle : blargle__union;
> >     }
> > end
> 
> Is this indirection (through S.t) really needed ?  It seems a bit
> ugly.  But I'm no expert on ocaml syntax or style.

It's the common idiom in ocaml, for a reason I cannot remember. 

> 
> > These type names are OK because they are already within the namespace
> > associated with the struct "s".
> > 
> > If the struct associated with bar is empty then we don't bother with
> > blargle_bar of "of blargle_bar".
> 
> I'm not sure I follow this observation.

In the type blargle__union we don't bother with the "of blargle_bar"
case of the corresponding struct is empty.

> I don't intend to review the actual generator and will instead take on
> trust that it does what you say :-).

Ack!



_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.