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

let mkTelbook ([Person*] -> [<entry>[Name Tel] *])
  | [ <person>[ (n & Name) (t & Tel) ; _ ]; rest] ->  
      [ <entry>[n t]; mkTelbook rest ]
  | [ <person>[ Name ; _ ] ; rest] ->  mkTelbook rest
  | [] -> []
 

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