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

Daniel Carrera daniel.carrera at zmsl.com
Tue Jan 3 13:08:17 EST 2006

Sebastian Sylvan wrote:
> Others have already replied with a solution, but it looks to me like
> what you're "missing" is how to sequence commands, which is the whole
> purpose of the "do" notation.
> print_list [] = return ()
> print_list (x:xs) =
>   do putStr x
>        print_list xs
> The do notation is used here to sequence to IO actions (which answers
> your second question), first it prints out the first character in the
> string, then it calls itself recursively to print the rest of the
> list.

Thanks! And yes, I'm just learning how to sequence commands/actions, so 
I know I'm missing a lot.

> The empty list shouldn't print an empty string, it should do nothing
> (that is, just return IO () because that's the return type of
> print_list)

Yeah... I just didn't know how to "do nothing" with Haskell. Thanks!

      /\/`) http://oooauthors.org
     /\/_/  http://opendocumentfellowship.org
    \/_/    I am not over-weight, I am under-tall.

More information about the Haskell-Cafe mailing list