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
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,
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
19 matches
Mail list logo