/[svn]/web/demo.xml
ViewVC logotype

Diff of /web/demo.xml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1412 by abate, Tue Jul 10 18:47:35 2007 UTC revision 1413 by abate, Tue Jul 10 18:47:42 2007 UTC
# Line 6  Line 6 
6  <title>CDuce demo</title>  <title>CDuce demo</title>
7    
8  <box title="Types, pattern matching" link="typpm">  <box title="Types, pattern matching" link="typpm">
9  <demo><include-verbatim file="funxml_types.cd"/><![CDATA[  <demo><![CDATA[
10    type Bib = [ Book* ]
11    type Book = <book>[ Title Subtitle? Author+ ]
12    type Title = <title>[ PCDATA ]
13    type Subtitle = <subtitle>[ PCDATA ]
14    type Author = <author>[ PCDATA ]
15    
16  let title(Book -> String)  <book>[ <title>x _* ] -> x  let title(Book -> String)  <book>[ <title>x _* ] -> x
17  let authors(Book -> [Author+]) <_>[ (x::Author|_)* ] -> x  let authors(Book -> [Author+]) <_>[ (x::Author|_)* ] -> x
18  ]]></demo></box>  ]]></demo></box>
# Line 21  Line 27 
27              <author>[ 'Atkinson' ]              <author>[ 'Atkinson' ]
28              <author>[ 'Benzaken' ]              <author>[ 'Benzaken' ]
29              <author>[ 'Maier' ] ]              <author>[ 'Maier' ] ]
30  let v : Bib = [ b1 b2 ]  let bib : Bib = [ b1 b2 ]
31  ]]></demo></box>  ]]></demo></box>
32    
33  <box title="Printing functions" link="printfun"><demo prefix="last"><![CDATA[  <box title="Printing functions" link="printfun"><demo prefix="last"><![CDATA[
# Line 33  Line 39 
39  let set(<book>c : Book)(f : FBook) : ABook = <book print=f>c  let set(<book>c : Book)(f : FBook) : ABook = <book print=f>c
40  let prepare(b : Bib) : ABib = map b with x -> set x title  let prepare(b : Bib) : ABib = map b with x -> set x title
41    
42  let b : Bib =  let abib = prepare bib
43   [ <book>[ <title>"T" <subtitle>"S" <author>"A" ] ]  ]]></demo></box>
44    
45    <box title="Display" link="display"><demo prefix="last"><![CDATA[
46    type Ul = <ul>[ Li+ ]
47    type Li = <li>[ PCDATA ]
48    
49    let display (ABib -> Ul; ABook -> Li)
50     | <book print=f>_ & x -> <li>(f x)
51     | [] -> raise "Empty bibliography"
52     | p -> <ul>(map p with z -> display z)
53    
54  let ab = prepare b  let d = display abib
55  ]]></demo></box>  ]]></demo></box>
56    
57    <box title="Changing the style" link="style"><demo prefix="last"><![CDATA[
58    let change(p : Book -> Bool)(f : FBook)(b : ABib) : ABib =
59     map b with x -> if (p x) then set x f else x
60    
61    type HasSub = <_>[ _* Subtitle _* ]
62    
63    let subtitle(Book & HasSub -> String)
64      <book>[ _* <subtitle>x _* ] -> x
65    
66    let change_sub =
67    change
68     (fun (Book -> Bool) HasSub -> `true | _ -> `false)
69     (fun (b : Book) : String =
70       title b @ ": " @ subtitle (b :? HasSub))
71    
72    
 <!--  
 #silent  
73    
 #verbose  
74    
75  let z = authors b1  ]]></demo></box>
 ]]>  
 </demo>  
 </box>  
 -->  
76    
77  <!--  <!--
78  <box title="XML elements" link="xml">  <box title="XML elements" link="xml">

Legend:
Removed from v.1412  
changed lines
  Added in v.1413

CVS Admin">CVS Admin
ViewVC Help
Powered by ViewVC 1.1.5