Map 2
Implement the function
val map2 : ('a -> 'b -> 'c) -> 'a list -> 'b list -> 'c list
so that map2 f l r is the result of applying f to each element
of l and r pointwise. If l and r are different lengths,
then the longer list should be truncated to the length of the
shorter list. For example, map2 f [a;b] [c;d;e] is equivalent to
[f a c ; f b d].
This is a two-list version of the function List.map. You should
not use the function List.map2 in your implementation (the
standard library version doesn't work the way we've defined map2
here).
Examples
let _ = assert (map2 (+) [1;2;3] [10;20;30] = [11;22;33])
let _ = assert (map2 (fun x y -> (x, y)) [1;2;3] ["a";"b"] = [(1, "a"); (2, "b")])
let _ = assert (map2 ( * ) [] [1;2;3] = [])