[Haskell-cafe] enumeration I/O and non-sequential access

Johan Tibell johan.tibell at gmail.com
Thu Oct 2 11:28:07 EDT 2008


On Thu, Oct 2, 2008 at 3:50 PM, John Lato <jwlato at gmail.com> wrote:
> Hello,
>
> I've recently been looking at Oleg's Iteratee approach to I/O
> (http://okmij.org/ftp/Haskell/Iteratee/), and I was wondering about
> something.  In general this seems to be a very good approach to
> handling sequential access, but I don't see a means of applying it
> where non-sequential (esp. random) access is desired.  In fact, the
> only way I see of doing so is to either hold references to all read
> data in memory until the file has finished processing, or to iterate
> over the file multiple times, depending on how the data is to be
> processed.  I can't see how either of these approaches would scale
> well.  Is this an actual problem?  Is there already a solution that
> I'm not aware of?

You could have the iteratee return the next position in the file it
would like to operate on. The enumerator would use e.g. `pread` to
perform random access reads in constant memory. I would have to know a
little more about your use case before I can say if this would be a
good idea or not.

Cheers,

Johan


More information about the Haskell-Cafe mailing list