[Haskell-beginners] Show how the evaluation works

John Moore john.moore54 at gmail.com
Sun Nov 22 11:17:46 EST 2009

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

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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20091122/5ede682c/attachment.html

More information about the Beginners mailing list