[Haskell-beginners] A first try

Mike Meyer mwm at mired.org
Mon Jun 27 18:41:42 CEST 2011


On Mon, 27 Jun 2011 12:54:51 +0300
Yitzchak Gale <gale at sefer.org> wrote:

> Heinrich Apfelmus wrote:
> > Again, let me stress that the biggest drawback of the Iteratee approach is
> > that you have to rewrite the consumer and cannot reuse ordinary list
> > functions like  length , words , lines , and so on. But these functions are
> > already lazy, so why not make use of this. (You don't lose anything, every
> > Iteratee can be rewritten as an ordinary function  String -> IO a  by using
> >  `seq`  in corresponding places.)
> > Here one possibility for a lazier version of  withFile' :

Very nice. I hope you don't mind if I use it?

I've been watching this thread closely, because one of my concerns for
my first project is making sure the file IO gets handled right. It's
processing a set of files in order (typical Unix command line stuff),
and I came up with two requirements:

1) Only the file currently being processed should be open.
2) Don't read the entire file into memory at once.

You seem to have hit both of them.

> Let me just add my voice in support of Heinrich.

Ditto.

> Whether you are using lazy IO or Iteratees, we really need
> some better higher-level combinators with simpler semantics
> for more of the common use cases. Then it won't really matter.

And that was my conclusion last night. Iteratees provide generalized
tools that don't seem to have obvious ways to do common
operations. While that kind of thing is needed, I suspect that over
90% of file processing (at least for command line arguments) could be
handled by things like Heinrich's withFiles and the obvious variants
of the HOF list functions, like:

    fileMap :: (String -> a) -> [FilePath] -> [a]
    fileFoldl' :: (a -> String -> a) -> a -> [FilePath] -> a

The user doesn't care whether it's using lazy IO or iteratees, so
long as it has the proper semantics.

    <mike
-- 
Mike Meyer <mwm at mired.org>		http://www.mired.org/
Independent Software developer/SCM consultant, email for more information.

O< ascii ribbon campaign - stop html mail - www.asciiribbon.org



More information about the Beginners mailing list