Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 0.94 KB | None | 0 0
  1. let zip (xs, ys) =
  2.     List.rev( snd (List.fold_left (fun (tail_of_ys, list_of_pairs) hx -> match tail_of_ys with                                                                                                                                   
  3.                                                                          | h::t -> (t, (hx, h)::list_of_pairs)                                                                                                                                           
  4.                                                                          | [] -> ([], list_of_pairs)                                                                                                                                                     
  5.                                                                                                                ) (ys, []) xs));;
  6.  
  7. zip( ['a';'b';'c';'d'] ,['a';'b';'c';'d']);;                (*xs.length = ys.length*)
  8. zip( [1;2;3] ,['a';'b';'c';'d']);;                                  (*xs.length < ys.length*)
  9. zip( [1;2;3;4;5;6;7;8;9;10] ,['a';'b';'c';'d']);;   (*xs.length > ys.length*)
  10. zip([], [1;2;3;45]);;                                                           (*xs.length = 0*)
  11. zip(['a';'b';'c';'d'], [1]);                                            (*ys.length = 0*)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement