[Haskell-cafe] Help wanted: Lazy multiway zipper with mismached intervals

Rene de Visser rene_de_visser at hotmail.com
Mon Sep 26 12:14:23 EDT 2005


Hello,

I need to zip together multiple lists.

The lists are sorted by date, and each entry in the list represents data for 
a time interval.
The time intervals between the lists may be missmatched from each other.

This means that sometimes you don't need to move forward in list, while you 
move forward in other lists. It might also mean that you need to skip a 
number of entries foward.

If the computation does not need part of the contents of one of the lists, 
then this list should be ignored until it is needed.

As the lists are sorted you never need to go backwards.

I found it fairly easy to write a zipper for two lists, where  the items 
from both lists are needed (example binary operator on the payload of the 
list).

However the combination of merging multiple lists together, and ignoring a 
list in the case it is not needed by the computation leads to very messy 
code.

I though about if there was a away of encapsulating this in a monad, but 
haven't thought of any way to do this.

Another idea is to have a mutable cursor for each list and move these 
forward as required. But I guess this might be worth avoiding?

I think it would be good if somehow I could encapsulate each list, so on a 
per list basis, and can say given me the current head, or move one forward. 
But I haven't figured out how to pass the state of the other threads 
invisibly through.

I guess the ony way might be to use the state monad?
I guess there can be no simple recursive solution?

Rene.




More information about the Haskell-Cafe mailing list