
Hi, this is probably an easy question, but i simply can't figure out, why this does not work: import Data.Char main = do contents <- getContents putStrLn $ show $ splitcomma contents splitcomma = split ',' split :: Char -> String -> [String] split _ "" = [""] split sp (c:cs) | c == sp = "": rest | otherwise = (c : head rest) : tail rest where rest = split sp cs The program compiles and runs without any problems. But there is absolutely no output, when f.eg. i type "hello, world" and hit return. Why would that be? Thank you very much

On 16 June 2012 20:03, Robert Heumüller
The program compiles and runs without any problems. But there is absolutely no output, when f.eg. i type "hello, world" and hit return. Why would that be?
getContents reads the entire input to the program. Under Linux you can terminate input with Ctrl-D. If you want to only read a single line, use getLine.

On 06/16/12 14:03, Robert Heumüller wrote:
Hi,
this is probably an easy question, but i simply can't figure out, why this does not work:
...
The program compiles and runs without any problems. But there is absolutely no output, when f.eg. i type "hello, world" and hit return. Why would that be?
"Return" doesn't end the input. Try Control-D, which should work on
Linux at least (it send end-of-file).
$ runhaskell test.hs
hello, world

On Sat, Jun 16, 2012 at 2:03 PM, Robert Heumüller
The program compiles and runs without any problems. But there is absolutely no output, when f.eg. i type "hello, world" and hit return. Why would that be?
At a guess, your "split" is too strict and requires the entire input in order to do anything, so you'd need control-D on Unix or control-Z on Windows to mark the end of the input stream. You might prefer to use the functions from the "split" package on Hackage (cabal install split) which are appropriately lazy. -- brandon s allbery allbery.b@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms
participants (4)
-
Brandon Allbery
-
Michael Orlitzky
-
Robert Heumüller
-
Tobias Brandt