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.