functional programming - Troubleshooting a haskell function -



functional programming - Troubleshooting a haskell function -

i learning haskell , have problems understanding errors trying tell me. code produces next error

data term = mul { factor :: term, factor2 :: term } | div { dividend :: term, divisor :: term } | add together { summand :: term, summand2 :: term } | sub { minuend :: term, subtrahend :: term } | mon { exponent :: int } value :: (double, term) -> double value x (mul b) = (value x a) * (value x b) value x (div b) = (value x a) / (value x b) value x (add b) = (value x a) + (value x b) value x (sub b) = (value x a) - (value x b) value x (mon a) = x^a

error:

couldn't match expected type `term -> (double, term)' actual type `double' function `value' applied 2 arguments, type `(double, term) -> double' has 1 in first argument of `(+)', namely `(value x a)' in expression: (value x a) + (value x b)

what doing wrong?

the problem type signature , definitions don't agree on how taking arguments.

you need either write type signature in curried style (recommended):

value :: double -> term -> double

or write function in uncurried style (non-idiomatic):

value (x, mul b) = ...

i recommend trying both, former way done in wild.

haskell functional-programming ghc

Comments

Popular posts from this blog

java - Bypassing "final local variable defined in an enclosing type" -

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -