Skip to content

Transpose hangs on infinite by finite lists

I found out that this code

take 5 $ map (take 3) (transpose (repeat [0..1]))

isn't equivalent to this one

take 5 $ map (take 3) [[0,0..], [1,1..]]

The second piece of code gives expectable output of [[0,0,0],[1,1,1]], while first one just hangs with output [[0,0,0],[1,1,1], also probably screwing up some descriptors after interruption with Ctrl+C (as in 8.2.1, didn't have such problem in 8.0.2. I attach the screenshot of my cmd after interruption and pressing Up and Down buttons randomly for a few times. The history seems to be broken).

In my homework I had to make a function zipN, which is actually zipWith but for more than two lists. The solution which dealt with stuck was to write my own transpose and apply takeWhile (not . null) to the remaining part of transposed matrix.

P.S.:

[[0,0..],[1,1..]] == transpose (repeat [0..1])

also hangs ghci.

Edited by utikeev
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information