From: Ian Campbell Subject: Re: [PATCH v2-resend 08/30] libxl: ocaml: support for KeyedUnion in the bindings generator. Date: Tue, 27 Aug 2013 16:28:49 +0100 Message-ID: <1377617329.29147.65.camel@kazak.uk.xensource.com> References: <1377168678-25492-1-git-send-email-rob.hoes@citrix.com> <1377168678-25492-9-git-send-email-rob.hoes@citrix.com> <21020.49438.73224.754027@mariner.uk.xensource.com> <1377616420.29147.60.camel@kazak.uk.xensource.com> <21020.50101.849234.536197@mariner.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <21020.50101.849234.536197@mariner.uk.xensource.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Ian Jackson Cc: Rob Hoes , xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org On Tue, 2013-08-27 at 16:20 +0100, Ian Jackson wrote: > Ian Campbell writes ("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: > > > 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. > > That's what I thought. So this part is wrong then ? You didn't quote this part ;-) > ] We generate C: > ] > ] enum { FOO, BAR } foo; I meant "enum foo { BAR, BAZ };" here. > > > > 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. > > So we generate > type blargle__union = Bar of blargle_bar | Baz; > ? If this is legal ocaml syntax, then fine, I guess. Not just legal but idiomatic too, I think. > (I can't remember what "of" does here.) I'm not sure what the proper name would be (a KeyedUnion maybe ;-)) it means you can unpick it with: match a_blargle with | Bar of thing -> do stuff with the content of thing | Baz -> do other stuff, not with thing (modulo me not remembering the real syntax, but it's close) Ian.