Think about it like this:

image.png

The current elements are zipped with the tails (which are created with transpose). This has to bottom out with empty tails (repeat []).

On Sat, Apr 24, 2021 at 2:32 AM Galaxy Being <borgauf@gmail.com> wrote:
I'm in Bird's Thinking Functionally with Haskell and he has this code to transpose a matrix based on a list of row lists

transpose :: [[a]] -> [[a]]
transpose [xs] = [[x] | x <- xs]
transpose (xs:xss) = zipWith (:) xs (transpose xss)


then he says transpose can be rewritten with this pattern

transpose [] = ...

what could be the rest of it? The answer he gives is

transpose2 :: [[a]] -> [[a]]
transpose2 [] = repeat []  
transpose2 (xs:xss) = zipWith (:) xs (transpose2 xss)


where repeat [] gives an infinite list of repetitions. And, he says, note that

transpose [xs] =  zipWith (;) xs (repeat []) = [[x] | x <- xs]

I suppose I get this last equation, but I don't understand repeat in transpose2. Can someone explain this to me?

LB

_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.