3 ms·
I have to agree. I found the answers to be mostly after-the-fact justifications, rather painful to read in fact. Sure, y = sin(x) is well modeled as having on
by mturmon 13y ago
I have to agree. I found the answers to be mostly after-the-fact justifications, rather painful to read in fact. Sure, y = sin(x) is well modeled as having one output, but there are plenty of multi-output functions, even in math. A few that come to mind are:
Modulus calculations like
a,b = mod(x,n)
where a is the remainder modulo n, and b is the residual, so that x = a + b*n.
The two outputs from the quadratic formula.
All the matrix factorizations, such as
L,U,P = lu(A)
where A = P L U, and L and U are triangular, and P is a permutation.
The remedy of having a data structure to hold the a and b integers above, or the two roots of a quadratic equation, is asinine.
- lelf 13y agohttp://hackage.haskell.org/package/base-4.6.0.1/docs/Prelude.html#v:divMod http://hackage.haskell.org/package/base-4.6.0.1/docs/Prelude... It's exactly like that in Haskell. If it makes sense to return 2 values — return tuple. Works really well with pattern matching. Syntactic overhead = 0.
- mturmon 13y agoYes. I first saw the idiom in Matlab, actually.