[Haskell-cafe] How to print a string (lazily)

Sebastian Sylvan sebastian.sylvan at gmail.com
Tue Jan 3 13:30:19 EST 2006


On 1/3/06, Daniel Carrera <daniel.carrera at zmsl.com> wrote:
> Neil Mitchell wrote:
> > All Haskell functions are lazy, hence there is no need to "write a
> > lazy version" of your print_list function. I think the function you
> > probably want is:
> >
> > putStr (unlines xs)
>
> Hhmm... that does work, and I'm a bit surprised that it does. I guess
> I'm still stuck in the eager computation mindset. I would expect putStr
> to have to wait for the (unlines xs) to be finished before doing any
> printing, but it doesn't.
>
> Some day I'll get the hang of this lazy evaluation thing. :)

It does, in a sense, but since unlines is lazy (just like *everything
else* in Haskell) it won't actually *do* anything until putStr demands
an element from the result.

/S

--
Sebastian Sylvan
+46(0)736-818655
UIN: 44640862


More information about the Haskell-Cafe mailing list