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

Contents of /web/demo.xml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1413 - (hide annotations)
Tue Jul 10 18:47:42 2007 UTC (5 years, 10 months ago) by abate
File MIME type: text/xml
File size: 4422 byte(s)
[r2005-01-06 17:09:37 by afrisch] Demo

Original author: afrisch
Date: 2005-01-06 17:09:38+00:00
1 abate 1384 <?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>
2 abate 1411 <!DOCTYPE page [
3     <!ENTITY leq "&#x2264;"> <!-- LESS_THAN OR EQUAL TO -->
4     ]>
5     <page name="demo">
6 abate 1384 <title>CDuce demo</title>
7    
8 abate 1411 <box title="Types, pattern matching" link="typpm">
9 abate 1413 <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 abate 1411 let title(Book -> String) <book>[ <title>x _* ] -> x
17     let authors(Book -> [Author+]) <_>[ (x::Author|_)* ] -> x
18 abate 1412 ]]></demo></box>
19 abate 1411
20 abate 1412 <box title="Sample values" link="samp"><demo prefix="last"><![CDATA[
21     let b1 : Book = <book>[
22     <title>[ 'Object-Oriented Programming' ]
23     <subtitle>[ 'A Unified Foundation' ]
24     <author>[ 'Castagna' ] ]
25     let b2 : Book = <book>[
26     <title>[ 'Persistent Object Systems' ]
27     <author>[ 'Atkinson' ]
28     <author>[ 'Benzaken' ]
29     <author>[ 'Maier' ] ]
30 abate 1413 let bib : Bib = [ b1 b2 ]
31 abate 1412 ]]></demo></box>
32    
33     <box title="Printing functions" link="printfun"><demo prefix="last"><![CDATA[
34 abate 1411 type FBook = Book -> String
35     type ABook = <book print=FBook>[ Title Subtitle? Author+ ]
36     type ABib = [ ABook* ]
37     (* Remark: ABook <= Book, ABib <= Bib *)
38    
39     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
41    
42 abate 1413 let abib = prepare bib
43     ]]></demo></box>
44 abate 1411
45 abate 1413 <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 d = display abib
55 abate 1412 ]]></demo></box>
56 abate 1411
57 abate 1413 <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 abate 1411
61 abate 1413 type HasSub = <_>[ _* Subtitle _* ]
62 abate 1412
63 abate 1413 let subtitle(Book & HasSub -> String)
64     <book>[ _* <subtitle>x _* ] -> x
65 abate 1411
66 abate 1413 let change_sub =
67     change
68     (fun (Book -> Bool) HasSub -> `true | _ -> `false)
69     (fun (b : Book) : String =
70     title b @ ": " @ subtitle (b :? HasSub))
71 abate 1411
72 abate 1413
73    
74    
75     ]]></demo></box>
76    
77 abate 1411 <!--
78 abate 1390 <box title="XML elements" link="xml">
79     <p>XML elements.</p>
80     <demo><include-verbatim file="examples/xml.cd"/></demo>
81 abate 1389 </box>
82    
83 abate 1390 <box link="functions" title="Functions">
84     <p>Several syntaxes to define functions.</p>
85     <demo><include-verbatim file="examples/functions.cd"/></demo>
86     </box>
87 abate 1388
88 abate 1390 <box link="mutrec" title="Mutual recursion">
89     <p>Mutual toplevel definition for types and functions.</p>
90     <demo><include-verbatim file="examples/mutrec.cd"/></demo>
91 abate 1384 </box>
92    
93 abate 1390 <box link="sequence" title="Sequence literals">
94     <p>How to write sequences.</p>
95     <demo><include-verbatim file="examples/sequence.cd"/></demo>
96 abate 1387 </box>
97    
98 abate 1390 <box link="seqtypes" title="Sequence types">
99     <p>Types for sequences.</p>
100     <demo><include-verbatim file="examples/seqtypes.cd"/></demo>
101     </box>
102    
103     <box link="integers" title="The factorial function">
104     <p>What about computing 10000! ?</p>
105     <demo><include-verbatim file="examples/integers.cd"/></demo>
106     </box>
107    
108     <box link="sumtype" title="Sum types">
109     <p>How to simulate ML sum types.</p>
110     <demo><include-verbatim file="examples/sumtype.cd"/></demo>
111     </box>
112    
113     <box link="ovfun" title="Overloaded functions">
114     <p>This examples demonstrates the use of overloaded functions.</p>
115     <demo><include-verbatim file="examples/ovfun.cd"/></demo>
116     </box>
117    
118     <box link="note" title="Footnotes">
119     <p>This example shows how to bind an XML element with surrounding text.</p>
120     <demo><include-verbatim file="examples/note.cd"/></demo>
121     </box>
122    
123     <box link="biblio" title="Bibliography">
124     <p>The good old XML bibliography example.</p>
125     <demo><include-verbatim file="examples/biblio.cd"/></demo>
126     </box>
127    
128     <box link="projection" title="Projection">
129     <p>Syntactic sugar for projection.</p>
130     <demo><include-verbatim file="examples/projection.cd"/></demo>
131     </box>
132    
133     <box link="xtransform" title="Tree transformations">
134     <p>How to perform XSLT-like transformations.</p>
135     <demo><include-verbatim file="examples/xtransform.cd"/></demo>
136     </box>
137    
138     <box link="reference" title="References">
139     <p>Mutable values.</p>
140     <demo><include-verbatim file="examples/reference.cd"/></demo>
141     </box>
142    
143     <box title="Compilation of pattern matching" link="pm_compil">
144     <p>This example demonstrates the efficient compilation of pattern
145     matching.</p>
146     <demo><include-verbatim file="examples/pm_compil.cd"/></demo>
147     </box>
148 abate 1411 -->
149 abate 1390
150 abate 1384 </page>

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