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

2006-01-03 Thread Daniel Carrera
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

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

2006-01-03 Thread Christian Maeder
Daniel Carrera wrote: print_list xs = do putStr(join xs) where join [] = join (x:xs) = (show x) ++ \n ++ join xs print_list xs = mapM putStrLn xs Question: What do you call a function that has side-effects? (like putStr) I know that function is the wrong term. action,

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

2006-01-03 Thread Chris Kuklewicz
Daniel Carrera wrote: 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

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

2006-01-03 Thread Neil Mitchell
Hi, 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) This uses the bulid in unlines function, which is similar in spirit to join (you get more quotes, which I guess you

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

2006-01-03 Thread Adrian Hey
On Tuesday 03 Jan 2006 5:37 pm, Christian Maeder wrote: Daniel Carrera wrote: Question: What do you call a function that has side-effects? (like putStr) I know that function is the wrong term. action, command, program, etc. Actually (at the risk of appearing pedantic), I think it's

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

2006-01-03 Thread Sebastian Sylvan
On 1/3/06, Daniel Carrera [EMAIL PROTECTED] wrote: 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

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

2006-01-03 Thread Daniel Carrera
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

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

2006-01-03 Thread Daniel Carrera
Chris Kuklewicz wrote: What does lazy printing mean? I assume it means you evaluate the head of the list, print it, then recursively do this for the tail of the list. With an infinite list you will get inifinite output. I assume it does not mean you evaluate the whole list before printing

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

2006-01-03 Thread Donn Cave
On Tue, 3 Jan 2006, Chris Kuklewicz wrote: ... I sometimes call a function with side-effects in IO a command. But the terms are fungible. But calling putStr a function is correct. It is not a pure function however. Is that the standard party line? I mean, we all know its type and

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

2006-01-03 Thread Daniel Carrera
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

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

2006-01-03 Thread Sebastian Sylvan
On 1/3/06, Daniel Carrera [EMAIL PROTECTED] 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

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

2006-01-03 Thread Adrian Hey
On Tuesday 03 Jan 2006 6:11 pm, Donn Cave wrote: On Tue, 3 Jan 2006, Chris Kuklewicz wrote: ... I sometimes call a function with side-effects in IO a command. But the terms are fungible. But calling putStr a function is correct. It is not a pure function however. Is that the standard

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

2006-01-03 Thread Ezra Cooper
On Jan 3, 2006, at 6:30 PM, Sebastian Sylvan wrote: On 1/3/06, Daniel Carrera [EMAIL PROTECTED] 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

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

2006-01-03 Thread Cale Gibbard
On 03/01/06, Donn Cave [EMAIL PROTECTED] wrote: On Tue, 3 Jan 2006, Chris Kuklewicz wrote: ... I sometimes call a function with side-effects in IO a command. But the terms are fungible. But calling putStr a function is correct. It is not a pure function however. Is that the standard

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

2006-01-03 Thread Tomasz Zielonka
On Tue, Jan 03, 2006 at 05:49:07PM +, 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) This uses the bulid in unlines function, which is

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

2006-01-03 Thread Udo Stenzel
Daniel Carrera wrote: 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 This looks as if you're confused. The keyword do is

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

2006-01-03 Thread Wolfgang Jeltsch
Am Dienstag, 3. Januar 2006 19:15 schrieb Daniel Carrera: 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

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

2006-01-03 Thread Tomasz Zielonka
On Tue, Jan 03, 2006 at 10:28:54PM +0100, Udo Stenzel wrote: Daniel Carrera wrote: print_list [] = do putStr This looks as if you're confused. The keyword do is completely redundant. do does not mean please ignore all rules and allow side effects, it rather means please build a new

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

2006-01-03 Thread Glynn Clements
Donn Cave wrote: I sometimes call a function with side-effects in IO a command. But the terms are fungible. But calling putStr a function is correct. It is not a pure function however. Is that the standard party line? I mean, we all know its type and semantics, whatever you want to