[Haskell-cafe] IO in lists

Joachim Breitner mail at joachim-breitner.de
Tue Jan 16 14:57:01 EST 2007


Hi,

Am Dienstag, den 16.01.2007, 19:19 +0000 schrieb David House:
> On 16/01/07, Yitzchak Gale <gale at sefer.org> wrote:
> > listChars2 :: ListT IO Char
> > listChars2 = do
> >   c <- lift getChar
> >   if c == 'q'
> >     then return c
> >     else return c `mplus` listChars2
> 
> It's probably eaiser to work with normal lists:
> 
> listChars :: IO [Char]
> listChars = do
>   c <- getChar
>   if c == 'q'
>     then return c
>     else liftM2 (:) (return c) listChars

But that is not lazy any more, is it? The idea of the OT was, I think,
that he can use the first elements of the list even before the last one
was entered.

Greetings,
Joachim

-- 
Joachim Breitner
  e-Mail: mail at joachim-breitner.de
  Homepage: http://www.joachim-breitner.de
  ICQ#: 74513189


More information about the Haskell-Cafe mailing list