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

Re: [MirageOS-devel] COW XML questions



On 5 Jan 2015, at 15:56, Thomas Gazagnaire <thomas@xxxxxxxxxxxxxx> wrote:
> 
> Hi,
> 
>> Some of the field names in the XML are not valid or idiomatic OCaml
>> record fields, for example they might be capitalized. Is there an
>> easyish way to get COW to do things like the following?
>> 
>> type t = {foo: int; bar: string} with xml;;
>> xml_of_t {foo=0; bar="hello"};
>> # yields <:xml< <Bar>hello</Bar> <Foo>0</Foo> >>
> 
> I think the COW deriving extensions are pretty dumb, so this is not possible 
> directly.
> 
> However you can write your own converter:
> 
> let xml_of_t { foo; bar } = <:xml< <Bar>$str:bar$</Bar> <Foo>$int:foo$</Foo> 
> >>

It's worth remembering this trick in general for all the type_conv-driven code 
generators, including sexp generation.

We talk about briefly in Real World OCaml in the s-expression section:

https://realworldocaml.org/v1/en/html/data-serialization-with-s-expressions.html#idm181611773136

-anil
_______________________________________________
MirageOS-devel mailing list
MirageOS-devel@xxxxxxxxxxxxxxxxxxxx
http://lists.xenproject.org/cgi-bin/mailman/listinfo/mirageos-devel


 


Rackspace

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