Live data from Hacker News

Common combinators in JavaScript

gist.github.com

51–55 of 55 posts

Re: Common combinators in JavaScript

#51

Earlier quoted context omitted.

I’m not going to defend single letter names (although shortness does have some virtue compared to some monstrous naming conventions), but... Most math texts have a fair amount of documentation when formulas are introduced. Perhaps substantially more than the table in this article.

Math papers on the other hand assume that the reader has recursively traversed and read all of the citations and knows most of the notation.

Of course, that’s the whole point of citations and notation. Do you want every single paper to be 500+ pages? I have better things to do trying to figure out where the novel result is in hundreds of pages of the same shit I’ve seen dozens of time already.

Re: Common combinators in JavaScript

#52
post #4
post #3

This site embodies everything I dislike about functional programming: an attitude that shorter and less specific is better. What use is a line like const S = f => g => x => f(x)(g(x)); for anyone except someone who already groks what the S combinator does and is for? Why do these combinators have single-letter names anyway? Does that help anyone? Even Haskell, heaven on earth for single-letter guess-what-i-mean coder…

This is an implementation of combinatory logic and nothing to do with functional programming. https://en.wikipedia.org/wiki/Combinatory_logic

the term functional programming has taken to mean more than just programming with functions. combinator logic certainly counts

Re: Common combinators in JavaScript

#53
post #45
post #29

Earlier quoted context omitted.

It's intentionally to get across the idea that you don't, and shouldn't, know anything about these arguments within this scope beyond "this is a function" and "this is an argument". These functions just define how to combine things; if you knew any more about the arguments, it would be breaking the abstraction. The only better names you could really give are ones like func1, func2, arg1, arg2, which don't add any inf…

That makes sense for the arguments to the outermost function but not to the function it self. Why call it A instead of apply and the then have a big cheat sheet where you put that A means apply and T means applyTo ?

I think those single-letter names like "S combinator" are a holdover from Math notation, where it was a practical consideration, but in practice in functional programming, those names aren't used (I certainly haven't memorized them); If you look at the Haskell column on the page, you can see that they're actually named for readability (though it might not initially seem like it if you don't do a lot of coding in Haskell):

- K is "const" and C is "flip"; they're generally used to for arguments to a higher order function: "map (const 5) myList", "foldl (flip f) 0 myList"

- Psi is "on", since it's regularly used to construct a new function "h = f `on` g"

- S is a specific type of application, called infix as "f `ap` x", but also has an operator to intentionally make it look more like just line noise: "f x". (Had to add spaces to this operator so HN wouldn't interpret it as italics)

The operators might seem opaque, but the idea is to make it more visually apparent that it's a pattern, not some application-specific business logic. There are lots of concepts of "apply" - there's pure application ($), Applicative application (), Monadic application (=<<), etc. - writing them out would distracting to read. Using operators makes it easier to skim and get the general idea of how the code works without worrying about the underlying structural details, while still being precise about them.

Re: Common combinators in JavaScript

#54

Earlier quoted context omitted.

Same reason we use + instead of Math.addTwoIntegers(). Pure snobbery.

However, we don't combine + with other operators to form an illegible mess. Even ++ is frowned upon for being unreadable/easily missed and/or placed in the wrong spot.

`5 + 10 * 2`?

Re: Common combinators in JavaScript

#55
post #54

Earlier quoted context omitted.

However, we don't combine + with other operators to form an illegible mess. Even ++ is frowned upon for being unreadable/easily missed and/or placed in the wrong spot.

`5 + 10 * 2`?

Not sure I see your point.
Post reply on HN