On Wed, Sep 30, 2009 at 09:33:07AM -0400, Till Varoquaux wrote: > OCamlduce (Alain correct me if I am wrong) basically maintains two > separate type systems side by side (the Xduce one and the Ocaml one). > This is done in order to make Ocamlduce maintainable by keeping a > clear separation. As a result you have to explicitly convert values > between type systems using {:...:}. These casts are type safe but do > lead to some work at runtime. > > Also note that ocaml's string are Latin1 and not String in the XML world. So: > > let devs = match xml with > | {{ <domain>[<devices>[<source dev=(Latin1 & dev) ..>[]]] }} -> {:dev:} > | {{ <domain>[<devices>[<source file=(Latin1 & file) ..>[]]] }} -> > {:file:} in > > Should work (I'm rusty and have nothing to check handy).
I tried variations on the above, but couldn't get it to work. ocamlduce is very fond of a mysterious error called "Error: Subtyping failed", which is very difficult for me to understand, and therefore must be absolutely impossible for someone not used to strong typing. This is where I'm heading at the moment (sorry, my previous example missed a <disk> level inside <devices>), so: let xml = from_string xml in prerr_endline (Ocamlduce.to_string xml); let devs = {{ map [xml] with | <domain..>[<devices..>[<disk..>[<source dev=(Latin1 & s) ..>_]]] | <domain..>[<devices..>[<disk..>[<source file=(Latin1 & s) ..>_]]] -> [s] | _ -> [] }} in prerr_endline (Ocamlduce.to_string devs); +1 : this compiles -1 : it doesn't work, devs is empty This is what the first prerr_endline prints: <domain type="kvm" id="2">[ <name>[ 'CentOS5x32' ] <uuid>[ '2ce397d9-1931-feb1-8ad8-15f22c4f18af' ] <memory>[ '524288' ] <currentMemory>[ '524288' ] <vcpu>[ '1' ] <os>[ <type arch="x86_64" machine="pc-0.11">[ 'hvm' ] <boot dev="hd">[ ] ] <features>[ <acpi>[ ] <apic>[ ] <pae>[ ] ] <clock offset="utc">[ ] <on_poweroff>[ 'destroy' ] <on_reboot>[ 'restart' ] <on_crash>[ 'restart' ] <devices>[ <emulator>[ '/usr/bin/qemu-kvm' ] <disk type="block" device="disk">[ <source dev="/dev/vg_trick/CentOS5x32">[ ] <target bus="ide" dev="hda">[ ] ] <interface type="network">[ <mac address="54:52:00:3c:76:11">[ ] <source network="default">[ ] <target dev="vnet0">[ ] ] <serial type="pty">[ <source path="/dev/pts/7">[ ] <target port="0">[ ] ] <console type="pty" tty="/dev/pts/7">[ <source path="/dev/pts/7">[ ] <target port="0">[ ] ] <input type="mouse" bus="ps2">[ ] <graphics autoport="yes" port="5900" type="vnc">[ ] <video>[ <model type="cirrus" vram="9216" heads="1">[ ] ] ] ] and what the second prerr_endline prints: "" Rich. -- Richard Jones Red Hat _______________________________________________ Caml-list mailing list. Subscription management: http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list Archives: http://caml.inria.fr Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs