16 ms·
You misunderstand (as most do): I never said function composition was a bad idea; I do it all the time. My only claim is that you don't need a Turing-complete
by colanderman 11y ago
You misunderstand (as most do): I never said function composition was a bad idea; I do it all the time.
My only claim is that you don't need a Turing-complete language to compose functions. As an thought-exercise, consider replacing all uses of first-class function compositions in any given OCaml program with top-level module compositions. You lose nothing: no-one (who designs maintainable software) uses the full expressive power of a Turing-complete language to manipulate first-class functions.
(Of course there are more user-friendly ways to implement second-class functions, which make using them less a burden, but no extant language has such a system.)
- catnaroek 11y agoWhen did I say “function composition”? What I said is “composing solutions to smaller, more tractable problems”. If you divide a problem `FooBarQux` into a sequence of subproblems, `Foo`, `Bar` and `Qux`, sure, these solutions must be combined using the function composition operator. But there are other ways to decompose problems. For instance, splitting a problem into a DAG of subproblems with overlapping dependencies gives rise to dynamic programming. And, no, an ML-like module system wouldn't make up for the lack of first-class functions. Standard ML doesn't allow any module recursion whatsoever, and, while OCaml allows it, it's quite unwieldy to use in practice. It would be literally impossible to define a function like `fix`, which requires the ability to call its function argument (let's call it `f`), supplying an expression containing `fix` itself as argument.
- colanderman 11y agoSince when do you need first-class functions for dynamic programming? How often have you had to define `fix`? It's not even possible in certain strongly typed functional languages. I stand by my assertion. First-class function manipulation is not a thing 99% of programs need to do.