Created
August 23, 2016 14:38
-
-
Save skatenerd/6fc88253708c36f01e9a1919384bb3db to your computer and use it in GitHub Desktop.
pipeline vs composition
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- pipelining | |
let x = 1 | |
doubled = x * 2 | |
squared = doubled * doubled | |
decremented = squared - 1 | |
in decremented | |
-- composition | |
let x = 1 | |
double = (*) 2 | |
square x = x * x | |
decrement x = x - 1 | |
in (decrement . square . double) x |
@raganwald, Thanks for responding!
I'm not sure I understand the distinction. In this case, both let
statements could just be the body of a first-class function, which could be named, passed around, composed, etc.
Maybe this example is just too small.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, and the vital difference between them is that the composition version creates a new first-class that can be named, passed as a value, &tc., while the pipelined version does not. Furthermore, the composition version can be dynamically composed, while most languages have difficulty dynamically pipelining things.
Both do the exact same thing in the small, but the compositional version can be much better if there is some wonderful thing enabled by making something first-class. And it can be worse if that is a distraction to the primary responsibility fo the code.