News for hackers. Stuff that matters.
Re:Concatenation is composition by viraptor on Monday July 18, 2022 @08:24AM (#32137471)
Spot a person who's been doing very functional programming for too long:

> These two fundamental operations -- curry and compose -- have very simple and intuitive semantics.

Re:Concatenation is composition by nine_k on Monday July 18, 2022 @08:54AM (#32137752)
They are indeed simple and intuitive. You can explain them in terms of cooking.

Curry: f(x, y) = f(x)(y)

For cookies, whip butter with sugar. Curried version: whip /f/ the butter /x/, then whip the result while adding sugar /y/.

Composition: f ⭘ g = f(g(x))

To produce nicely shaped cookies, shape the cookies /x/ on a tray first /g/, then bake them /f/.

Re:Concatenation is composition by tantalor on Monday July 18, 2022 @09:09AM (#32137901)
The fact that you originally swapped /f/ and /g/ in your comment then edited it to fix there mistake is perfect example of why this is a dangerous and bug prone approach to writing programs.
Re:Concatenation is composition by nine_k on Monday July 18, 2022 @09:22AM (#32138048)
It's just f and g being poor names, also on keys next to each other. The circle is a good symbol for a whiteboard, but it's a poor identifier.

Normally you write composition like readFile().then(stripComments).then(sort).then(takeFirst), or compose using shell pipes.

Composition is so widespread and so trivial-looking that it's even easy to miss.

Re:Concatenation is composition by mjburgess on Monday July 18, 2022 @09:17AM (#32137982)
Strange take -- the whole basis of FP is dangerous and bug-prone?

Unlike the imperative `;`, which sequences commands in an absolutely obvious way, right?

Re:Concatenation is composition by viraptor on Monday July 18, 2022 @09:43AM (#32138288)
While I understand curry and compose, I just don't consider them simple or intuitive in usage because normally I get cleaner result by not using them. I don't understand your recipe explanation unfortunately.
Re:Concatenation is composition by waynesonfire on Tuesday July 19, 2022 @12:47AM (#32147644)
> because normally I get cleaner result by not using them

i doubt it. composition and currying are so fundamental.

Re:Concatenation is composition by viraptor on Tuesday July 19, 2022 @06:39AM (#32149731)
Just to be clear, I don't use it in a pure form you'd see in many Haskell, etc. environments. I still use them when appropriate, with context-specific names and full arguments, because .then and "x => x<4" are more readable even if less terse.
Re:Concatenation is composition by suremarc on Monday July 18, 2022 @09:25AM (#32138083)
> Composition: f ⭘ g = g(f(x))

This should be reversed. It is not defined this way in mathematics nor in Haskell.

Re:Concatenation is composition by nine_k on Monday July 18, 2022 @10:09AM (#32138580)
Thanks! Reversing.
Re:Concatenation is composition by chriswarbo on Monday July 18, 2022 @02:08PM (#32141398)
I don't find these analogies compelling at all:

> whip /f/ the butter /x/, then whip the result while adding sugar /y/

That's not a valid explanation, since curried functions don't "act" until they've got all their arguments; i.e. we do not whip any butter until the sugar has been added.

> shape the cookies /x/ on a tray first /g/, then bake them /f/

Whilst this is accurrate, I think introducing a notion of time ("then") makes things much harder than they need to be. (That's one reason I find imperative programs hard to understand)