[Haskell-cafe] Optimization problem

Rohan Drape rd at slavepianos.org
Thu Sep 14 03:05:51 EDT 2006

> > splitStreams [(3,x),(1,y),(3,z),(2,w)]
> [(3,[x,z]),(1,[y]),(2,[w])]


> 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])]


More information about the Haskell-Cafe mailing list