I am still learning Haskell and the question seems very basic but it's been stomping me for a while.
Given the following
data Term =
Number Integer
| Abs Term
| Plus Term Term
| Mult Term Term
deriving (Eq, Show)
I want to create an interpreter such that if I call, for example,
evaluate (Plus (Number 10) (Number 10))
it will return 20. Below is what I have so far
myabsolute :: Integer -> Integer
myabsolute n = if n >= 0 then n else -n
evaluate :: Term -> Integer
evaluate Plus = evaluate(t1) + evaluate(t2)
evaluate Mult = evaluate(t1) * evaluate(t2)
evaluate Abs = myabs(evaluate(t1))
evaluate _ = 0
I am confused how to get the Number Integer part working since I do not know how to extract the numbers and map them to t1 and t2 in Plus, Mult, and Abs.
Since I am still learning, if I am doing something completely wrong please let me know!