tag:blogger.com,1999:blog-6919669035402552575.post7162901999755774991..comments2022-12-14T11:05:23.203-08:00Comments on RuMiNaTiOnS: Two-dimensional zipAnonymoushttp://www.blogger.com/profile/07441435909838565635noreply@blogger.comBlogger13125tag:blogger.com,1999:blog-6919669035402552575.post-701616947797576102008-08-07T05:48:00.000-07:002008-08-07T05:48:00.000-07:00doh! Of course. Brain lapse there. Thanks, Arnar....doh! Of course. Brain lapse there. Thanks, Arnar.Brenthttps://www.blogger.com/profile/14440861005012132386noreply@blogger.comtag:blogger.com,1999:blog-6919669035402552575.post-90718832378947864632008-08-06T22:54:00.000-07:002008-08-06T22:54:00.000-07:00Great! Thanks very much - keep up the good work! :...Great! Thanks very much - keep up the good work! :) <BR/>- AndyAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-6919669035402552575.post-24412141510981712622008-08-06T09:55:00.000-07:002008-08-06T09:55:00.000-07:00Absolutely, feel free to use the code.Absolutely, feel free to use the code.Anonymoushttps://www.blogger.com/profile/07441435909838565635noreply@blogger.comtag:blogger.com,1999:blog-6919669035402552575.post-23311074937496371852008-08-05T23:06:00.000-07:002008-08-05T23:06:00.000-07:00Hi Clifford! Really nice code - I love seeing eleg...Hi Clifford! <BR/><BR/>Really nice code - I love seeing elegant solutions like this! <BR/><BR/>I'm looking at doing a public-domain crosstab app in Haskell, so I was wondering - could I include this code? (I'll give acknowledgement of course, if it is used). <BR/><BR/>Thanks for doing this post! Bye for now - <BR/>- AndyAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-6919669035402552575.post-15537000505299200712008-08-05T17:47:00.000-07:002008-08-05T17:47:00.000-07:00Brent said: indices2d = [(r,c) | r <- [0..], c ...Brent said: <I>indices2d = [(r,c) | r <- [0..], c <- [0..]]</I><BR/><BR/>That doesn't work, in fact it is equivalent to [(0,c) | c <- [0..]]<BR/><BR/>The type is not even the same. What Clifford needed was a two-dimensional list of the type [[(Integer,Integer)]], i.e. a 2-D lattice of integers.Arnar Birgissonhttps://www.blogger.com/profile/12073820949049315334noreply@blogger.comtag:blogger.com,1999:blog-6919669035402552575.post-9217251106010260752008-08-05T16:56:00.000-07:002008-08-05T16:56:00.000-07:00By the way, you don't need nested comprehensio...By the way, you don't need nested comprehensions to define indices2d. Just write:<BR/><BR/>indices2d = [(r,c) | r <- [0..], c <- [0..]]Brenthttps://www.blogger.com/profile/14440861005012132386noreply@blogger.comtag:blogger.com,1999:blog-6919669035402552575.post-21804506507032775262008-08-05T12:47:00.000-07:002008-08-05T12:47:00.000-07:00Ah, nice. I didn't know about iterate.If you want ...Ah, nice. I didn't know about iterate.<BR/><BR/>If you want at least the rhs of your second definition to be point-free, it is not too exotic:<BR/><BR/>fiter f n = (!!n) . iterate fArnar Birgissonhttps://www.blogger.com/profile/12073820949049315334noreply@blogger.comtag:blogger.com,1999:blog-6919669035402552575.post-8873731873700273912008-08-05T12:27:00.000-07:002008-08-05T12:27:00.000-07:00Since fpow really means iterated function, one mig...Since fpow really means iterated function, one might express it thus:<BR/><BR/>fiter f n x = iterate f x !! n<BR/><BR/>Or, to emphasize operating on functions:<BR/><BR/>fiter f n = \x -> iterate f x !! n<BR/><BR/>Unfortunately some pointless-y goodness is lost, though.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-6919669035402552575.post-5111654331076173822008-08-05T10:32:00.000-07:002008-08-05T10:32:00.000-07:00Arnar Birgisson said: fpow f n = foldr (.) id $ ...Arnar Birgisson said:<BR/><BR/> fpow f n = foldr (.) id $ replicate n f<BR/><BR/><BR/>Very nice.Anonymoushttps://www.blogger.com/profile/07441435909838565635noreply@blogger.comtag:blogger.com,1999:blog-6919669035402552575.post-15461999692071575422008-08-05T10:19:00.000-07:002008-08-05T10:19:00.000-07:00Luke said:zip2DWith = zipWith . zipWithzip3DWith =...Luke said:<BR/><I><BR/>zip2DWith = zipWith . zipWith<BR/>zip3DWith = zipWith . zipWith . zipWith<BR/>zip2DWith3 = zipWith3 . zipWith3<BR/></I><BR/>This gives rise to:<BR/><BR/>fpow f n = foldr (.) id $ replicate n f<BR/><BR/>Then,<BR/><BR/>zip2DWith = zipWith `fpow` 2<BR/>zip4DWith = zipWith `fpow` 4<BR/><BR/>etc. :)Arnar Birgissonhttps://www.blogger.com/profile/12073820949049315334noreply@blogger.comtag:blogger.com,1999:blog-6919669035402552575.post-84829447289926611382008-08-05T00:36:00.000-07:002008-08-05T00:36:00.000-07:00I thought about exploring the point-free forms som...I thought about exploring the point-free forms some more but decided it was time to post. Thanks for the TypeCompose observation as well. I haven't read that code since it first came out; clearly time to catch up. I was thinking that Conal must have done something similar to this zip in his Image work. I remember he was thinking about how to make the sets infinite in both directions.Anonymoushttps://www.blogger.com/profile/07441435909838565635noreply@blogger.comtag:blogger.com,1999:blog-6919669035402552575.post-66859851332294144592008-08-05T00:13:00.000-07:002008-08-05T00:13:00.000-07:00Of course this relates to zipping being an applica...Of course this relates to zipping being an applicative functor. So the implementation for zip2DWith is just the applicative functor instance for ZipList :. ZipList (where (:.) is from TypeCompose), zip2DWith 3 is just liftA3 on that functor, etc.Luke Palmerhttps://www.blogger.com/profile/09807388788677769669noreply@blogger.comtag:blogger.com,1999:blog-6919669035402552575.post-35982130692916028872008-08-05T00:07:00.000-07:002008-08-05T00:07:00.000-07:00This is one of those simple pleasures, that I find...This is one of those simple pleasures, that I find incredibly beautiful.<BR/><BR/>zip2DWith = zipWith . zipWith<BR/>zip3DWith = zipWith . zipWith . zipWith<BR/>zip2DWith3 = zipWith3 . zipWith3<BR/>etc.Luke Palmerhttps://www.blogger.com/profile/09807388788677769669noreply@blogger.com