[Haskell-cafe] Confused about my IterIO code

John Ky newhoggy at gmail.com
Mon Jul 4 01:44:55 CEST 2011


Thanks David,

Right - it invokes its iter repeatedly because mkInumC does that and mkInum is
defined as:

mkInum = mkInumC id noCtl


So to do it all manually is:

inumReverseLines :: (Monad m) => Inum L.ByteString L.ByteString m a
inumReverseLines = mkInumM $ loop where
  loop = do
    eof <- atEOFI
    unless eof $ do
      line <- lineI
      ifeed (L.concat [L.reverse line, C.pack "\n"])
      loop


Cheers,

-John

On 1 July 2011 01:20, <dm-list-haskell-cafe at scs.stanford.edu> wrote:

> At Thu, 30 Jun 2011 23:53:02 +1000,
> John Ky wrote:
> >
> > But all I've done is:
> >
> >     enum |$ inumReverseLines .| iter
> >
> >     inumReverseLines = mkInum $ do
> >       line <- lineI
> >       return (L.reverse (L.concat [line, C.pack "\n"]))
>
> mkInum repeatedly invokes its iter argument so as to keep producing
> chunks.  If you want to reverse only one line, it might be easiest to
> use something along the lines of:
>
>    mkInumM $ do
>      line <- lineI
>      ifeed (L.reverse (L.concat [line, C.pack "\n"]))
>
> mkInumM is a more manual Inum construction function that doesn't
> automatically do things like loop or handle EOF conditions.
>
> David
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110704/b0c71590/attachment.htm>


More information about the Haskell-Cafe mailing list