This reminded me of "interleaving" as in: Backtracking, Interleaving, and Terminating Monad Transformers http://www.cs.rutgers.edu/~ccshan/logicprog/LogicT-icfp2005.pdf
On 4/10/07, Dave Feustel <[EMAIL PROTECTED]> wrote:
Talk about synchronicity! I was just wondering whether 'weaving' of infinite lists is possible. eg weave the infinite lists [2,4..], [3,6..], [5,10..] to get [2,3,4,5,6,8,9,10,..] Is this kind of lazy evaluation possible? Thanks, Dave Feustel -----Original Message----- >From: Bas van Dijk <[EMAIL PROTECTED]> >Sent: Apr 10, 2007 6:13 PM >To: [email protected] >Subject: [Haskell-cafe] Weaving fun > >Hello, > >For my own exercise I'm writing a function 'weave' that "weaves" a >list of lists together. For example: > > weave [[1,1,1], [2,2,2], [3,3]] ==> [1,2,3,1,2,3,1,2] > weave [[1,1,1], [2,2], [3,3,3]] ==> [1,2,3,1,2,3,1] > >Note that 'weave' stops when a list is empty. Right now I have: > > weave :: [[a]] -> [a] > weave ll = work ll [] [] > where > work ll = foldr f (\rst acc -> work (reverse rst) [] acc) ll > f [] g = \_ acc -> reverse acc > f (x:xs) g = \rst acc -> g (xs:rst) (x:acc) > >However I find this definition hard to read and I'm questioning its >efficiency especially due to the 'reverse' parts (how do they impact >performance and can they be removed?) > >So I'm wondering if 'weave' can be defined more "elegantly" (better >readable, shorter, more efficient, etc.)? > >happy hacking, > >Bas van Dijk >_______________________________________________ >Haskell-Cafe mailing list >[email protected] >http://www.haskell.org/mailman/listinfo/haskell-cafe http://RepublicBroadcasting.org - Because You CAN Handle The Truth! http://iceagenow.com - Because Global Warming Is A Scam! _______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
-- Ricardo GuimarĂ£es Herrmann "You never change things by fighting the existing reality. To change something, build a new model that makes the existing model obsolete" - R. Buckminster Fuller
_______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
