| 3 |
<!ENTITY leq "≤"> <!-- LESS_THAN OR EQUAL TO --> |
<!ENTITY leq "≤"> <!-- LESS_THAN OR EQUAL TO --> |
| 4 |
]> |
]> |
| 5 |
<page name="demo"> |
<page name="demo"> |
| 6 |
<title>CDuce demo</title> |
<title>CDuce demo at PLANX 2005</title> |
| 7 |
|
|
| 8 |
|
<box title="Introduction" link="intro"> |
| 9 |
|
|
| 10 |
|
<p> |
| 11 |
|
This page is the support for the CDuce demo at the PLANX 2005 workshop |
| 12 |
|
(Longbeach). The demo illustrates the use of first-class functions |
| 13 |
|
in XML transformations. Here, functions are stored within documents. |
| 14 |
|
</p> |
| 15 |
|
|
| 16 |
|
<boxes-toc/> |
| 17 |
|
|
| 18 |
|
</box> |
| 19 |
|
|
| 20 |
<box title="Types, pattern matching" link="typpm"> |
<box title="Types, pattern matching" link="typpm"> |
| 21 |
<demo><![CDATA[ |
<demo><![CDATA[ |
| 25 |
type Subtitle = <subtitle>[ PCDATA ] |
type Subtitle = <subtitle>[ PCDATA ] |
| 26 |
type Author = <author>[ PCDATA ] |
type Author = <author>[ PCDATA ] |
| 27 |
|
|
| 28 |
let title(Book -> String) <book>[ <title>x _* ] -> x |
let title(Book -> String) |
| 29 |
let authors(Book -> [Author+]) <_>[ (x::Author|_)* ] -> x |
<book>[ <title>x _* ] -> x |
| 30 |
|
|
| 31 |
|
let authors(Book -> [Author+]) |
| 32 |
|
<book>[ (x::Author|_)* ] -> x |
| 33 |
]]></demo></box> |
]]></demo></box> |
| 34 |
|
|
| 35 |
<box title="Sample values" link="samp"><demo prefix="last"><![CDATA[ |
<box title="Sample values" link="samp"><demo prefix="last"><![CDATA[ |
| 51 |
type ABib = [ ABook* ] |
type ABib = [ ABook* ] |
| 52 |
(* Remark: ABook <= Book, ABib <= Bib *) |
(* Remark: ABook <= Book, ABib <= Bib *) |
| 53 |
|
|
| 54 |
let set(<book>c : Book)(f : FBook) : ABook = <book print=f>c |
let set(<book>c : Book)(f : FBook) : ABook = |
| 55 |
let prepare(b : Bib) : ABib = map b with x -> set x title |
<book print=f>c |
| 56 |
|
|
| 57 |
|
let prepare(b : Bib) : ABib = |
| 58 |
|
map b with x -> set x title |
| 59 |
|
|
| 60 |
let abib = prepare bib |
let abib = prepare bib |
| 61 |
]]></demo></box> |
]]></demo></box> |
| 73 |
]]></demo></box> |
]]></demo></box> |
| 74 |
|
|
| 75 |
<box title="Changing the style" link="style"><demo prefix="last"><![CDATA[ |
<box title="Changing the style" link="style"><demo prefix="last"><![CDATA[ |
| 76 |
let change(p : Book -> Bool)(f : FBook)(b : ABib) : ABib = |
let change(p : Book -> Bool) |
| 77 |
|
(f : FBook) |
| 78 |
|
(b : ABib) : ABib = |
| 79 |
map b with x -> if (p x) then set x f else x |
map b with x -> if (p x) then set x f else x |
| 80 |
|
|
| 81 |
type HasSub = <_>[ _* Subtitle _* ] |
type HasSub = <_>[ _* Subtitle _* ] |
| 88 |
(fun (Book -> Bool) HasSub -> `true | _ -> `false) |
(fun (Book -> Bool) HasSub -> `true | _ -> `false) |
| 89 |
(fun (b : Book) : String = |
(fun (b : Book) : String = |
| 90 |
title b @ ": " @ subtitle (b :? HasSub)) |
title b @ ": " @ subtitle (b :? HasSub)) |
| 91 |
|
|
| 92 |
|
let subtitle_first(Bib -> Bib; ABib -> ABib) |
| 93 |
|
[ (x::HasSub|y::_)* ] -> x @ y |
| 94 |
]]></demo></box> |
]]></demo></box> |
| 95 |
|
|
| 96 |
|
<box title="Compilation of pattern-matching" link="pm"><demo prefix="last"><![CDATA[ |
| 97 |
|
debug compile |
| 98 |
|
(*typ*) [ Title Subtitle? Author+ ] |
| 99 |
|
(*pat*) [ (x::Author|_)* ] |
| 100 |
|
]]></demo></box> |
| 101 |
|
|
| 102 |
|
|
| 103 |
<!-- |
<!-- |
| 104 |
<box title="XML elements" link="xml"> |
<box title="XML elements" link="xml"> |
| 105 |
<p>XML elements.</p> |
<p>XML elements.</p> |