I need to get an input until the empty line is entered and when the empty line is entered I need to print all first characters of each line (as one word).
Can somebody explain what should I write in the last line?
inp :: IO String
inp
= do
line <- getLine
if null line
then return ""
else do
lines <- inp
return lines????
I don’t want to spoil everything, but here are a few hints:
Stringis actually just another name for[Char].(:) :: a -> [a] -> [a]function (and in particular,(:) :: Char -> String -> String). You can read this function aloud as “cons”. For example,1:[2,3,4]is the same as[1,2,3,4], and'a':"bcd"is the same as"abcd".head :: [a] -> afunction (and in particular,head :: String -> Char).nullandif/then/else; this also eliminates the need forhead, which is often a code smell.From a comment, you’ve also tried something like this as your last line:
The main problem here is that
returnis not a keyword in Haskell, it’s just a plain old function. So if your argument is an expression, you need to parenthesize it (or use one of the various tricks for avoiding parentheses):etc. This should get you to where things typecheck and run; then you can get started correcting the bugs in the behavior of the code. =)