possible incorrect indentation

Hi all, Will somebody please explain why this wont run, I sure the code is right? data Expression = Val Integer | Add Expression Expression | Subtract Expression Expression | Multiply Expression Expression | Divide Expression Expression deriving Show demo1 = (Add(Add(Add(Val 6)(Val 5))(Val 10))(Val 7)) evalStep :: Expression -> Expression evalStep (Val x)= (Val x) evalStep (Add x y) = case x of (Val a) -> case y of (Val b) -> Val (a+b) left -> Add x (evalStep y) right -> Add y(evalStep x) evaluate :: Expression -> Expression -- Base case evaluate (Val a) = Val a -- Recursive case evaluate e = do putStrLn "Evaluating one more step" e' <- return (evalStep e) putStrLn ("Result is "++(show e')) putStrLn "Do another step (y/n)? :" c <- getChar if (c=='y') then evaluate e' else putStrLn "OK, finished" Its suppose to print out the first step then ask you if you want the next step all the way to the end

Indent the if like this: if (c=='y') then evaluate e' else putStrLn "OK, finished" I don't know the syntax rule of why you should write it like this. The point is that your then and else should be more indented than your if. The following also works: if (c=='y') then evaluate e' else putStrLn "OK, finished" On Mon, 2010-01-25 at 22:45 +0000, John Moore wrote:
data Expression = Val Integer | Add Expression Expression | Subtract Expression Expression | Multiply Expression Expression | Divide Expression Expression deriving Show demo1 = (Add(Add(Add(Val 6)(Val 5))(Val 10))(Val 7)) evalStep :: Expression -> Expression evalStep (Val x)= (Val x) evalStep (Add x y) = case x of (Val a) -> case y of (Val b) -> Val (a+b) left -> Add x (evalStep y) right -> Add y(evalStep x)
evaluate :: Expression -> Expression -- Base case evaluate (Val a) = Val a -- Recursive case evaluate e = do putStrLn "Evaluating one more step" e' <- return (evalStep e) putStrLn ("Result is "++(show e')) putStrLn "Do another step (y/n)? :" c <- getChar if (c=='y') then evaluate e' else putStrLn "OK, finished"
participants (2)
-
jean verdier
-
John Moore