
splitStreams [(3,x),(1,y),(3,z),(2,w)] [(3,[x,z]),(1,[y]),(2,[w])]
[snip]
Furthermore it should work on infinite lists. It can't eat the whole list before producing any output.
This doesn't seem to make sense? Only at the end of the list can you know that you've collected all the events for each channel. If you output anything before scanning to the end, you'd not know if there were perhaps more events on that channel? You could accumulate only over a window, which would produce values on an infinite input, though the output list could have multiple packets for each channel. splitterW 3 [(3,x),(1,y),(3,z),(2,w),(3,v)]
[(3,[x,z]),(1,[y]),(2,[w]),(3,[v])]
Or accumulate until either there are 'n' messages on a channel or the end of the list is reached? splitterN 3 [(3,x),(1,y),(3,z),(2,w),(3,v),(1,u),(3,t)]
[(3,[x,z,v]),(1,[y,u]),(2,[w]),(3,[t])]
Regards, Rohan

On Sep 14, 2006, at 03:05 , Rohan Drape wrote:
splitStreams [(3,x),(1,y),(3,z),(2,w)] [(3,[x,z]),(1,[y]),(2,[w])]
[snip]
Furthermore it should work on infinite lists. It can't eat the whole list before producing any output.
This doesn't seem to make sense? Only at the end of the list can you know that you've collected all the events for each channel. If you output anything before scanning to the end, you'd not know if there were perhaps more events on that channel? It makes good sense. Each list will of events will be evaluated lazily, so thing will appear there as they appear in the input.
I don't think you can do it in Haskell without some magic in the IO/ ST monad. In LML we had an array construction function that did almost exactly what the O.P. asked for. -- Lennart

On 15/09/06, Lennart Augustsson
On Sep 14, 2006, at 03:05 , Rohan Drape wrote:
splitStreams [(3,x),(1,y),(3,z),(2,w)] [(3,[x,z]),(1,[y]),(2,[w])]
[snip]
Furthermore it should work on infinite lists. It can't eat the whole list before producing any output.
This doesn't seem to make sense? Only at the end of the list can you know that you've collected all the events for each channel. If you output anything before scanning to the end, you'd not know if there were perhaps more events on that channel? It makes good sense. Each list will of events will be evaluated lazily, so thing will appear there as they appear in the input.
I don't think you can do it in Haskell without some magic in the IO/ ST monad.
But even if you could do it, its very hard to safely /use/ the result. Looking for the next event on any channel runs the risk that actually there are no more events ever on that channel, and a resultant scan to the end of the infinite list! -- Brian_Brunswick____brian@ithil.org____Wit____Disclaimer____!Shortsig_rules!

I agree, the function can be tricky to use. But that's not our problem, we are only to implement it. :) On Sep 15, 2006, at 05:28 , Brian Brunswick wrote:
On 15/09/06, Lennart Augustsson
wrote: On Sep 14, 2006, at 03:05 , Rohan Drape wrote: splitStreams [(3,x),(1,y),(3,z),(2,w)] [(3,[x,z]),(1,[y]),(2,[w])]
[snip]
Furthermore it should work on infinite lists. It can't eat the whole list before producing any output.
This doesn't seem to make sense? Only at the end of the list can you know that you've collected all the events for each channel. If you output anything before scanning to the end, you'd not know if there were perhaps more events on that channel? It makes good sense. Each list will of events will be evaluated lazily, so thing will appear there as they appear in the input.
I don't think you can do it in Haskell without some magic in the IO/ ST monad.
But even if you could do it, its very hard to safely /use/ the result. Looking for the next event on any channel runs the risk that actually there are no more events ever on that channel, and a resultant scan to the end of the infinite list!
-- Brian_Brunswick____brian@ithil.org____Wit____Disclaimer____! Shortsig_rules! _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

It makes good sense. Each list will of events will be evaluated lazily, so thing will appear there as they appear in the input.
Indeed, thankyou. On a closer inspection I can in fact see that although the first value, (chn,[msgs]), will never appear, one can nonetheless start reading the [msgs] of any channel, precisely because they are in order in the input. Apologies for the noise, slowly learning... Regards, Rohan
participants (3)
-
Brian Brunswick
-
Lennart Augustsson
-
Rohan Drape