3 ms·
This example: x = foo01(); y = foo02(x); z = foo03(x, y); could easily be written in Haskell as: let x = foo01 y = foo02 x z
by ParetoOptimal 4y ago
This example:
x = foo01();
y = foo02(x);
z = foo03(x, y);
could easily be written in Haskell as:
let x = foo01
y = foo02 x
z = foo03 x y
in z
My thinking is that functional languages don't preclude you from having intermediate state, but I will agree that composition is used often.
Typically when working in a repl I don't really miss the intermediate state because my debugging consists of:
The lambdas must flow.
λ> foo01
"expected result"
λ> foo02
"UNexpected result"
Then I'll debug foo02 in isolation.
> foo03(foo01(), foo02(foo01()) );
I think I'd write this as the let example above with variables. Otherwise I guess I'd need to use something like:
foo03 foo01 . foo02 $ foo01
Here's a Haskell playground link with these examples if you're curious or had something else in mind and want to modify the example: https://play.haskell.org/saved/MeRGyCjr https://play.haskell.org/saved/MeRGyCjr