Reputation: 585
I am learning haskell and have some problems understanding what the errors are trying to tell me. This Code produces the following error
data Term = Mul { factor :: Term, factor2 :: Term }
| Div { dividend :: Term, divisor :: Term }
| Add { summand :: Term, summand2 :: Term }
| Sub { minuend :: Term, subtrahend :: Term }
| Mon { exponent :: Int }
value :: (Double, Term) -> Double
value x (Mul a b) = (value x a) * (value x b)
value x (Div a b) = (value x a) / (value x b)
value x (Add a b) = (value x a) + (value x b)
value x (Sub a b) = (value x a) - (value x b)
value x (Mon a) = x^a
Error:
Couldn't match expected type `Term -> (Double, Term)'
with actual type `Double'
The function `value' is applied to two arguments,
but its type `(Double, Term) -> Double' has only one
In the first argument of `(+)', namely `(value x a)'
In the expression: (value x a) + (value x b)
What am I doing wrong?
Upvotes: 1
Views: 71
Reputation: 60463
The problem is that your type signature and definitions don't agree on how they are taking the arguments.
You need to either write your type signature in curried style (recommended):
value :: Double -> Term -> Double
or write your function in uncurried style (non-idiomatic):
value (x, Mul a b) = ...
I recommend trying both, but the former is almost always the way it is done in the wild.
Upvotes: 4