Commit 0465fa5d authored by Pietro Abate's avatar Pietro Abate
Browse files

[r2004-12-27 16:05:06 by afrisch] Forgot an example

Original author: afrisch
Date: 2004-12-27 16:05:06+00:00
parent 06848baa
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)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment