From: Ian Campbell Subject: Re: [PATCH 1 of 4] xl: idl: Abolish keyed union types Date: Thu, 6 Jan 2011 18:55:37 +0000 Message-ID: <1294340137.13733.58.camel@localhost.localdomain> References: <5a8c843ab94a38df32e5.1294234913@localhost6.localdomain6> <19750.597.357993.810638@mariner.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <19750.597.357993.810638@mariner.uk.xensource.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Ian Jackson Cc: "xen-devel@lists.xensource.com" , Gianni Tedesco , Stefano Stabellini List-Id: xen-devel@lists.xenproject.org On Thu, 2011-01-06 at 17:56 +0000, Ian Jackson wrote: > Gianni Tedesco writes ("[Xen-devel] [PATCH 1 of 4] xl: idl: Abolish keyed union types"): > > xl: idl: Abolish keyed union types > > > > Since the IDL file has become useful for generating language > > bindings it has become apparent that the KeyedUnion type has no > > straightforward translation to scripting languages which have no > > notion of unions. > > Uhh? Most scripting languages' aggregate types are practically > nothing _but_ unions! > > The correct translation of a keyed union would probably be an > aggregate (eg, in Python, a dictionary) containing an entry for the > key and entries for whatever version of the union it involved. The union type ends up looking quite nice in the ocaml bindings too: type build_spec = BuildHVM of build_hvm_info | BuildPV of build_pv_info which allows nice ocaml idiomatic stuff like match build with | BuildHVM hvm -> do_some_hvm_stuff hvm | BuildPV pv -> do_some_pv_stuff pv > > Turns out this is only used in domain_build_info which is hardly a memory > > criticial structure. > > However I don't have a strong opinion about the desirability of using > a tagged union for this particular structure. Me neither. That ocaml stuff currently hand coded (and no one is imminently working on changing that to my knowledge) so I don't think the libxl API change arising from this IDL change prevents retaining this interface but it does suggest why having the notion of a key which selects between alternative fields could be a semantically useful concept in the interface. If having KeyedStruct instead of KeyedUnion simplifies things that could be an alternative. Or go the whole hog and define a Dict type (turns into an enum + the relevant number of fields)? Or just nuke it and cross the bridge when we come to it ;-). Ian.