I'm creating a program to compute the solution to a cubic equation in haskell. I'm new to functional languages and I'm having some difficulties. Here is my code:
cubicQ :: Float -> Float -> Float -> Float
cubicQ a b c = ((3 * a * c) - (b**2)) / (9 * (a**2)) --calculates Q
cubicR :: Float -> Float -> Float -> Float -> Float
cubicR a b c d = ((9 * a * b * c) - (27 * a**2 * d) - (2 * b**3)) / (54
* a**3)--calculates R
cubicS :: Float -> Float -> Float
cubicS r q = (r + (sqrt(q**3 + r**2))) ** (1/3)--calculates S
cubicT :: Float -> Float -> Float
cubicT q r = (r - (sqrt(q**3 + r**2))) ** (1/3)--calculates T
check :: Float -> Float -> Float
check q r = ((q**3)+(r**2)) --checks for real numbers
x1 :: Float -> Float -> Float -> Float -> Float
x1 s t a b = (s + t) - (b / (3 * a)) --calculates x1
cubicRealSolution :: Float -> Float -> Float -> Float -> Float
--defines function which takes input and solves
cubicRealSolution a b c d = if l < 0 then error "NaN" else (sol) --Check
for real numbers
where
q = cubicQ
r = cubicR
s = cubicS
t = cubicT
l = check
sol = x1
I get this error when compiling, * Couldn't match expected type Float'
with actual type Float -> Float -> Float -> Float -> Float'
* Probable cause: sol' is applied to too few arguments
I'm not sure where to go from here. I can get it to work if i remove all of the functions and instead just make my variables equal to the computations that thr functions do, but it's for a school assignment and so I have to have these functions defined.
q = cubicQwill simply assign the function to the variableq. So you need to call it likeq = cubicQ a b c.