type Content = [(Name Addr Tel?)*];; type Addrbook = Content;; type Name = [String];; type Addr = [String];; type Tel = [String];; [ ["Haruo Hosoya"] ["Tokyo"] ["Benjamin Pierce"] ["Philadelphia"] ["123-456-789"] ["Peter Buneman"] ["Scotland"] ];; [ ["Haruo Hosoya"] ["Tokyo"] ["Benjamin Pierce"] ["Philadelphia"] ["123-456-789"] ["Peter Buneman"] ["Scotland"] ];; [ ["Haruo Hosoya"] ["Tokyo"] ["Benjamin Pierce"] ["Philadelphia"] ["123-456-789"] ["Peter Buneman"] ["Scotland"] ];; [ ["Haruo Hosoya"] ["Tokyo"] ["Benjamin Pierce"] ["Philadelphia"] ["123-456-789"] ["Peter Buneman"] ["Scotland"] ];; (* (* converting an address book into a telephone list *) fun mkTelList ([ (Name Addr Tel?)* ] -> [ (Name Tel)* ]) | [ n a t ; rest] -> [ n t ; mkTelList rest] | [ n a; rest] -> mkTelList rest | [ ] -> [ ] ;; fun mkTelList (Addrbook -> [ (Name Tel)* ]) <_>[ ( ( (x::Name) Addr (x::Tel) ) | _ )* ] -> x ;; *) fun (Int -> Addrbook) x -> [ ["Haruo Hosoya"] ["Tokyo"] ["Benjamin Pierce"] ["Philadelphia"] ["123-456-789"] ["Peter Buneman"] ["Scotland"] ] ;; (* fun (Int -> Addrbook) x -> [ ["Haruo Hosoya"] ["Tokyo"] ["Benjamin Pierce"] ["Philadelphia"] ["123-456-789"] ["Peter Buneman"] ["Scotland"] ] ;; *) (* match [ ["Haruo Hosoya"] ["Tokyo"] ["Benjamin Pierce"] ["Philadelphia"] ["123-456-789"] ["Peter Buneman"] ["Scotland"] ] with <_>[ ( ( (x::Name) Addr (x::Tel) ) | _ )* ] -> x;; (* (* the pattern extract the full sequence of subelements *) match ex with addrbook:[;a] -> mkTelList a;; *) *)