[Haskell-cafe] Re: Network parsing and parsec

Benjamin Franksen benjamin.franksen at bessy.de
Wed Sep 21 14:08:45 EDT 2005


On Wednesday 21 September 2005 19:36, Jan-Willem Maessen wrote:
> On Sep 20, 2005, at 6:32 PM, Benjamin Franksen wrote:
> > On Tuesday 20 September 2005 16:50, John Goerzen wrote:
> >> On the flip side, Parsec is really nice.  I wonder how easy it
> >> would be to make it parse [Word8] instead of String?
> >
> > Isn't Parsec parameterized over the token type?
> >
> >> Or even a
> >> FastPackedString? (And how easy it would be to get that instead of
> >> a String from hGetContents)?
> >
> > From the FPS haddock:
> >
> > hGetContents :: Handle -> IO FastString
> >
> >   Read entire handle contents into a FastString.
> >
> > This may or may not do what you want...it's probably not a lazy
> > read.
>
> It seems like there might need to be something like:
>
> hGetContentsLazily :: Handle -> IO [FastString]
>
> which returns file contents in chunks based on our ability to buffer
> the handle.  If we can mmap the handle, we may get a singleton list
> with a giant FastString; if we are using a Socket or a terminal, each
> succeeding string might be the next chunk of available data from the
> handle.

From the FPS haddock:

data LazyFile 
  Constructors
    LazyString String
    MMappedFastString FastString
    LazyFastStrings [FastString]
  Instances
    Eq LazyFile

  readFileLazily :: FilePath -> IO LazyFile

That comes pretty near. Unfortunately it works on a file name, not a 
handle. Thus it cannot be used for a socket or such things.

Ben


More information about the Haskell-Cafe mailing list