Does Haskell have a greedy zip (one preserving all elements)?
<p>I'm not exactly sure if my nomenclature is correct here, but I was wondering if there was a zip function in Haskell that was greedy. This means that if I had</p>

<pre><code>a = [1, 2, 3]
b = [4, 5]
zip' a b
#=&gt; [(Just 1, Just 4),(Just 2, Just 5),(Just 3, Nothing)]
</code></pre>

<p>...where <code>zip'</code> is the greedy zip function, it would return a list of tuples the length of the longer list, and where the longer list has an element, but the shorter list does not <code>Nothing</code> is put in the respective tuple position. I am not asking how to write this, but instead was wondering if this exists as a built-in.</p>

<p>Here is my implementation (which is probably not great)</p>

<pre><code>zip' :: [a] -&gt; [b] -&gt; [(Maybe a, Maybe b)]
zip' (a:xs) [] = (Just a, Nothing) : zip' xs []
zip' [] (b:ys) = (Nothing, Just b) : zip' [] ys
zip' [] _ = []
zip' (a:xs) (b:ys) = (Just a, Just b) : zip' xs ys
</code></pre>