[Haskell-beginners] explanation

Thomas Davie tom.davie at gmail.com
Wed Dec 1 21:19:29 CET 2010


On 1 Dec 2010, at 19:34, John Moore wrote:

> Hi ,
>      Havent used haskell in a while can someone explain just whats happening here. I know what it does, I just can't workout how it does it. Only need to explain how the red area works and I can work out the rest myself

The red block says... in order to figure out the value of two expressions added together, you must find out if you have values either side of the add sign... If you do, simply add them together.  If you do not, evaluate one side or the other.

It's a bit odd to use small-step semantics here though, the code could be much much neater if it used a denotational aproach:

eval :: Expression -> Double
eval (Val x) = x
eval (Add x y) = (eval x) + (eval y)
eval (Subtract x y) = (eval x) - (eval y)
eval (Multiply x y) = (eval x) * (eval y)
eval (Divide x y) = (eval x) / (eval y)

Bob




More information about the Beginners mailing list