Skip to content

Instantly share code, notes, and snippets.

@echojc
Created May 24, 2013 15:03
Show Gist options
  • Save echojc/5644155 to your computer and use it in GitHub Desktop.
Save echojc/5644155 to your computer and use it in GitHub Desktop.
transpose :: [[a]] -> [a] -> [a]
transpose [] output = output
transpose input output = transpose
(filter (\x -> not (null x)) (map (\x -> tail x) input))
(output ++ (map (\x -> head x) input))
print (transpose [[1, 2, 3], [4, 5], [6, 7, 8]] [])
-- prints [1, 4, 6, 2, 5, 7, 3, 8]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment