From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: ** X-Spam-Status: No, score=2.8 required=5.0 tests=AWL,DNS_FROM_RFC_POST, SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 19E44BC37 for ; Wed, 30 Sep 2009 16:28:16 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AskBAM8Hw0rRVd+2mWdsb2JhbACPV4ppPwEBAQEBCAsKBxOta5AFAQMDBYQiBIFNhlA X-IronPort-AV: E=Sophos;i="4.44,480,1249250400"; d="scan'208";a="37183062" Received: from mail-iw0-f182.google.com ([209.85.223.182]) by mail1-smtp-roc.national.inria.fr with ESMTP; 30 Sep 2009 16:28:15 +0200 Received: by iwn12 with SMTP id 12so3309036iwn.1 for ; Wed, 30 Sep 2009 07:28:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:in-reply-to :references:date:x-google-sender-auth:message-id:subject:from:to:cc :content-type:content-transfer-encoding; bh=vn018ulA0B3zWZ9j2jEK4eDWSoW8zQ1AQm3t3UjClm8=; b=UerBRziNoUBarxCWVPF8j/vCIy/q2n0V/epKTX78yd5FhJ1spyf9iRGit+nlgeaiVp 6DbZQB3Q0q/i7hXSXDaShQJKMzio0QkbfbCuZtb+xjutR2Fl1IfWubVrXO9GHGuAXYfh fZxAH4+ai6HJy4KL3VEHTb7R0CY3m8+xBNwKs= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=Nwa8qdCYvB0PXOFOxA8cL3EdmB7lNN3Am4Ff4go08wNQMNzxpST98mtt5BxsuaV3wv +kYUHpQt6apVA8eodlfzD9HwT0u4Gtr+YpJzWiQw1yko1J8DkOoPHeciIWIpssSPKN0/ b56qhitXsufbCNLzS/NRuKe5x9ev1Trmk23go= MIME-Version: 1.0 Sender: till.varoquaux@gmail.com Received: by 10.231.122.208 with SMTP id m16mr11586592ibr.16.1254320894298; Wed, 30 Sep 2009 07:28:14 -0700 (PDT) In-Reply-To: <20090930140107.GB5126@annexia.org> References: <20090930101622.GA15517@annexia.org> <245077.49646.qm@web111516.mail.gq1.yahoo.com> <20090930115723.GL1104@annexia.org> <20090930125904.GA5126@annexia.org> <9d3ec8300909300633t51db9ed9jf3ad15e6b0551c1e@mail.gmail.com> <20090930140107.GB5126@annexia.org> Date: Wed, 30 Sep 2009 10:28:14 -0400 X-Google-Sender-Auth: 1032a8dcb057034a Message-ID: <9d3ec8300909300728t6edb78e3w447fa06358942edf@mail.gmail.com> Subject: Re: [Caml-list] xpath or alternatives From: Till Varoquaux To: Richard Jones Cc: caml-list@inria.fr Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Spam: no; 0.00; node:01 node:01 ocamlduce:01 xduce:01 ocaml:01 ocamlduce:01 casts:01 runtime:01 ocaml's:01 subtyping:01 prerr:01 endline:01 prerr:01 endline:01 usr:01 If I am not mistaken you are selecting a domain whose first child is a device node whose only child is disk node ... instead of: [[[_]]] you should aim for something in the vein of: [_* ( ((| _)* |_)* _*] Till On Wed, Sep 30, 2009 at 10:01 AM, Richard Jones wrote: > 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: >> >> =C2=A0let devs =3D match xml with >> =C2=A0 =C2=A0| {{ [[[]]= ] }} -> {:dev:} >> =C2=A0 =C2=A0| {{ [[[= ]]] }} -> >> {: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 level inside ), so: > > =C2=A0let xml =3D from_string xml in > =C2=A0prerr_endline (Ocamlduce.to_string xml); > > =C2=A0let devs =3D {{ map [xml] with > =C2=A0 =C2=A0| [[[_]]] > =C2=A0 =C2=A0| [[[_]]] -> [s] > =C2=A0 =C2=A0| _ -> [] }} in > =C2=A0prerr_endline (Ocamlduce.to_string devs); > > +1 : this compiles > -1 : it doesn't work, devs is empty > > This is what the first prerr_endline prints: > > =C2=A0type=3D"kvm" > =C2=A0id=3D"2">[ > =C2=A0[ 'CentOS5x32' ] > =C2=A0[ '2ce397d9-1931-feb1-8ad8-15f22c4f18af' ] > =C2=A0[ '524288' ] > =C2=A0[ '524288' ] > =C2=A0[ '1' ] > =C2=A0[ [ 'hvm' ] [ ] ] > =C2=A0[ [ ] [ ] [ ] ] > =C2=A0[ ] > =C2=A0[ 'destroy' ] > =C2=A0[ 'restart' ] > =C2=A0[ 'restart' ] > =C2=A0[ > =C2=A0 =C2=A0[ '/usr/bin/qemu-kvm' ] > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0type=3D"block" > =C2=A0 =C2=A0 =C2=A0device=3D"disk">[ > =C2=A0 =C2=A0 =C2=A0[ ] > =C2=A0 =C2=A0 =C2=A0[ ] > =C2=A0 =C2=A0 =C2=A0] > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0type=3D"network">[ > =C2=A0 =C2=A0 =C2=A0[ ] > =C2=A0 =C2=A0 =C2=A0[ ] > =C2=A0 =C2=A0 =C2=A0[ ] > =C2=A0 =C2=A0 =C2=A0] > =C2=A0 =C2=A0[ [ ] [ ] ] > =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0type=3D"pty" > =C2=A0 =C2=A0 =C2=A0tty=3D"/dev/pts/7">[ > =C2=A0 =C2=A0 =C2=A0[ ] > =C2=A0 =C2=A0 =C2=A0[ ] > =C2=A0 =C2=A0 =C2=A0] > =C2=A0 =C2=A0[ ] > =C2=A0 =C2=A0[ ] > =C2=A0 =C2=A0