addrbook3.cd 484 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10
type Addrbook = <addrbook>[Person*]
type Person = <person>[(Name Tel? Email* )]
type Name = <name>String
type Tel = <tel>String
type Email = <email>String

let mkTelbook (l : [Person*]) : [<entry>[Name Tel] *] =
 transform l with <person>[ (n & Name) (t & Tel) ; _ ] -> [ <entry>[n t] ]
 

11
match argv [] with
12 13
  | [ f ] -> 
   (match load_xml f with
14
    | <addrbook>(x & [Person*]) -> <addrbook>(mkTelbook x)
15 16
    | _ -> raise "Invalid document") 
  | _ -> raise "Invalid command line"