sshine
21 minutes ago
> Functions Are Asymmetric
No, bijective functions are symmetric.
Injectivity is enough to invert a function.
> Even though they may take any number of arguments, they must each have one return value. [...] This is true of all functions.
Mathematical functions take one value and produce one value. This is true of all mathematical functions.
Programming functions can be modelled this way by treating multiple input arguments as a single product, and non-scalar outputs containing multiple values as a single product.
Programming functions don't even have to always return one value:
- Haskell's Void type
- Rust's ! type
- TypeScript's never type
all have zero values, meaning the function can't meaningfully return.Arguably, programming functions must take at least one value as input, otherwise how can they be called?
In that sense, programming functions are asymmetric: It rarely makes sense to write a function you can't call, but it often makes sense to write a function that never returns.
When does it make sense to write a function that you can't call? When the point of the function is to prove something as a result of being compiled. The value lies in the compilation, not in being called.
A better title for this article: Some Functions Are Asymmetric.
Which is less of a profound insight.