5 ms·
if you are comfortable with returning tuples, perhaps the inputs should be a tuple as well... def findRoot(p:(Double,Double,Double)) = { assert(p._
by dxbydt 15y ago
if you are comfortable with returning tuples, perhaps the inputs should be a tuple as well...
def findRoot(p:(Double,Double,Double)) = {
assert(p._1 != 0)
val n = sqrt(p._2*p._2-4*p._1*p._3)
val d = 2*p._1
( (-p._2+n)/d, (-p._2-n)/d )
}
----
scala> findRoot((6,-6,-36))
res0: (Double, Double) = (3.0,-2.0)
- ajross 15y agoNot sure how we got to Scala, but in (non-varargs) C linkage the whole metaphor of "funtion arguments" is inherently a "tuple" to begin with. They only exist in tandem with each other, never in isolation. There's no real value I can see to trying to double-abstract it.
- nooop 15y ago> if you are comfortable with returning tuples, perhaps the inputs should be a tuple as well... why should they?