funxml.cd 1.06 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
type Bib = [ Book* ]
type Book = <book>[ Title Subtitle? Author+ ]
type Title = <title>[ PCDATA ]
type Subtitle = <subtitle>[ PCDATA ]
type Author = <author>[ PCDATA ]

let title(Book -> String)  <book>[ <title>x _* ] -> x

(* We annotate each book with a printing function for it *)

type FBook = Book -> String
type ABook = <book print=FBook>[ Title Subtitle? Author+ ]
type ABib = [ ABook* ]
  (* Note that: ABook <= Book,  ABib <= Bib *)

let set(<book>c : Book)(f : FBook) : ABook = <book print=f>c
let prepare(b : Bib) : ABib = map b with x -> set x title

(* We display the annotated bibliography *)

type Ul = <ul>[ Li+ ]
type Li = <li>[ PCDATA ]

let display (ABib -> Ul; ABook -> Li)
 | <book print=f>_ & x -> <li>(f x)
 | [] -> raise "Empty bibliography"
 | p -> <ul>(map p with z -> display z)

(* We change the dispay function for some books *)

let change(p : Book -> Bool)(f : FBook)(b : ABib) : ABib =
 map b with x -> if (p x) then set x f else x

type HasSub = <_>[ _* Subtitle _* ]

let change_if_sub = 
 change (fun (Book -> Bool) HasSub -> `true | _ -> `false)