Reputation: 49
Hi this is probably a very simple problem but I'm having issue with it. I'm trying to make a roots function with the formula:
roots a b c = ((-b + t)/a', (-b - t)/a')
where
t = b ^ 2 - 4 * a * c
a' = 2 * a
I'm now trying to make it a curried function however I can't seem to get it to work this is what I've put:
roots:: Double -> (Double -> (Double -> Double))
Could someone please help me out?
Thanks!
Upvotes: 0
Views: 200
Reputation: 48654
In Haskell, functions are automatically curried. So you don't have to do anything special to make them curried.
Your function roots is of the type roots:: Double -> Double -> Double -> (Double, Double)
. Something like this will typecheck: let a = roots 3.0
because of currying.
In case your roots
function was not curried, then it is likely to have a type like this: roots:: (Double , Double , Double) -> (Double, Double)
which is not the proper way to write function definitons.
Upvotes: 3
Reputation: 671
As far as I know (but I'm not the expert, just had couple of lessons 'bout Haskell so far) function that gets 3 input parameters and produces one output (like in your example) should be written like:
roots:: Double -> Double -> Double -> Double
Last element in the chain (forth Double) is return type, all previous ones are input parameter types. This should do the trick
Upvotes: 0