[Haskell-cafe] How to print a string (lazily)
Daniel Carrera
daniel.carrera at zmsl.com
Tue Jan 3 12:32:20 EST 2006
Hello,
I've been studying more Haskell and I've improved a lot. But I just hit
a small problem. I want to print all the elements of a linst (putStr).
I'd like to write something like this:
print_list [] = do putStr ""
print_list (x:xs) = (do putStr x) && print_list xs
I know this is wrong, but I hope you can see what I'm trying to do.
I know of other ways I could print a list. For example:
print_list xs = do putStr(join xs)
where join [] = ""
join (x:xs) = (show x) ++ "\n" ++ join xs
But the thing is, I want to write a lazy version of this function. It's
not that I need such a function, I'm just trying to learn Haskell.
Any suggestions?
Question: What do you call a function that has side-effects? (like
putStr) I know that "function" is the wrong term.
Cheers,
Daniel.
--
/\/`) http://oooauthors.org
/\/_/ http://opendocumentfellowship.org
/\/_/
\/_/ I am not over-weight, I am under-tall.
/
More information about the Haskell-Cafe
mailing list