From: Ian Jackson Subject: Re: [PATCH v2-resend 08/30] libxl: ocaml: support for KeyedUnion in the bindings generator. Date: Tue, 27 Aug 2013 16:09:18 +0100 Message-ID: <21020.49438.73224.754027@mariner.uk.xensource.com> References: <1377168678-25492-1-git-send-email-rob.hoes@citrix.com> <1377168678-25492-9-git-send-email-rob.hoes@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1377168678-25492-9-git-send-email-rob.hoes@citrix.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: Rob Hoes Cc: ian.campbell@citrix.com, xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org 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. > 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. > 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. I don't intend to review the actual generator and will instead take on trust that it does what you say :-). Ian.