The input to the code is numbers written in words "one" "two" etc. the output is the sum of a all numbers inputed when "sum" or "end" is entered. "end" also exits the program.
This is the code that I've written.
main = addfunc 0
addfunc :: Int -> IO ()
addfunc l = do
{
input <- getLine;
let n = myStrToI input
; if n == -2
then do {
putStrLn("The final sum is: " ++ show (l));
return ();
}
else if n == -1
then
putStrLn("The current sum is: " ++ show(l));
addfunc l; <--Error Here
else addfunc (n+l)
}
myStrToI :: [Char] -> Int
myStrToI l
| l == "zero" = 0
| l == "one" = 1
| l == "two" = 2
| l == "three" = 3
| l == "four" = 4
| l == "five" = 5
| l == "six" = 6
| l == "seven" = 7
| l == "eight" = 8
| l == "nine" = 9
| l == "sum" = -1
| l == "end" = -2
The error I get is
"error: parse error on input 'addfunc'
17. addfunc l;"
I've tried changing the amount of spaces or removing the ';' in the line above, but I still get an error at that place. Is this error because the indentation of if else blocks? I'm beginner to Haskell and don't really understand where the error is.
dokeyword on line 15{};? Yes, Haskell allows C-like syntax too, but it's not really supposed to be used in human-written code.{ .. ; .. ; .. }-style, you should really use a consistent indentation. The one above is completely misleading. Just because indentation does no longer matter to the compiler is not a good reason: in C,Java, etc. it does matter yet it is still a must-have for humans. Also note that;is a separator, not a terminator, hence there must be no;just before the}.