[Haskell-beginners] possible incorrect indentation

John Moore john.moore54 at gmail.com
Mon Jan 25 17:45:16 EST 2010


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20100125/05480709/attachment-0001.html


More information about the Beginners mailing list