3 ms·
> Function returning function returning function is an awful style of coding that is hard to read. Hey, that's basically how any function with more than one ar
by eru 4y ago
> Function returning function returning function is an awful style of coding that is hard to read.
Hey, that's basically how any function with more than one argument is implemented in Haskell. (Look up currying.)
It's not so much that this style is 'awful' in any universal sense; it's more that Go is terrible, terrible host language for anything in this style.
- codedokode 4y agoHaskell hides this complexity and allows you to write just: add x y = x + y There is no functions returning functions here, just a normal addition. It is perfectly readable.
- eru 4y agoYes, it is perfectly readable. But: there is a function returning a function. Haskell just decided to have a syntax (and type system) that can handle this without inducing nausea in the programmer. As with everything, this comes with trade-offs. For example, Haskell's syntax (and type system) have a much harder time dealing with optional arguments. Something that eg Python does just fine, and that even C handles OK in the form of varargs.