[Haskell-cafe] repeat confusion
Lyndon Maydwell
maydwell at gmail.com
Fri Apr 23 22:26:55 UTC 2021
Think about it like this:
[image: 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 at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20210424/56e5d77b/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 30405 bytes
Desc: not available
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20210424/56e5d77b/attachment.png>
More information about the Haskell-Cafe
mailing list