Hi All,
I'm trying to work out how to show the steps in evaluating "How the function is calculated". In other words I want this program to actually print out the steps. For e.g. eval (Multiply(Add(Val 10) (Val 20)) (Val 3) Which is add 10+20 and multiply by 3 = 90
The program then produces( Prints out) something like
working: eval (Multiply(Add(Val 10) (Val 20)) (Val 3)
working Add(Val10) (Val 20)
answer 1 Val 30
answer 2 Val 90
This is what I have so far but it wont even do the calculations. Any help appreciated.
data Expression = Val Float
| Add Expression Expression
| Subtract Expression Expression
| Multiply Expression Expression
| Divide Expression Expression
deriving Show
eval :: Expression -> Float
eval (Val x) = x
eval (Add x y) = eval x + eval y
eval (Multiply x y) = eval x * eval y
eval (Subtract x y) = eval x - eval y
eval (Divide x y) = eval x / eval y
John