<div dir="auto">In Data.List, we define<div dir="auto"><br></div><div dir="auto">transpose :: [[a]] -> [[a]]</div><div dir="auto">transpose [] = []</div><div dir="auto">transpose ([] : xss) = transpose xss</div><div dir="auto">transpose ((x : xs) : xss) = (x : [h | (h : _) <- xss]) : transpose (xs : [t | (_ : t) <- xss])</div><div dir="auto"><br></div><div dir="auto">The potential difficulty is that we essentially mapMaybe over the xss list twice in the third case. So we hang on to the heads where we need the tails and the tails where we need the heads. We could fix that with something like this:</div><div dir="auto"><br></div><div dir="auto"><span style="font-family:sans-serif">transpose ((x : xs) : xss) = (x : fronts) : transpose (xs : rears)</span><br></div><div dir="auto"><span style="font-family:sans-serif">  where</span></div><div dir="auto"><span style="font-family:sans-serif">    (fronts, rears) = unzip [(h,t) | (h : t) <- xss]</span></div><div dir="auto"><br></div><div dir="auto"><span style="font-family:sans-serif">I don't know how much that'll cost in practice.</span></div></div>