[Haskell-cafe] repeat confusion

Galaxy Being borgauf at gmail.com
Fri Apr 23 16:31:46 UTC 2021


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20210423/ce6d9896/attachment.html>


More information about the Haskell-Cafe mailing list