I'm new at Haskell-programming and have to do some excercises for my functional development lecture at the university. I got the task to create a datatype, called "term" which represents a rational function. The second task is to create a method which differentiates the entered term.
We need a simple solution and constructors for: monomial, Addition, Multiplication, divison
Given:
data Term = Monom (Int, Int) | Addition[Term] deriving Show
diff :: Term -> Term
diff (Monom(a, b)) = Monom(a*b, b-1)
Edit:
Calling the following function will return the corresponsing derivation:
diff (Monom(a,b)) = if b>0 then Monom(a*b, b-1) else Monom(0,0)
same for:
diff (Addition(x:xs)) = diff(x)
Can anyone tell me how to iterate over all elements in the entered list? The function above returns only the first derivated value..
I appreciate every help or hint!