0

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!

Liamh101
  • 49
  • 1
  • 10
  • 2
    Your function is already curried: `roots:: Double -> Double -> Double -> (Double, Double)` – Sibi Apr 03 '14 at 10:24
  • 2
    By the way, the indentions in your code are wrong. `where` should have more indention, and `t` and `a'` should have the same indentions that are larger than `where`'s. – Lee Duhem Apr 03 '14 at 10:49

2 Answers2

3

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.

Sibi
  • 47,472
  • 16
  • 95
  • 163
0

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

markubik
  • 646
  • 4
  • 9
  • No that doesn't work, also you need the brackets in there to tell that your going into a different function. SORRY WAS WRONG! You don't have to have the brackets! – Liamh101 Apr 03 '14 at 10:24